Add log and auth modules
This commit is contained in:
25
modules/auth/auth.go
Normal file
25
modules/auth/auth.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
"strings"
|
||||
|
||||
"code.as/writeas/web/modules/log"
|
||||
)
|
||||
|
||||
// GetToken parses out the user token from an Authorization header.
|
||||
func GetToken(header string) []byte {
|
||||
var accessToken []byte
|
||||
if len(header) > 0 {
|
||||
f := strings.Fields(header)
|
||||
if len(f) == 2 && f[0] == "Token" {
|
||||
t, err := uuid.ParseHex(f[1])
|
||||
if err != nil {
|
||||
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
||||
} else {
|
||||
accessToken = t[:]
|
||||
}
|
||||
}
|
||||
}
|
||||
return accessToken
|
||||
}
|
Reference in New Issue
Block a user