Skip to content

Commit

Permalink
remove dead code, not called anyway for things like []int
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Nov 20, 2023
1 parent d0f1dee commit 581f043
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,43 +589,6 @@ type ValueType[T ValueTypes] struct {
Val T
}

/*
func arrayToString(s []interface{}) string {
var buf strings.Builder
buf.WriteString("[")
for i, e := range s {
if i != 0 {
buf.WriteString(",")
}
vv := ValueType[interface{}]{Val: e}
buf.WriteString(vv.String())
}
buf.WriteString("]")
return buf.String()
}
func mapToString(s map[string]interface{}) string {
var buf strings.Builder
buf.WriteString("{")
keys := make([]string, 0, len(s))
for k := range s {
keys = append(keys, k)
}
sort.Strings(keys)
for i, k := range keys {
if i != 0 {
buf.WriteString(",")
}
buf.WriteString(fmt.Sprintf("%q", k))
buf.WriteString(":")
vv := ValueType[interface{}]{Val: s[k]}
buf.WriteString(vv.String())
}
buf.WriteString("}")
return buf.String()
}
*/

func toJSON(v any) string {
bytes, err := json.Marshal(v)
if err != nil {
Expand All @@ -642,18 +605,13 @@ func toJSON(v any) string {

func (v ValueType[T]) String() string {
// if the type is numeric, use Sprint(v.val) otherwise use Sprintf("%q", v.Val) to quote it.
switch /*s :=*/ any(v.Val).(type) {
switch s := any(v.Val).(type) {
case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64,
float32, float64:
return fmt.Sprint(v.Val)
/* It's all handled by json fallback now - todo test if this is/was cheaper?
case error: // struct with no public fields so we need to call Error() to get a string. otherwise we get {}
return fmt.Sprintf("%q", s.Error())
case []interface{}:
return arrayToString(s)
case map[string]interface{}:
return mapToString(s)
*/
return fmt.Sprint(s)
case string:
return fmt.Sprintf("%q", s)
/* It's all handled by json fallback now even though slightly more expensive at runtime, it's a lot simpler */
default:
return toJSON(v.Val) // was fmt.Sprintf("%q", fmt.Sprint(v.Val))
}
Expand Down

0 comments on commit 581f043

Please sign in to comment.