chores: refactor struct and structure project

This commit is contained in:
ericprd
2025-03-05 21:21:44 +08:00
parent 13a8481f22
commit 567e0e32ca
103 changed files with 1125 additions and 731 deletions
+30
View File
@@ -0,0 +1,30 @@
package utils
import (
"fmt"
"net/http"
"strings"
)
const SessionHeader = "Authorization"
func GetToken(r *http.Request) (string, error) {
token := getTokenFromHeader(r)
if token == "" {
return "", fmt.Errorf("token not found")
}
return token, nil
}
func getTokenFromHeader(r *http.Request) string {
session := r.Header.Get(SessionHeader)
arr := strings.Split(session, " ")
if len(arr) != 2 || strings.ToUpper(arr[0]) != "BEARER" {
return ""
}
return arr[1]
}