MCPcopy Create free account
hub / github.com/stretchr/objx / String

Method String

value.go:21–55  ·  view source on GitHub ↗

String returns the value always as a string

()

Source from the content-addressed store, hash-verified

19
20// String returns the value always as a string
21func (v *Value) String() string {
22 switch {
23 case v.IsNil():
24 return ""
25 case v.IsStr():
26 return v.Str()
27 case v.IsBool():
28 return strconv.FormatBool(v.Bool())
29 case v.IsFloat32():
30 return strconv.FormatFloat(float64(v.Float32()), 'f', -1, 32)
31 case v.IsFloat64():
32 return strconv.FormatFloat(v.Float64(), 'f', -1, 64)
33 case v.IsInt():
34 return strconv.FormatInt(int64(v.Int()), 10)
35 case v.IsInt8():
36 return strconv.FormatInt(int64(v.Int8()), 10)
37 case v.IsInt16():
38 return strconv.FormatInt(int64(v.Int16()), 10)
39 case v.IsInt32():
40 return strconv.FormatInt(int64(v.Int32()), 10)
41 case v.IsInt64():
42 return strconv.FormatInt(v.Int64(), 10)
43 case v.IsUint():
44 return strconv.FormatUint(uint64(v.Uint()), 10)
45 case v.IsUint8():
46 return strconv.FormatUint(uint64(v.Uint8()), 10)
47 case v.IsUint16():
48 return strconv.FormatUint(uint64(v.Uint16()), 10)
49 case v.IsUint32():
50 return strconv.FormatUint(uint64(v.Uint32()), 10)
51 case v.IsUint64():
52 return strconv.FormatUint(v.Uint64(), 10)
53 }
54 return fmt.Sprintf("%#v", v.Data())
55}
56
57// StringSlice returns the value always as a []string
58func (v *Value) StringSlice(optionalDefault ...[]string) []string {

Callers 9

parseURLValuesMethod · 0.95
Base64Method · 0.80
TestAccessorsNestedFunction · 0.80
TestStringTypeStringFunction · 0.80
TestStringTypeBoolFunction · 0.80
TestStringTypeIntFunction · 0.80
TestStringTypeUintFunction · 0.80
TestStringTypeFloatFunction · 0.80
TestStringTypeOtherFunction · 0.80

Calls 15

IsNilMethod · 0.95
IsStrMethod · 0.95
StrMethod · 0.95
IsBoolMethod · 0.95
BoolMethod · 0.95
IsFloat32Method · 0.95
Float32Method · 0.95
IsFloat64Method · 0.95
Float64Method · 0.95
IsIntMethod · 0.95
IntMethod · 0.95
IsInt8Method · 0.95

Tested by 7

TestAccessorsNestedFunction · 0.64
TestStringTypeStringFunction · 0.64
TestStringTypeBoolFunction · 0.64
TestStringTypeIntFunction · 0.64
TestStringTypeUintFunction · 0.64
TestStringTypeFloatFunction · 0.64
TestStringTypeOtherFunction · 0.64