refactor(routes): simplify route exclusion check and health check defaults

This commit is contained in:
yusing
2025-12-04 15:12:35 +08:00
parent f2e73af32f
commit 100eac1f3c
7 changed files with 30 additions and 50 deletions

View File

@@ -24,6 +24,8 @@ type (
}
)
var _ types.FileServerRoute = (*FileServer)(nil)
func handler(root string) http.Handler {
return http.FileServer(http.Dir(root))
}
@@ -91,16 +93,12 @@ func (s *FileServer) Start(parent task.Parent) gperr.Error {
}
if s.UseHealthCheck() {
s.HealthMon = monitor.NewFileServerHealthMonitor(s.HealthCheck, s.Root)
s.HealthMon = monitor.NewMonitor(s)
if err := s.HealthMon.Start(s.task); err != nil {
return err
}
}
if s.ShouldExclude() {
return nil
}
routes.HTTP.Add(s)
s.task.OnFinished("remove_route_from_http", func() {
routes.HTTP.Del(s)
@@ -108,6 +106,10 @@ func (s *FileServer) Start(parent task.Parent) gperr.Error {
return nil
}
func (s *FileServer) RootPath() string {
return s.Root
}
// ServeHTTP implements http.Handler.
func (s *FileServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.handler.ServeHTTP(w, req)