parseBoolOpt parses a boolean option from the query string, returning true if the value is "t" or "true" case-insensitive false if the value is "f" or "false" case-insensitive
(q url.Values, name string)
| 1030 | // true if the value is "t" or "true" case-insensitive |
| 1031 | // false if the value is "f" or "false" case-insensitive |
| 1032 | func parseBoolOpt(q url.Values, name string) (*bool, error) { |
| 1033 | v, ok := q[name] |
| 1034 | if !ok { |
| 1035 | return nil, nil |
| 1036 | } |
| 1037 | |
| 1038 | if len(v) != 1 { |
| 1039 | return nil, newBadCommandError(fmt.Sprintf("%v param should be only one value: %q", name, v)) |
| 1040 | } |
| 1041 | |
| 1042 | switch strings.ToLower(v[0]) { |
| 1043 | case "true", "t", "": |
| 1044 | enable := true |
| 1045 | return &enable, nil |
| 1046 | case "false", "f": |
| 1047 | disable := false |
| 1048 | return &disable, nil |
| 1049 | default: |
| 1050 | // value is not recognized |
| 1051 | return nil, newBadCommandError( |
| 1052 | fmt.Sprintf("%v query param should be true or false, got: %q", |
| 1053 | name, v[0], |
| 1054 | )) |
| 1055 | } |
| 1056 | |
| 1057 | } |
| 1058 | |
| 1059 | // runSignalWrapper watches for SIGTERM and SIGINT and interupts execution if necessary. |
| 1060 | func runSignalWrapper(cmd *Command) (err error) { |
no test coverage detected