OptionalBigIntArrayParam 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, if not, it returns an empty slice 2. If it is present, iterates the elements, checks each is a string, a
(args map[string]any, p string)
| 293 | // 1. Checks if the parameter is present in the request, if not, it returns an empty slice |
| 294 | // 2. If it is present, iterates the elements, checks each is a string, and converts them to int64 values |
| 295 | func OptionalBigIntArrayParam(args map[string]any, p string) ([]int64, error) { |
| 296 | // Check if the parameter is present in the request |
| 297 | if _, ok := args[p]; !ok { |
| 298 | return []int64{}, nil |
| 299 | } |
| 300 | |
| 301 | switch v := args[p].(type) { |
| 302 | case nil: |
| 303 | return []int64{}, nil |
| 304 | case []string: |
| 305 | return convertStringSliceToBigIntSlice(v) |
| 306 | case []any: |
| 307 | int64Slice := make([]int64, len(v)) |
| 308 | for i, v := range v { |
| 309 | s, ok := v.(string) |
| 310 | if !ok { |
| 311 | return []int64{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v) |
| 312 | } |
| 313 | val, err := convertStringToBigInt(s, 0) |
| 314 | if err != nil { |
| 315 | return []int64{}, fmt.Errorf("parameter %s: failed to convert element %d (%s) to int64: %w", p, i, s, err) |
| 316 | } |
| 317 | int64Slice[i] = val |
| 318 | } |
| 319 | return int64Slice, nil |
| 320 | default: |
| 321 | return []int64{}, fmt.Errorf("parameter %s could not be coerced to []int64, is %T", p, args[p]) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // WithPagination adds REST API pagination parameters to a tool. |
| 326 | // https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api |
no test coverage detected