MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / requireAdmin

Method requireAdmin

internal/payment/shop.go:110–126  ·  view source on GitHub ↗

requireAdmin 要求请求携带有效的管理员 Bearer token。

(next http.HandlerFunc)

Source from the content-addressed store, hash-verified

108
109// requireAdmin 要求请求携带有效的管理员 Bearer token。
110func (s *ShopAPI) requireAdmin(next http.HandlerFunc) http.HandlerFunc {
111 return func(w http.ResponseWriter, r *http.Request) {
112 if s.AdminAuth != nil {
113 const prefix = "Bearer "
114 auth := r.Header.Get("Authorization")
115 token := ""
116 if strings.HasPrefix(auth, prefix) {
117 token = strings.TrimSpace(strings.TrimPrefix(auth, prefix))
118 }
119 if token == "" || !s.AdminAuth.ValidateToken(token) {
120 writeJSONError(w, http.StatusUnauthorized, "admin token required")
121 return
122 }
123 }
124 next(w, r)
125 }
126}
127
128func (s *ShopAPI) listPlansHandler(mode string) http.HandlerFunc {
129 return func(w http.ResponseWriter, r *http.Request) {

Callers 1

RegisterMethod · 0.95

Calls 3

writeJSONErrorFunction · 0.85
GetMethod · 0.65
ValidateTokenMethod · 0.65

Tested by

no test coverage detected