Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly handle []any type #110

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 50 additions & 40 deletions amqpjobs/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,58 @@ import (
)

func convHeaders(h amqp.Table) map[string][]string { //nolint:gocyclo
ret := make(map[string][]string)
ret := make(map[string][]string, len(h))
for k := range h {
switch t := h[k].(type) {
case int:
ret[k] = []string{strconv.Itoa(t)}
case int8:
ret[k] = []string{strconv.Itoa(int(t))}
case int16:
ret[k] = []string{strconv.Itoa(int(t))}
case int32:
ret[k] = []string{strconv.Itoa(int(t))}
case int64:
ret[k] = []string{strconv.Itoa(int(t))}
case uint:
ret[k] = []string{strconv.FormatUint(uint64(t), 10)}
case uint8:
ret[k] = []string{strconv.FormatUint(uint64(t), 10)}
case uint16:
ret[k] = []string{strconv.FormatUint(uint64(t), 10)}
case uint32:
ret[k] = []string{strconv.FormatUint(uint64(t), 10)}
case uint64:
ret[k] = []string{strconv.FormatUint(t, 10)}
case float32:
ret[k] = []string{strconv.FormatFloat(float64(t), 'f', 5, 64)}
case float64:
ret[k] = []string{strconv.FormatFloat(t, 'f', 5, 64)}
case string:
ret[k] = []string{t}
case []string:
ret[k] = t
case bool:
switch t {
case true:
ret[k] = []string{"true"}
case false:
ret[k] = []string{"false"}
}
case []byte:
ret[k] = []string{string(t)}
}
// mut ret
convHeadersAnyType(&ret, k, h[k])
}

return ret
}

func convHeadersAnyType(ret *map[string][]string, k string, header any) {
switch t := header.(type) {
case int:
(*ret)[k] = append((*ret)[k], strconv.Itoa(t))
case int8:
(*ret)[k] = append((*ret)[k], strconv.Itoa(int(t)))
case int16:
(*ret)[k] = append((*ret)[k], strconv.Itoa(int(t)))
case int32:
(*ret)[k] = append((*ret)[k], strconv.Itoa(int(t)))
case int64:
(*ret)[k] = append((*ret)[k], strconv.Itoa(int(t)))
rustatian marked this conversation as resolved.
Show resolved Hide resolved
case uint:
(*ret)[k] = append((*ret)[k], strconv.FormatUint(uint64(t), 10))
case uint8:
(*ret)[k] = append((*ret)[k], strconv.FormatUint(uint64(t), 10))
case uint16:
(*ret)[k] = append((*ret)[k], strconv.FormatUint(uint64(t), 10))
case uint32:
(*ret)[k] = append((*ret)[k], strconv.FormatUint(uint64(t), 10))
case uint64:
(*ret)[k] = append((*ret)[k], strconv.FormatUint(t, 10))
case float32:
(*ret)[k] = append((*ret)[k], strconv.FormatFloat(float64(t), 'f', 5, 64))
case float64:
(*ret)[k] = append((*ret)[k], strconv.FormatFloat(t, 'f', 5, 64))
case string:
(*ret)[k] = append((*ret)[k], t)
case []string:
(*ret)[k] = append((*ret)[k], t...)
case bool:
switch t {
case true:
(*ret)[k] = []string{"true"}
case false:
(*ret)[k] = []string{"false"}
}
case []byte:
(*ret)[k] = append((*ret)[k], string(t))
case []any:
for _, v := range t {
// we need to recursively call this function to handle nested slices of primitives
convHeadersAnyType(ret, k, v)
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading