webhookd/pkg/api/static.go
Nicolas Carlier 39ab72bb30
refactor(config): small config refactoring
- split config structure
- improve config logic
- improve test lib and fix typos
2024-03-04 09:13:59 +01:00

20 lines
438 B
Go

package api
import (
"net/http"
"github.com/ncarlier/webhookd/pkg/config"
)
func static(prefix string) HandlerFunc {
return func(conf *config.Config) http.Handler {
if conf.Static.Dir != "" {
fs := http.FileServer(http.Dir(conf.Static.Dir))
return http.StripPrefix(prefix, fs)
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "404 page not found", http.StatusNotFound)
})
}
}