MCPcopy
hub / github.com/digitalocean/doctl / GetStringMapString

Method GetStringMapString

doit.go:459–484  ·  view source on GitHub ↗

GetStringMapString returns a config value as a string to string map.

(ns, key string)

Source from the content-addressed store, hash-verified

457
458// GetStringMapString returns a config value as a string to string map.
459func (c *LiveConfig) GetStringMapString(ns, key string) (map[string]string, error) {
460 nskey := nskey(ns, key)
461
462 if isRequired(nskey) && !c.IsSet(key) {
463 return nil, NewMissingArgsErr(nskey)
464 }
465
466 // We cannot call viper.GetStringMapString because it does not handle
467 // pflag's StringToStringP properly:
468 // https://github.com/spf13/viper/issues/608
469 // Re-implement the necessary pieces on our own instead.
470
471 vals := map[string]string{}
472 items := viper.GetStringSlice(nskey)
473 for _, item := range items {
474 parts := strings.SplitN(item, "=", 2)
475 if len(parts) < 2 {
476 return nil, fmt.Errorf("item %q does not adhere to form: key=value", item)
477 }
478 labelKey := parts[0]
479 labelValue := parts[1]
480 vals[labelKey] = labelValue
481 }
482
483 return vals, nil
484}
485
486// GetDuration returns a config value as a duration.
487func (c *LiveConfig) GetDuration(ns, key string) (time.Duration, error) {

Callers

nothing calls this directly

Calls 6

IsSetMethod · 0.95
nskeyFunction · 0.85
isRequiredFunction · 0.85
NewMissingArgsErrFunction · 0.85
ErrorfMethod · 0.80
GetStringSliceMethod · 0.65

Tested by

no test coverage detected