mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-04 02:42:34 +02:00
reset favicon cache on route reload
This commit is contained in:
parent
eac3afba52
commit
585b81c12e
5 changed files with 17 additions and 16 deletions
4
go.mod
4
go.mod
|
@ -3,6 +3,7 @@ module github.com/yusing/go-proxy
|
||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/PuerkitoBio/goquery v1.10.1
|
||||||
github.com/coder/websocket v1.8.12
|
github.com/coder/websocket v1.8.12
|
||||||
github.com/coreos/go-oidc/v3 v3.12.0
|
github.com/coreos/go-oidc/v3 v3.12.0
|
||||||
github.com/docker/cli v27.4.1+incompatible
|
github.com/docker/cli v27.4.1+incompatible
|
||||||
|
@ -16,6 +17,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.4.0
|
github.com/puzpuzpuz/xsync/v3 v3.4.0
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/rs/zerolog v1.33.0
|
||||||
|
github.com/vincent-petithory/dataurl v1.0.0
|
||||||
golang.org/x/crypto v0.32.0
|
golang.org/x/crypto v0.32.0
|
||||||
golang.org/x/net v0.34.0
|
golang.org/x/net v0.34.0
|
||||||
golang.org/x/oauth2 v0.25.0
|
golang.org/x/oauth2 v0.25.0
|
||||||
|
@ -26,7 +28,6 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
github.com/PuerkitoBio/goquery v1.10.1 // indirect
|
|
||||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
|
@ -63,7 +64,6 @@ require (
|
||||||
github.com/prometheus/common v0.61.0 // indirect
|
github.com/prometheus/common v0.61.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
github.com/vincent-petithory/dataurl v1.0.0 // indirect
|
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
|
||||||
go.opentelemetry.io/otel v1.33.0 // indirect
|
go.opentelemetry.io/otel v1.33.0 // indirect
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
v1 "github.com/yusing/go-proxy/internal/api/v1"
|
v1 "github.com/yusing/go-proxy/internal/api/v1"
|
||||||
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
||||||
|
"github.com/yusing/go-proxy/internal/api/v1/favicon"
|
||||||
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
config "github.com/yusing/go-proxy/internal/config/types"
|
config "github.com/yusing/go-proxy/internal/config/types"
|
||||||
|
@ -37,7 +38,7 @@ func NewHandler(cfg config.ConfigInstance) http.Handler {
|
||||||
mux.HandleFunc("GET", "/v1/schema/{filename...}", v1.GetSchemaFile)
|
mux.HandleFunc("GET", "/v1/schema/{filename...}", v1.GetSchemaFile)
|
||||||
mux.HandleFunc("GET", "/v1/stats", useCfg(cfg, v1.Stats))
|
mux.HandleFunc("GET", "/v1/stats", useCfg(cfg, v1.Stats))
|
||||||
mux.HandleFunc("GET", "/v1/stats/ws", useCfg(cfg, v1.StatsWS))
|
mux.HandleFunc("GET", "/v1/stats/ws", useCfg(cfg, v1.StatsWS))
|
||||||
mux.HandleFunc("GET", "/v1/favicon/{alias}", auth.RequireAuth(v1.GetFavIcon))
|
mux.HandleFunc("GET", "/v1/favicon/{alias}", auth.RequireAuth(favicon.GetFavIcon))
|
||||||
return mux
|
return mux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package v1
|
package favicon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/homepage"
|
"github.com/yusing/go-proxy/internal/homepage"
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
gphttp "github.com/yusing/go-proxy/internal/net/http"
|
gphttp "github.com/yusing/go-proxy/internal/net/http"
|
||||||
|
"github.com/yusing/go-proxy/internal/route/routes"
|
||||||
route "github.com/yusing/go-proxy/internal/route/types"
|
route "github.com/yusing/go-proxy/internal/route/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,8 +67,8 @@ func GetFavIcon(w http.ResponseWriter, req *http.Request) {
|
||||||
U.RespondError(w, U.ErrMissingKey("alias"), http.StatusBadRequest)
|
U.RespondError(w, U.ErrMissingKey("alias"), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := listRoute(alias)
|
r, ok := routes.GetHTTPRoutes().Load(alias)
|
||||||
if r == nil {
|
if !ok {
|
||||||
http.NotFound(w, req)
|
http.NotFound(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,12 @@ var (
|
||||||
iconCacheMu sync.RWMutex
|
iconCacheMu sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ResetIconCache(route route.HTTPRoute) {
|
||||||
|
iconCacheMu.Lock()
|
||||||
|
defer iconCacheMu.Unlock()
|
||||||
|
delete(iconCache, route.TargetName())
|
||||||
|
}
|
||||||
|
|
||||||
func loadIconCache(key string) (icon []byte, ok bool) {
|
func loadIconCache(key string) (icon []byte, ok bool) {
|
||||||
iconCacheMu.RLock()
|
iconCacheMu.RLock()
|
||||||
icon, ok = iconCache[key]
|
icon, ok = iconCache[key]
|
||||||
|
@ -158,7 +165,6 @@ func sanitizeName(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func findIcon(r route.HTTPRoute, req *http.Request, uri string) (icon []byte, status int, errMsg string) {
|
func findIcon(r route.HTTPRoute, req *http.Request, uri string) (icon []byte, status int, errMsg string) {
|
||||||
// FIXME: invalidate cache on route change
|
|
||||||
key := r.TargetName()
|
key := r.TargetName()
|
||||||
icon, ok := loadIconCache(key)
|
icon, ok := loadIconCache(key)
|
||||||
if ok {
|
if ok {
|
|
@ -1,7 +1,5 @@
|
||||||
package homepage
|
package homepage
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
//nolint:recvcheck
|
//nolint:recvcheck
|
||||||
Config map[string]Category
|
Config map[string]Category
|
||||||
|
@ -39,13 +37,6 @@ func (c *Config) Clear() {
|
||||||
*c = make(Config)
|
*c = make(Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cleanName = strings.NewReplacer(
|
|
||||||
" ", "-",
|
|
||||||
"_", "-",
|
|
||||||
"(", "",
|
|
||||||
")", "",
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c Config) Add(item *Item) {
|
func (c Config) Add(item *Item) {
|
||||||
if c[item.Category] == nil {
|
if c[item.Category] == nil {
|
||||||
c[item.Category] = make(Category, 0)
|
c[item.Category] = make(Category, 0)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/yusing/go-proxy/internal/api/v1/favicon"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
"github.com/yusing/go-proxy/internal/docker"
|
"github.com/yusing/go-proxy/internal/docker"
|
||||||
"github.com/yusing/go-proxy/internal/docker/idlewatcher"
|
"github.com/yusing/go-proxy/internal/docker/idlewatcher"
|
||||||
|
@ -160,6 +161,8 @@ func (r *HTTPRoute) Start(parent task.Parent) E.Error {
|
||||||
if common.PrometheusEnabled {
|
if common.PrometheusEnabled {
|
||||||
r.task.OnCancel("metrics_cleanup", r.rp.UnregisterMetrics)
|
r.task.OnCancel("metrics_cleanup", r.rp.UnregisterMetrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.task.OnCancel("reset_favicon", func() { favicon.ResetIconCache(r) })
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue