diff --git a/mux.go b/mux.go index 2cbc51b7..d9287041 100644 --- a/mux.go +++ b/mux.go @@ -145,7 +145,7 @@ func Handle(s *Server, path string, controller http.Handler, options ...func(*Ba return Register(s, Route[any, any]{ BaseRoute: BaseRoute{ Path: path, - FullName: FuncName(controller), + FullName: funcName(controller), }, }, controller) } @@ -179,7 +179,7 @@ func registerFuegoController[T, B any, Contexted ctx[B]](s *Server, method, path Method: method, Path: path, Params: make(map[string]OpenAPIParam), - FullName: FuncName(controller), + FullName: funcName(controller), Operation: openapi3.NewOperation(), OpenAPI: s.OpenAPI, } @@ -199,7 +199,7 @@ func registerStdController(s *Server, method, path string, controller func(http. route := BaseRoute{ Method: method, Path: path, - FullName: FuncName(controller), + FullName: funcName(controller), Operation: openapi3.NewOperation(), OpenAPI: s.OpenAPI, } @@ -218,8 +218,8 @@ func withMiddlewares(controller http.Handler, middlewares ...func(http.Handler) return controller } -// FuncName returns the name of a function and the name with package path -func FuncName(f interface{}) string { +// funcName returns the name of a function and the name with package path +func funcName(f interface{}) string { return strings.TrimSuffix(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "-fm") } diff --git a/openapi_handler.go b/openapi_handler.go index 015b257c..4e973a32 100644 --- a/openapi_handler.go +++ b/openapi_handler.go @@ -7,7 +7,12 @@ import ( func DefaultOpenAPIHandler(specURL string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - _, _ = w.Write([]byte(` + _, _ = w.Write([]byte(DefaultOpenAPIHTML(specURL))) + }) +} + +func DefaultOpenAPIHTML(specURL string) string { + return `
@@ -27,6 +32,5 @@ func DefaultOpenAPIHandler(specURL string) http.Handler { tryItCredentialsPolicy="same-origin" /> -`)) - }) +