Something went wrong. Try again.
forked from darkweak/souin
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package api
import ( "net/http"
"github.com/darkweak/souin/configurationtypes" "github.com/darkweak/souin/pkg/api/debug" "github.com/darkweak/souin/pkg/api/prometheus" "github.com/darkweak/souin/pkg/storage/types" "github.com/darkweak/souin/pkg/surrogate/providers")
// MapHandler is a map to store the available http Handlerstype MapHandler struct { Handlers *map[string]http.HandlerFunc}
// GenerateHandlerMap generate the MapHandlerfunc GenerateHandlerMap( configuration configurationtypes.AbstractConfigurationInterface, storers []types.Storer, surrogateStorage providers.SurrogateInterface,) *MapHandler { hm := make(map[string]http.HandlerFunc) shouldEnable := false
souinAPI := configuration.GetAPI() basePathAPIS := souinAPI.BasePath if basePathAPIS == "" { basePathAPIS = "/souin-api" }
for _, endpoint := range Initialize(configuration, storers, surrogateStorage) { if endpoint.IsEnabled() { shouldEnable = true hm[basePathAPIS+endpoint.GetBasePath()] = endpoint.HandleRequest } }
if shouldEnable { return &MapHandler{Handlers: &hm} }
return nil}
// Initialize contains all apis that should be enabledfunc Initialize(c configurationtypes.AbstractConfigurationInterface, storers []types.Storer, surrogateStorage providers.SurrogateInterface) []EndpointInterface { return []EndpointInterface{initializeSouin(c, storers, surrogateStorage), debug.InitializeDebug(c), prometheus.InitializePrometheus(c)}}