| 296 | type boolMapper struct{} |
| 297 | |
| 298 | func (boolMapper) Decode(ctx *DecodeContext, target reflect.Value) error { |
| 299 | if ctx.Scan.Peek().Type == FlagValueToken { |
| 300 | token := ctx.Scan.Pop() |
| 301 | switch v := token.Value.(type) { |
| 302 | case string: |
| 303 | v = strings.ToLower(v) |
| 304 | switch v { |
| 305 | case "true", "1", "yes": |
| 306 | target.SetBool(true) |
| 307 | |
| 308 | case "false", "0", "no": |
| 309 | target.SetBool(false) |
| 310 | |
| 311 | default: |
| 312 | return fmt.Errorf("bool value must be true, 1, yes, false, 0 or no but got %q", v) |
| 313 | } |
| 314 | |
| 315 | case bool: |
| 316 | target.SetBool(v) |
| 317 | |
| 318 | default: |
| 319 | return fmt.Errorf("expected bool but got %q (%T)", token.Value, token.Value) |
| 320 | } |
| 321 | } else { |
| 322 | target.SetBool(true) |
| 323 | } |
| 324 | return nil |
| 325 | } |
| 326 | func (boolMapper) IsBool() bool { return true } |
| 327 | |
| 328 | func durationDecoder() MapperFunc { |