Skip to content

Bag in type conversion #152

@agoalofalife

Description

@agoalofalife

switch possibleSlice.(type) {

if the first argument to pass type type MapClaims map[string]interface{}
example how here:

	if !sliceContainsStr(tokenClaims[JWT_ENDPOINTS_ATTR], url) {
			http.Error(w, "", http.StatusUnauthorized)
			return

It switch possibleSlice.(type) { will return interface{}
accordingly, the function will never return true

func sliceContainsStr(possibleSlice interface{}, str string) bool {
	switch possibleSlice.(type) {
	case []string:
		for _, elem := range possibleSlice.([]string) {
			if elem == str {
				return true
			}
		}
	}
	return false
}

I suggest so:

func sliceContainsStr(possibleSlice interface{}, str string) bool {
	if possibleSlice, exist := possibleSlice.([]string); exist {
		for _, elem := range possibleSlice {
			if elem == str {
				return true
			}
		}
	}
	return false
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions