package corehttp import ( "net" "net/http" core "gitlab.dms3.io/dms3/go-dms3/core" ) func RedirectOption(path string, redirect string) ServeOption { handler := &redirectHandler{redirect} return func(n *core.Dms3Node, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { if len(path) > 0 { mux.Handle("/"+path+"/", handler) } else { mux.Handle("/", handler) } return mux, nil } } type redirectHandler struct { path string } func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, i.path, 302) }