Skip to content

Commit 6b819fc

Browse files
committed
auther 使用http request 作为参数
1 parent 36296fb commit 6b819fc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

http/mock/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func NewMockAuther() router.Auther {
2020

2121
type mockAuther struct{}
2222

23-
func (m *mockAuther) Auth(h http.Header) (authInfo interface{}, err error) {
24-
authHeader := h.Get("Authorization")
23+
func (m *mockAuther) Auth(r *http.Request) (authInfo interface{}, err error) {
24+
authHeader := r.Header.Get("Authorization")
2525
if authHeader == "" {
2626
return nil, exception.NewUnauthorized("Authorization missed in header")
2727
}

http/router/auther.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "net/http"
66
// Header 用于鉴定身份
77
// Entry 用于鉴定权限
88
type Auther interface {
9-
Auth(http.Header) (authInfo interface{}, err error)
9+
Auth(*http.Request) (authInfo interface{}, err error)
1010
Permission(authInfo interface{}, entry Entry) (err error)
1111
}
1212

http/router/httprouter/httprouter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (r *httpRouter) addHandler(method, path string, h http.Handler) {
147147
}
148148

149149
if entry.AuthEnable {
150-
ai, err := r.auther.Auth(req.Header)
150+
ai, err := r.auther.Auth(req)
151151
if err != nil {
152152
response.Failed(w, exception.NewUnauthorized(err.Error()))
153153
return

0 commit comments

Comments
 (0)