configure stores the name=value mapping into the current config, correctly handling the case when name identifies a particular choice in a field.
(name, value string)
| 294 | // configure stores the name=value mapping into the current config, correctly |
| 295 | // handling the case when name identifies a particular choice in a field. |
| 296 | func configure(name, value string) error { |
| 297 | currentMu.Lock() |
| 298 | defer currentMu.Unlock() |
| 299 | f, ok := configFieldMap[name] |
| 300 | if !ok { |
| 301 | return fmt.Errorf("unknown config field %q", name) |
| 302 | } |
| 303 | if f.name == name { |
| 304 | return currentCfg.set(f, value) |
| 305 | } |
| 306 | // name must be one of the choices. If value is true, set field-value |
| 307 | // to name. |
| 308 | if v, err := strconv.ParseBool(value); v && err == nil { |
| 309 | return currentCfg.set(f, name) |
| 310 | } |
| 311 | return fmt.Errorf("unknown config field %q", name) |
| 312 | } |
| 313 | |
| 314 | // resetTransient sets all transient fields in *cfg to their currently |
| 315 | // configured values. |
searching dependent graphs…