Open agoalofalife opened 6 years ago
https://github.com/HouzuoGuo/tiedot/blob/21707c0a3e12f008577d5384772fbd7ce9bb059d/httpapi/jwt.go#L244
if the first argument to pass type type MapClaims map[string]interface{} example how here:
type MapClaims map[string]interface{}
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
switch possibleSlice.(type) {
interface{}
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 }
how
https://github.com/HouzuoGuo/tiedot/blob/21707c0a3e12f008577d5384772fbd7ce9bb059d/httpapi/jwt.go#L244
if the first argument to pass type
type MapClaims map[string]interface{}
example how here:It
switch possibleSlice.(type) {
will returninterface{}
accordingly, the function will never return trueI suggest so: