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)
| 293 | // |
| 294 | // myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default")) |
| 295 | func (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 | // |