fix: Remove hard coded string

This commit is contained in:
Ce Gao 2021-10-11 16:00:48 +08:00
parent c6e1651d9e
commit d2f078443e
1 changed files with 6 additions and 1 deletions

View File

@ -11,6 +11,11 @@ import (
"github.com/muety/wakapi/utils"
)
const (
// queryApiKey is the query parameter name for api key.
queryApiKey = "api_key"
)
var (
errEmptyKey = fmt.Errorf("the api_key is empty")
)
@ -102,7 +107,7 @@ func (m *AuthenticateMiddleware) tryGetUserByApiKeyHeader(r *http.Request) (*mod
}
func (m *AuthenticateMiddleware) tryGetUserByApiKeyQuery(r *http.Request) (*models.User, error) {
key := r.URL.Query().Get("api_token")
key := r.URL.Query().Get(queryApiKey)
var user *models.User
userKey := strings.TrimSpace(key)
if userKey == "" {