From b731d13a88c510bff66d5ef1928915cd52c9f258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F=E4=B9=90?= Date: Mon, 26 Dec 2022 16:37:40 +0800 Subject: [PATCH] x --- xserver/http.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xserver/http.go b/xserver/http.go index bbd4805..3b268f2 100644 --- a/xserver/http.go +++ b/xserver/http.go @@ -7,29 +7,30 @@ import ( "time" ) -type httpServer struct { +type Http struct { server *http.Server } -func (h *httpServer) Start() error { +func (h *Http) Start() error { return h.server.ListenAndServe() } -func (h *httpServer) Shutdown(ctx context.Context) error { +func (h *Http) Shutdown(ctx context.Context) error { return h.server.Shutdown(ctx) } -func NewHttp(httpHost string, app *gin.Engine) *httpServer { - server := &http.Server{ - Addr: httpHost, - Handler: app, - ReadTimeout: 60 * time.Second, - WriteTimeout: 60 * time.Second, - MaxHeaderBytes: 20 << 20, +func NewHttp(httpHost string, app *gin.Engine) *Http { + return &Http{ + server: &http.Server{ + Addr: httpHost, + Handler: app, + ReadTimeout: 60 * time.Second, + WriteTimeout: 60 * time.Second, + MaxHeaderBytes: 20 << 20, + }, } - return &httpServer{server: server} } -func (c *httpServer) Name() string { +func (c *Http) Name() string { return "http" }