|
|
|
@ -105,6 +105,15 @@ func TLSConfig(c *tls.Config) ServerOption { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// StrictSlash is with mux's StrictSlash
|
|
|
|
|
// If true, when the path pattern is "/path/", accessing "/path" will
|
|
|
|
|
// redirect to the former and vice versa.
|
|
|
|
|
func StrictSlash(strictSlash bool) ServerOption { |
|
|
|
|
return func(o *Server) { |
|
|
|
|
o.strictSlash = strictSlash |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Server is an HTTP server wrapper.
|
|
|
|
|
type Server struct { |
|
|
|
|
*http.Server |
|
|
|
@ -121,6 +130,7 @@ type Server struct { |
|
|
|
|
dec DecodeRequestFunc |
|
|
|
|
enc EncodeResponseFunc |
|
|
|
|
ene EncodeErrorFunc |
|
|
|
|
strictSlash bool |
|
|
|
|
router *mux.Router |
|
|
|
|
log *log.Helper |
|
|
|
|
} |
|
|
|
@ -134,12 +144,13 @@ func NewServer(opts ...ServerOption) *Server { |
|
|
|
|
dec: DefaultRequestDecoder, |
|
|
|
|
enc: DefaultResponseEncoder, |
|
|
|
|
ene: DefaultErrorEncoder, |
|
|
|
|
strictSlash: true, |
|
|
|
|
log: log.NewHelper(log.DefaultLogger), |
|
|
|
|
} |
|
|
|
|
for _, o := range opts { |
|
|
|
|
o(srv) |
|
|
|
|
} |
|
|
|
|
srv.router = mux.NewRouter() |
|
|
|
|
srv.router = mux.NewRouter().StrictSlash(srv.strictSlash) |
|
|
|
|
srv.router.Use(srv.filter()) |
|
|
|
|
srv.Server = &http.Server{ |
|
|
|
|
Handler: FilterChain(srv.filters...)(srv.router), |
|
|
|
|