From 2a011cd288f52936e29367a8a68f372a4f643fea Mon Sep 17 00:00:00 2001 From: chenzhihui Date: Sat, 20 Feb 2021 19:12:09 +0800 Subject: [PATCH] add prefix handle to register other router --- transport/http/server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/transport/http/server.go b/transport/http/server.go index a4dd39ce7..4e42f9fb7 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -110,7 +110,7 @@ func NewServer(opts ...ServerOption) *Server { return srv } -// RouteGroup . +// RouteGroup returns a new route group for the URL path prefix. func (s *Server) RouteGroup(prefix string) *RouteGroup { return &RouteGroup{prefix: prefix, router: s.router} } @@ -125,6 +125,11 @@ func (s *Server) HandleFunc(path string, h http.HandlerFunc) { s.router.HandleFunc(path, h) } +// PrefixHanlde registers a new route with a matcher for the URL path prefix. +func (s *Server) PrefixHanlde(prefix string, h http.Handler) { + s.router.PathPrefix(prefix).Handler(h) +} + // ServeHTTP should write reply headers and data to the ResponseWriter and then return. func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) { ctx, cancel := context.WithTimeout(req.Context(), s.timeout)