kinda working

This commit is contained in:
wagslane
2023-05-30 21:28:23 -06:00
parent 7d1852d380
commit 80ec635705
91 changed files with 13103 additions and 2 deletions

23
internal/auth/auth.go Normal file
View File

@@ -0,0 +1,23 @@
package auth
import (
"errors"
"net/http"
"strings"
)
var ErrNoAuthHeaderIncluded = errors.New("no authorization header included")
// GetAPIKey -
func GetAPIKey(headers http.Header) (string, error) {
authHeader := headers.Get("Authorization")
if authHeader == "" {
return "", ErrNoAuthHeaderIncluded
}
splitAuth := strings.Split(authHeader, " ")
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
return "", errors.New("malformed authorization header")
}
return splitAuth[1], nil
}