|
|
@ -11,6 +11,7 @@ import (
|
|
|
|
"github.com/zeromicro/go-zero/rest/chain"
|
|
|
|
"github.com/zeromicro/go-zero/rest/chain"
|
|
|
|
"github.com/zeromicro/go-zero/rest/handler"
|
|
|
|
"github.com/zeromicro/go-zero/rest/handler"
|
|
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/rest/internal"
|
|
|
|
"github.com/zeromicro/go-zero/rest/internal/cors"
|
|
|
|
"github.com/zeromicro/go-zero/rest/internal/cors"
|
|
|
|
"github.com/zeromicro/go-zero/rest/router"
|
|
|
|
"github.com/zeromicro/go-zero/rest/router"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -19,6 +20,9 @@ type (
|
|
|
|
// RunOption defines the method to customize a Server.
|
|
|
|
// RunOption defines the method to customize a Server.
|
|
|
|
RunOption func(*Server)
|
|
|
|
RunOption func(*Server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StartOption defines the method to customize http server.
|
|
|
|
|
|
|
|
StartOption func(svr *http.Server)
|
|
|
|
|
|
|
|
|
|
|
|
// A Server is a http server.
|
|
|
|
// A Server is a http server.
|
|
|
|
Server struct {
|
|
|
|
Server struct {
|
|
|
|
ngin *engine
|
|
|
|
ngin *engine
|
|
|
@ -112,8 +116,12 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// Start starts the Server.
|
|
|
|
// Start starts the Server.
|
|
|
|
// Graceful shutdown is enabled by default.
|
|
|
|
// Graceful shutdown is enabled by default.
|
|
|
|
// Use proc.SetTimeToForceQuit to customize the graceful shutdown period.
|
|
|
|
// Use proc.SetTimeToForceQuit to customize the graceful shutdown period.
|
|
|
|
func (s *Server) Start() {
|
|
|
|
func (s *Server) Start(opts ...StartOption) {
|
|
|
|
handleError(s.ngin.start(s.router))
|
|
|
|
var startOption []internal.StartOption
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
|
|
|
startOption = append(startOption, internal.StartOption(opt))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(s.ngin.start(s.router, startOption...))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Stop stops the Server.
|
|
|
|
// Stop stops the Server.
|
|
|
|