diff --git a/agent/go.mod b/agent/go.mod index 1587679a..ca7d9c9a 100644 --- a/agent/go.mod +++ b/agent/go.mod @@ -42,7 +42,6 @@ require ( github.com/cloudwego/base64x v0.1.6 // indirect github.com/containerd/errdefs v1.0.0 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect - github.com/coreos/go-oidc/v3 v3.17.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/diskfs/go-diskfs v1.7.0 // indirect github.com/distribution/reference v0.6.0 // indirect @@ -52,7 +51,6 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/ebitengine/purego v0.9.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/gabriel-vasile/mimetype v1.4.12 // indirect github.com/gin-contrib/sse v1.1.0 // indirect github.com/go-acme/lego/v4 v4.30.1 // indirect @@ -66,7 +64,6 @@ require ( github.com/gobwas/glob v0.2.3 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-yaml v1.19.1 // indirect - github.com/golang-jwt/jwt/v5 v5.3.0 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gotify/server/v2 v2.7.3 // indirect github.com/jinzhu/copier v0.4.0 // indirect @@ -120,7 +117,6 @@ require ( golang.org/x/crypto v0.46.0 // indirect golang.org/x/mod v0.31.0 // indirect golang.org/x/net v0.48.0 // indirect - golang.org/x/oauth2 v0.34.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.39.0 // indirect golang.org/x/text v0.32.0 // indirect diff --git a/internal/config/state.go b/internal/config/state.go index 72633a5a..bf3e027b 100644 --- a/internal/config/state.go +++ b/internal/config/state.go @@ -140,8 +140,8 @@ func (state *state) EntrypointHandler() http.Handler { return &state.entrypoint } -func (state *state) Entrypoint() *entrypoint.Entrypoint { - return &state.entrypoint +func (state *state) ShortLinkMatcher() config.ShortLinkMatcher { + return state.entrypoint.ShortLinkMatcher() } // AutoCertProvider returns the autocert provider. diff --git a/internal/config/types/state.go b/internal/config/types/state.go index 9be9ad62..06b26111 100644 --- a/internal/config/types/state.go +++ b/internal/config/types/state.go @@ -6,7 +6,6 @@ import ( "iter" "net/http" - "github.com/yusing/godoxy/internal/entrypoint" "github.com/yusing/godoxy/internal/types" "github.com/yusing/goutils/server" "github.com/yusing/goutils/synk" @@ -23,7 +22,7 @@ type State interface { Value() *Config EntrypointHandler() http.Handler - Entrypoint() *entrypoint.Entrypoint + ShortLinkMatcher() ShortLinkMatcher AutoCertProvider() server.CertProvider LoadOrStoreProvider(key string, value types.RouteProvider) (actual types.RouteProvider, loaded bool) @@ -35,6 +34,12 @@ type State interface { FlushTmpLog() } +type ShortLinkMatcher interface { + AddRoute(alias string) + DelRoute(alias string) + ServeHTTP(w http.ResponseWriter, r *http.Request) +} + // could be nil before first call on Load var ActiveState synk.Value[State] diff --git a/internal/route/fileserver.go b/internal/route/fileserver.go index c5dd4087..b6a97aea 100644 --- a/internal/route/fileserver.go +++ b/internal/route/fileserver.go @@ -126,12 +126,12 @@ func (s *FileServer) Start(parent task.Parent) gperr.Error { routes.HTTP.Add(s) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().AddRoute(s.Alias) + state.ShortLinkMatcher().AddRoute(s.Alias) } s.task.OnFinished("remove_route_from_http", func() { routes.HTTP.Del(s) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().DelRoute(s.Alias) + state.ShortLinkMatcher().DelRoute(s.Alias) } }) return nil diff --git a/internal/route/reverse_proxy.go b/internal/route/reverse_proxy.go index b99687c5..4bc37866 100755 --- a/internal/route/reverse_proxy.go +++ b/internal/route/reverse_proxy.go @@ -168,12 +168,12 @@ func (r *ReveseProxyRoute) Start(parent task.Parent) gperr.Error { } else { routes.HTTP.Add(r) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().AddRoute(r.Alias) + state.ShortLinkMatcher().AddRoute(r.Alias) } r.task.OnCancel("remove_route", func() { routes.HTTP.Del(r) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().DelRoute(r.Alias) + state.ShortLinkMatcher().DelRoute(r.Alias) } }) } @@ -216,12 +216,12 @@ func (r *ReveseProxyRoute) addToLoadBalancer(parent task.Parent) { linked.SetHealthMonitor(lb) routes.HTTP.AddKey(cfg.Link, linked) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().AddRoute(cfg.Link) + state.ShortLinkMatcher().AddRoute(cfg.Link) } r.task.OnFinished("remove_loadbalancer_route", func() { routes.HTTP.DelKey(cfg.Link) if state := config.WorkingState.Load(); state != nil { - state.Entrypoint().ShortLinkMatcher().DelRoute(cfg.Link) + state.ShortLinkMatcher().DelRoute(cfg.Link) } }) lbLock.Unlock()