Skip to content

Conversation

AlexanderLieret
Copy link
Contributor

The function contains only allowed to check maps of the type map[string]string. This PR lifts this restriction and allows for arbitrary types to be used.

This commit lifts the restriction of the contains function to only allow
'map[string]string' as an input map. Both the key and value type of the
map can be of an arbitrary type.
@buchdag
Copy link
Member

buchdag commented Apr 29, 2021

@AlexanderLieret maybe the test unit should also be declined for other basic go types like bool, uint and float32 ?

@AlexanderLieret
Copy link
Contributor Author

@buchdag I don't have much experience with go. This was a simple test to test what happens if a wrong key datatype is supplied.

I bit of testing revealed that the types of the keys are compared first. Checking with other types should not be necessary.

m := map[int]bool { 42: true }
m[42] // true
m[42.0] // true
m["42"] // compiler error
m[m] // compiler error
contains(m, 42) // true
contains(m, 42.0) // false
contains(m, "42") // false
contains(m, m) // false

@jwilder jwilder merged commit 4401220 into nginx-proxy:master Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants