{"record":{"id":"e2db692fdb3a13b7","repo":"kataras/iris","slug":"unsupported-type-of-map-t","errorCode":null,"errorMessage":"unsupported type of map: %T","messagePattern":"unsupported type of map: %T","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/basicauth/user.go","lineNumber":128,"sourceCode":"\t\t\t}\n\t\t}\n\tcase reflect.Map:\n\t\telem := v.Interface()\n\t\tswitch m := elem.(type) {\n\t\tcase map[string]string:\n\t\t\treturn userMap(m, opts...)\n\t\tcase map[string]any:\n\t\t\tusername, password, ok := mapUsernameAndPassword(m)\n\t\t\tif !ok {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcp[username] = &user{\n\t\t\t\tpassword: password,\n\t\t\t\tref:      m,\n\t\t\t}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"unsupported type of map: %T\", users))\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unsupported type: %T\", users))\n\t}\n\n\toptions := toUserAuthOptions(opts)\n\n\treturn func(_ *context.Context, username, password string) (any, bool) {\n\t\tif u, ok := cp[username]; ok { // fast map access,\n\t\t\tif options.ComparePassword(u.password, password) {\n\t\t\t\treturn u.ref, true\n\t\t\t}\n\t\t}\n\n\t\treturn nil, false\n\t}\n}\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/basicauth/user.go#L110-L146","documentation":"AllowUsers accepts users as a map[string]string, map[string]any, a slice of maps, or a slice of User-like structs. This panic fires when the `users` argument is a map whose key/value types are neither string/string nor string/any (e.g. map[int]string). It is a deliberate fail-fast at middleware construction time so a bad configuration never reaches serving.","triggerScenarios":"Calling AllowUsers with a map other than map[string]string or map[string]any, such as AllowUsers(map[int]string{1: \"pass\"}) or a typed map alias like map[string][]byte. Non-map, non-slice values instead hit the sibling \"unsupported type\" panic at line 131.","commonSituations":"Building the users map from config where usernames were parsed as ints; using a custom map type (type Users map[string]Secret) whose value type is not string/any; passing a nil interface typed as a map with non-string keys.","solutions":["Convert the map to map[string]string (or map[string]any) before calling AllowUsers, e.g. via a loop or json round-trip.","If usernames are numeric keys, convert them to strings with strconv when building the map.","If users come from a struct list, pass the slice of structs instead of a map so the Slice branch is used."],"exampleFix":"// before\nusers := map[int]string{1: \"pass\"}\nh := basicauth.Default(basicauth.Options{Allow: basicauth.AllowUsers(users)})\n// after\nusers := map[string]string{\"admin\": \"pass\"}\nh := basicauth.Default(basicauth.Options{Allow: basicauth.AllowUsers(users)})","handlingStrategy":"type-guard","validationCode":"switch users.(type) {\ncase map[string]string, map[string]any:\n    // ok\ndefault:\n    panic(fmt.Sprintf(\"AllowUsers: unsupported map type %T\", users))\n}","typeGuard":"func isSupportedUsersMap(v any) bool {\n    switch v.(type) {\n    case map[string]string, map[string]any:\n        return true\n    }\n    return false\n}","tryCatchPattern":"// panics are not recoverable per-call idiom here; guard before:\nif !isSupportedUsersMap(users) { log.Fatalf(\"unsupported users type %T\", users) }\nallow := basicauth.AllowUsers(users)","preventionTips":["Always declare the users map as map[string]string or map[string]any explicitly.","Convert config-driven maps with a small adapter function before passing to AllowUsers.","Add a startup test that constructs the middleware with the production users value."],"tags":["go","panic","basicauth","type-mismatch","startup"],"backgroundTag":"unsupported-users-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}