mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
refactor(main): streamline metrics route handling in main function
This commit is contained in:
parent
e9e932b0b7
commit
ef97e833e6
22
main.go
22
main.go
@ -30,12 +30,6 @@ func main() {
|
|||||||
mirrorHandler := handler.NewMirrorProxyHandler()
|
mirrorHandler := handler.NewMirrorProxyHandler()
|
||||||
proxyHandler := handler.NewProxyHandler(cfg)
|
proxyHandler := handler.NewProxyHandler(cfg)
|
||||||
|
|
||||||
// 添加监控路由
|
|
||||||
http.HandleFunc("/metrics", proxyHandler.AuthMiddleware(proxyHandler.MetricsHandler))
|
|
||||||
http.HandleFunc("/metrics/ui", proxyHandler.MetricsPageHandler)
|
|
||||||
http.HandleFunc("/metrics/auth", proxyHandler.MetricsAuthHandler)
|
|
||||||
http.HandleFunc("/metrics/dashboard", proxyHandler.MetricsDashboardHandler)
|
|
||||||
|
|
||||||
// 创建处理器链
|
// 创建处理器链
|
||||||
handlers := []struct {
|
handlers := []struct {
|
||||||
matcher func(*http.Request) bool
|
matcher func(*http.Request) bool
|
||||||
@ -71,6 +65,22 @@ func main() {
|
|||||||
|
|
||||||
// 创建主处理器
|
// 创建主处理器
|
||||||
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 先处理监控路由
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/metrics":
|
||||||
|
proxyHandler.AuthMiddleware(proxyHandler.MetricsHandler)(w, r)
|
||||||
|
return
|
||||||
|
case "/metrics/ui":
|
||||||
|
proxyHandler.MetricsPageHandler(w, r)
|
||||||
|
return
|
||||||
|
case "/metrics/auth":
|
||||||
|
proxyHandler.MetricsAuthHandler(w, r)
|
||||||
|
return
|
||||||
|
case "/metrics/dashboard":
|
||||||
|
proxyHandler.MetricsDashboardHandler(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 遍历所有处理器
|
// 遍历所有处理器
|
||||||
for _, h := range handlers {
|
for _, h := range handlers {
|
||||||
if h.matcher(r) {
|
if h.matcher(r) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user