From 581f043760db9deef38e825d47ba735d3fc8a72e Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 20 Nov 2023 12:37:56 -0800 Subject: [PATCH] remove dead code, not called anyway for things like []int --- logger.go | 52 +++++----------------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/logger.go b/logger.go index 6878a48..eba4e9e 100644 --- a/logger.go +++ b/logger.go @@ -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 { @@ -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)) }