run go fmt

This commit is contained in:
john 2020-06-14 10:16:08 +08:00
parent a05220f619
commit 4d8150e363
2 changed files with 7 additions and 10 deletions

10
auth.go
View File

@ -21,19 +21,17 @@ type Accounts map[string]string
// authKVMap defines a key/value for Authorization token / user // authKVMap defines a key/value for Authorization token / user
type authKVMap map[string]string type authKVMap map[string]string
func (a authKVMap) searchCredential(authValue string) (string, bool) { func (a authKVMap) searchCredential(authValue string) (string, bool) {
if authValue == "" { if authValue == "" {
return "", false return "", false
} }
user,ok:=a[authValue] user, ok := a[authValue]
if !ok{ if !ok {
return "", false return "", false
} }
return user,true return user, true
} }
// BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as arguments a map[string]string where // 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. // 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. // 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 { for user, password := range accounts {
assert1(user != "", "User can not be empty") assert1(user != "", "User can not be empty")
value := authorizationHeader(user, password) value := authorizationHeader(user, password)
authMap[value]=user authMap[value] = user
} }
return authMap return authMap
} }

View File

@ -20,11 +20,10 @@ func TestBasicAuth(t *testing.T) {
"bar": "foo", "bar": "foo",
}) })
assert.Len(t, authMap, 3) assert.Len(t, authMap, 3)
assert.Contains(t,authMap,"Basic YmFyOmZvbw==") assert.Contains(t, authMap, "Basic YmFyOmZvbw==")
assert.Contains(t,authMap,"Basic Zm9vOmJhcg==") assert.Contains(t, authMap, "Basic Zm9vOmJhcg==")
assert.Contains(t,authMap,"Basic YWRtaW46cGFzc3dvcmQ=") assert.Contains(t, authMap, "Basic YWRtaW46cGFzc3dvcmQ=")
} }