chore: add mercury
This commit is contained in:
@@ -8,6 +8,7 @@ type mux struct {
|
||||
*http.ServeMux
|
||||
api *http.ServeMux
|
||||
wellknown *http.ServeMux
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
func (mux *mux) Add(fns ...interface{ RegisterHTTP(*http.ServeMux) }) {
|
||||
@@ -24,16 +25,30 @@ func (mux *mux) Add(fns ...interface{ RegisterHTTP(*http.ServeMux) }) {
|
||||
// log.Printf("WellKnown: %T", fn)
|
||||
fn.RegisterWellKnown(mux.wellknown)
|
||||
}
|
||||
|
||||
if fn, ok := fn.(interface{ RegisterMiddleware(http.Handler) http.Handler }); ok {
|
||||
hdlr := mux.handler
|
||||
// log.Printf("WellKnown: %T", fn)
|
||||
mux.handler = fn.RegisterMiddleware(hdlr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (mux *mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
mux.handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
|
||||
func New() *mux {
|
||||
mux := &mux{
|
||||
api: http.NewServeMux(),
|
||||
wellknown: http.NewServeMux(),
|
||||
ServeMux: http.NewServeMux(),
|
||||
}
|
||||
mux.Handle("/v1/", http.StripPrefix("/v1", mux.api))
|
||||
mux.Handle("/api/v1/", http.StripPrefix("/api/v1", mux.api))
|
||||
mux.Handle("/.well-known/", http.StripPrefix("/.well-known", mux.wellknown))
|
||||
mux.handler = mux.ServeMux
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user