static.go 438 B

12345678910111213141516171819
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/ncarlier/webhookd/pkg/config"
  5. )
  6. func static(prefix string) HandlerFunc {
  7. return func(conf *config.Config) http.Handler {
  8. if conf.Static.Dir != "" {
  9. fs := http.FileServer(http.Dir(conf.Static.Dir))
  10. return http.StripPrefix(prefix, fs)
  11. }
  12. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  13. http.Error(w, "404 page not found", http.StatusNotFound)
  14. })
  15. }
  16. }