1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

add prefix handle to register other router

This commit is contained in:
chenzhihui 2021-02-20 19:12:09 +08:00
parent c97bfa41d8
commit 2a011cd288

View File

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