Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 15:49:16 -05:00
pkg-proxy/internal/server/cooldown_profiles.go
2026-11-05 21:42:44 +00:00

26 lines
658 B
Go

package server
import (
"net/http"
"strings"
"github.com/git-pkgs/proxy/internal/handler"
"github.com/go-chi/chi/v5"
)
func (s *Server) mountCooldownProfiles(r chi.Router, proxy *handler.Proxy) error {
if err := s.cfg.Cooldown.ValidateProfiles(); err != nil {
return err
}
for name, cfg := range s.cfg.Cooldown.Profiles {
policy, err := cfg.Policy()
if err != nil {
return err
}
prefix := "/cooldown/" + name
profile := chi.NewRouter()
s.mountProtocolHandlersAt(profile, proxy.WithCooldown(policy, cfg.Shortest()), strings.TrimRight(s.cfg.BaseURL, "/")+prefix)
r.Mount(prefix, http.StripPrefix(prefix, profile))
}
return nil
}