From fde6d52c607d3d5be7b11152eaeccfe8a2ecbe7b Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 22 Dec 2023 10:17:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E8=BF=87?= =?UTF-8?q?=E6=97=B6=E7=9A=84=20server.NewHttpWrapper=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E3=80=81server.Server.HttpServer=20=E5=87=BD=E6=95=B0=E5=BD=93?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E4=BD=BF=E7=94=A8=20Gin=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=97=B6=E4=B8=8D=E5=86=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=80=9A=E8=BF=87=20Gin=20=E5=87=BD=E6=95=B0=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/http.go | 6 +++--- server/http_wrapper.go | 12 ------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/server/http.go b/server/http.go index 7ef78e0..830d33d 100644 --- a/server/http.go +++ b/server/http.go @@ -6,7 +6,7 @@ import "github.com/gin-gonic/gin" // - 默认使用 server.HttpContext 作为上下文,如果需要依赖其作为新的上下文,可以通过 NewHttpContext 创建 func NewHttpHandleWrapper[Context any](srv *Server, packer ContextPacker[Context]) *Http[Context] { return &Http[Context]{ - gin: srv.ginServer, + Engine: srv.ginServer, HttpRouter: &HttpRouter[Context]{ srv: srv, group: srv.ginServer, @@ -18,10 +18,10 @@ func NewHttpHandleWrapper[Context any](srv *Server, packer ContextPacker[Context // Http 基于 gin.Engine 包装的 http 服务器 type Http[Context any] struct { srv *Server - gin *gin.Engine + *gin.Engine *HttpRouter[Context] } func (slf *Http[Context]) Gin() *gin.Engine { - return slf.gin + return slf.Engine } diff --git a/server/http_wrapper.go b/server/http_wrapper.go index 5a9cce9..d19e4bd 100644 --- a/server/http_wrapper.go +++ b/server/http_wrapper.go @@ -7,18 +7,6 @@ import ( type HttpWrapperHandleFunc[CTX any] func(ctx CTX) -// NewHttpWrapper 创建 http 包装器 -// -// Deprecated: 从 Minotaur 0.0.29 开始,由于该函数基于 *Server.HttpRouter 函数设计,已弃用。 -// 如果需要单纯的对 *gin.Engine 进行包装,可以使用 NewGinWrapper 函数进行包装。该函数已不在建议对 server.Server 使用。 -// 如果需要对 Server.HttpServer 进行包装,可以使用 NewHttpHandleWrapper 函数进行包装。 -func NewHttpWrapper[CTX any](server *Server, pack func(ctx *gin.Context) CTX) *HttpWrapper[CTX] { - return &HttpWrapper[CTX]{ - server: server.ginServer, - packHandle: pack, - } -} - // NewGinWrapper 创建 gin 包装器,用于对 NewHttpWrapper 函数的替代 func NewGinWrapper[CTX any](server *gin.Engine, pack func(ctx *gin.Context) CTX) *HttpWrapper[CTX] { return &HttpWrapper[CTX]{