MCPcopy
hub / github.com/bitly/go-simplejson / MustString

Method MustString

simplejson.go:295–312  ·  view source on GitHub ↗

MustString guarantees the return of a `string` (with optional default) useful when you explicitly want a `string` in a single value return context: myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))

(args ...string)

Source from the content-addressed store, hash-verified

293//
294// myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))
295func (j *Json) MustString(args ...string) string {
296 var def string
297
298 switch len(args) {
299 case 0:
300 case 1:
301 def = args[0]
302 default:
303 log.Panicf("MustString() received too many arguments %d", len(args))
304 }
305
306 s, err := j.String()
307 if err == nil {
308 return s
309 }
310
311 return def
312}
313
314// MustStringArray guarantees the return of a `[]string` (with optional default)
315//

Callers 1

TestSimplejsonFunction · 0.80

Calls 1

StringMethod · 0.95

Tested by 1

TestSimplejsonFunction · 0.64