knowyt/server/handler/authmux.go

30 lines
585 B
Go
Raw Normal View History

2021-07-28 20:21:14 +00:00
package handler
import (
"net/http"
)
2021-07-29 19:06:25 +00:00
type HandlerFunc func(http.ResponseWriter, *http.Request)
2021-07-28 20:21:14 +00:00
type AuthMux struct {
2021-07-29 19:06:25 +00:00
mux *http.ServeMux
2021-07-28 20:21:14 +00:00
}
func NewAuthMux() *AuthMux {
return &(AuthMux{
2021-07-29 19:06:25 +00:00
mux: http.NewServeMux(),
2021-07-28 20:21:14 +00:00
})
}
func (authMux *AuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
authMux.mux.ServeHTTP(w, r)
}
2021-07-29 19:06:25 +00:00
func (authMux *AuthMux) PublicHandleFunc(pattern string, handlerFunc HandlerFunc) {
2021-07-28 20:21:14 +00:00
authMux.mux.HandleFunc(pattern, handlerFunc)
}
func (authMux *AuthMux) PublicHandle(pattern string, handler http.Handler) {
authMux.mux.Handle(pattern, handler)
}