refactor(route): unify common fields into routes.go

This commit is contained in:
yusing
2025-06-05 18:25:15 +08:00
parent d3568d9c35
commit 9470a14fe8
4 changed files with 15 additions and 68 deletions

View File

@@ -11,7 +11,6 @@ import (
"github.com/yusing/go-proxy/internal/net/gphttp/middleware"
"github.com/yusing/go-proxy/internal/route/routes"
"github.com/yusing/go-proxy/internal/task"
"github.com/yusing/go-proxy/internal/watcher/health"
"github.com/yusing/go-proxy/internal/watcher/health/monitor"
)
@@ -19,9 +18,6 @@ type (
FileServer struct {
*Route
Health *monitor.FileServerHealthMonitor `json:"health"`
task *task.Task
middleware *middleware.Middleware
handler http.Handler
accessLogger *accesslog.AccessLogger
@@ -90,8 +86,8 @@ func (s *FileServer) Start(parent task.Parent) gperr.Error {
}
if s.UseHealthCheck() {
s.Health = monitor.NewFileServerHealthMonitor(s.HealthCheck, s.Root)
if err := s.Health.Start(s.task); err != nil {
s.HealthMon = monitor.NewFileServerHealthMonitor(s.HealthCheck, s.Root)
if err := s.HealthMon.Start(s.task); err != nil {
return err
}
}
@@ -111,15 +107,6 @@ func (s *FileServer) Start(parent task.Parent) gperr.Error {
return nil
}
func (s *FileServer) Task() *task.Task {
return s.task
}
// Finish implements task.TaskFinisher.
func (s *FileServer) Finish(reason any) {
s.task.Finish(reason)
}
// ServeHTTP implements http.Handler.
func (s *FileServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.handler.ServeHTTP(w, req)
@@ -127,7 +114,3 @@ func (s *FileServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.accessLogger.Log(req, req.Response)
}
}
func (s *FileServer) HealthMonitor() health.HealthMonitor {
return s.Health
}