chore: add mercury

This commit is contained in:
xuu
2024-01-22 16:00:58 -07:00
parent b1cc2af8d8
commit af9633c866
51 changed files with 6635 additions and 52 deletions

View File

@@ -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
}