RequiredBigInt 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
(args map[string]any, p string)
| 156 | // 3. Checks if the parameter is not empty, i.e: non-zero value. |
| 157 | // 4. Validates that the float64 value can be safely converted to int64 without truncation. |
| 158 | func RequiredBigInt(args map[string]any, p string) (int64, error) { |
| 159 | val, ok := args[p] |
| 160 | if !ok { |
| 161 | return 0, fmt.Errorf("missing required parameter: %s", p) |
| 162 | } |
| 163 | |
| 164 | result, err := toInt64(val) |
| 165 | if err != nil { |
| 166 | return 0, fmt.Errorf("parameter %s is not a valid number: %w", p, err) |
| 167 | } |
| 168 | |
| 169 | if result == 0 { |
| 170 | return 0, fmt.Errorf("missing required parameter: %s", p) |
| 171 | } |
| 172 | |
| 173 | return result, nil |
| 174 | } |
| 175 | |
| 176 | // OptionalParam is a helper function that can be used to fetch a requested parameter from the request. |
| 177 | // It does the following checks: |
no test coverage detected