MCPcopy
hub / github.com/SleepingBag945/dddd / ToString

Function ToString

lib/nuclei/pkg/types/interfaces.go:34–79  ·  view source on GitHub ↗

ToString converts an interface to string in a quick way

(data interface{})

Source from the content-addressed store, hash-verified

32
33// ToString converts an interface to string in a quick way
34func ToString(data interface{}) string {
35 switch s := data.(type) {
36 case nil:
37 return ""
38 case string:
39 return s
40 case bool:
41 return strconv.FormatBool(s)
42 case float64:
43 return strconv.FormatFloat(s, 'f', -1, 64)
44 case float32:
45 return strconv.FormatFloat(float64(s), 'f', -1, 32)
46 case int:
47 return strconv.Itoa(s)
48 case int64:
49 return strconv.FormatInt(s, 10)
50 case int32:
51 return strconv.Itoa(int(s))
52 case int16:
53 return strconv.FormatInt(int64(s), 10)
54 case int8:
55 return strconv.FormatInt(int64(s), 10)
56 case uint:
57 return strconv.FormatUint(uint64(s), 10)
58 case uint64:
59 return strconv.FormatUint(s, 10)
60 case uint32:
61 return strconv.FormatUint(uint64(s), 10)
62 case uint16:
63 return strconv.FormatUint(uint64(s), 10)
64 case uint8:
65 return strconv.FormatUint(uint64(s), 10)
66 case []byte:
67 return string(s)
68 case severity.Holder:
69 return s.Severity.String()
70 case severity.Severity:
71 return s.String()
72 case fmt.Stringer:
73 return s.String()
74 case error:
75 return s.Error()
76 default:
77 return fmt.Sprintf("%v", data)
78 }
79}
80
81// ToStringNSlice converts an interface to string in a quick way or to a slice with strings
82// if the input is a slice of interfaces.

Callers 5

JSONScalarToStringFunction · 0.70
ToStringNSliceFunction · 0.70
ToStringSliceFunction · 0.70
ToByteSliceFunction · 0.70
ToStringMapFunction · 0.70

Calls 2

StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected