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-08-01 16:36:02 +00:00
|
|
|
mux *http.ServeMux
|
|
|
|
Port int
|
2021-07-28 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewAuthMux() *AuthMux {
|
2021-08-01 16:36:02 +00:00
|
|
|
mux := AuthMux{
|
|
|
|
mux: http.NewServeMux(),
|
|
|
|
Port: 32039,
|
|
|
|
}
|
|
|
|
http.Handle("/", mux.mux)
|
|
|
|
|
|
|
|
return &mux
|
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)
|
|
|
|
}
|
2021-08-01 16:36:02 +00:00
|
|
|
|
|
|
|
func (authMux *AuthMux) ListenAndServe() {
|
|
|
|
http.ListenAndServe(":32039", nil)
|
|
|
|
}
|