Disable nil's out the named feature. If it isn't found then it will log a message.
(name string)
| 216 | // Disable nil's out the named feature. If it isn't found then it |
| 217 | // will log a message. |
| 218 | func (ft *Features) Disable(name string) *Features { |
| 219 | // Prefix boolean values with ! to set the feature |
| 220 | invert := false |
| 221 | if strings.HasPrefix(name, "!") { |
| 222 | name = name[1:] |
| 223 | invert = true |
| 224 | } |
| 225 | v := reflect.ValueOf(ft).Elem() |
| 226 | vType := v.Type() |
| 227 | for i := range v.NumField() { |
| 228 | vName := vType.Field(i).Name |
| 229 | field := v.Field(i) |
| 230 | if strings.EqualFold(name, vName) { |
| 231 | if !field.CanSet() { |
| 232 | Errorf(nil, "Can't set Feature %q", name) |
| 233 | } else { |
| 234 | if invert { |
| 235 | if field.Type().Kind() == reflect.Bool { |
| 236 | field.Set(reflect.ValueOf(true)) |
| 237 | Debugf(nil, "Set feature %q", name) |
| 238 | } else { |
| 239 | Errorf(nil, "Can't set Feature %q to true", name) |
| 240 | } |
| 241 | } else { |
| 242 | zero := reflect.Zero(field.Type()) |
| 243 | field.Set(zero) |
| 244 | Debugf(nil, "Reset feature %q", name) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | return ft |
| 250 | } |
| 251 | |
| 252 | // List returns a slice of all the possible feature names |
| 253 | func (ft *Features) List() (out []string) { |