OptionalStringArrayParam 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 its zero-value 2. If it is present, iterates the elements and checks each is a string
(args map[string]any, p string)
| 243 | // 1. Checks if the parameter is present in the request, if not, it returns its zero-value |
| 244 | // 2. If it is present, iterates the elements and checks each is a string |
| 245 | func OptionalStringArrayParam(args map[string]any, p string) ([]string, error) { |
| 246 | // Check if the parameter is present in the request |
| 247 | if _, ok := args[p]; !ok { |
| 248 | return []string{}, nil |
| 249 | } |
| 250 | |
| 251 | switch v := args[p].(type) { |
| 252 | case nil: |
| 253 | return []string{}, nil |
| 254 | case []string: |
| 255 | return v, nil |
| 256 | case []any: |
| 257 | strSlice := make([]string, len(v)) |
| 258 | for i, v := range v { |
| 259 | s, ok := v.(string) |
| 260 | if !ok { |
| 261 | return []string{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v) |
| 262 | } |
| 263 | strSlice[i] = s |
| 264 | } |
| 265 | return strSlice, nil |
| 266 | default: |
| 267 | return []string{}, fmt.Errorf("parameter %s could not be coerced to []string, is %T", p, args[p]) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | func convertStringSliceToBigIntSlice(s []string) ([]int64, error) { |
| 272 | int64Slice := make([]int64, len(s)) |
no outgoing calls