RequiredInt is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request. 2. Checks if the parameter is of the expected type (float64 or numeric string). 3. Checks if the parameter is not emp
(args map[string]any, p string)
| 132 | // 2. Checks if the parameter is of the expected type (float64 or numeric string). |
| 133 | // 3. Checks if the parameter is not empty, i.e: non-zero value |
| 134 | func RequiredInt(args map[string]any, p string) (int, error) { |
| 135 | v, ok := args[p] |
| 136 | if !ok { |
| 137 | return 0, fmt.Errorf("missing required parameter: %s", p) |
| 138 | } |
| 139 | |
| 140 | result, err := toInt(v) |
| 141 | if err != nil { |
| 142 | return 0, fmt.Errorf("parameter %s is not a valid number: %w", p, err) |
| 143 | } |
| 144 | |
| 145 | if result == 0 { |
| 146 | return 0, fmt.Errorf("missing required parameter: %s", p) |
| 147 | } |
| 148 | |
| 149 | return result, nil |
| 150 | } |
| 151 | |
| 152 | // RequiredBigInt is a helper function that can be used to fetch a requested parameter from the request. |
| 153 | // It does the following checks: |