feat: 实现管理后台 A3 注册群消息概览与 metrics 门禁

This commit is contained in:
Nixevol
2026-09-30 08:12:19 +08:00
parent 19a8ec95fa
commit 77d2dbddb1
13 changed files with 1593 additions and 82 deletions
+29
View File
@@ -0,0 +1,29 @@
package httpx
import (
"net/http"
"strings"
)
// MetricsGate 实现 DEVELOPMENT 4.3 节 /metrics 访问规则(共用端口)。
// token 为空返回 404;Authorization Bearer 不匹配返回 401;匹配则交给 next。
// 后台单独监听时不要包这层,直接挂 metrics Handler。
func MetricsGate(token string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if token == "" {
http.NotFound(w, r)
return
}
auth := r.Header.Get("Authorization")
const prefix = "Bearer "
if !strings.HasPrefix(auth, prefix) || auth[len(prefix):] != token {
w.WriteHeader(http.StatusUnauthorized)
return
}
if next == nil {
http.NotFound(w, r)
return
}
next.ServeHTTP(w, r)
})
}