mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
run go fmt
This commit is contained in:
parent
a05220f619
commit
4d8150e363
10
auth.go
10
auth.go
@ -21,19 +21,17 @@ type Accounts map[string]string
|
||||
// authKVMap defines a key/value for Authorization token / user
|
||||
type authKVMap map[string]string
|
||||
|
||||
|
||||
func (a authKVMap) searchCredential(authValue string) (string, bool) {
|
||||
if authValue == "" {
|
||||
return "", false
|
||||
}
|
||||
user,ok:=a[authValue]
|
||||
if !ok{
|
||||
user, ok := a[authValue]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return user,true
|
||||
return user, true
|
||||
}
|
||||
|
||||
|
||||
// BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as arguments a map[string]string where
|
||||
// the key is the user name and the value is the password, as well as the name of the Realm.
|
||||
// If the realm is empty, "Authorization Required" will be used by default.
|
||||
@ -73,7 +71,7 @@ func processAccounts(accounts Accounts) authKVMap {
|
||||
for user, password := range accounts {
|
||||
assert1(user != "", "User can not be empty")
|
||||
value := authorizationHeader(user, password)
|
||||
authMap[value]=user
|
||||
authMap[value] = user
|
||||
}
|
||||
return authMap
|
||||
}
|
||||
|
@ -20,11 +20,10 @@ func TestBasicAuth(t *testing.T) {
|
||||
"bar": "foo",
|
||||
})
|
||||
|
||||
|
||||
assert.Len(t, authMap, 3)
|
||||
assert.Contains(t,authMap,"Basic YmFyOmZvbw==")
|
||||
assert.Contains(t,authMap,"Basic Zm9vOmJhcg==")
|
||||
assert.Contains(t,authMap,"Basic YWRtaW46cGFzc3dvcmQ=")
|
||||
assert.Contains(t, authMap, "Basic YmFyOmZvbw==")
|
||||
assert.Contains(t, authMap, "Basic Zm9vOmJhcg==")
|
||||
assert.Contains(t, authMap, "Basic YWRtaW46cGFzc3dvcmQ=")
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user