From 23323d60e5ef18ac6715d07b8dcec3300dc71a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 30 Nov 2024 14:49:30 +0800 Subject: [PATCH] feat: optimize --- context.go | 6 +++--- context_request.go | 2 +- context_response.go | 2 +- utils.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/context.go b/context.go index 4a5c610..4d5c0f2 100644 --- a/context.go +++ b/context.go @@ -29,13 +29,13 @@ type Context struct { response http.ContextResponse } -func NewContext() http.Context { +func NewContext() *Context { return contextPool.Get().(*Context) } func (c *Context) Request() http.ContextRequest { if c.request == nil { - request := NewContextRequest().(*ContextRequest) + request := NewContextRequest() httpBody, err := getHttpBody(c) if err != nil { LogFacade.Error(fmt.Sprintf("%+v", errors.Unwrap(err))) @@ -51,7 +51,7 @@ func (c *Context) Request() http.ContextRequest { func (c *Context) Response() http.ContextResponse { if c.response == nil { - response := NewContextResponse().(*ContextResponse) + response := NewContextResponse() response.instance = c.instance c.response = response } diff --git a/context_request.go b/context_request.go index d7bf660..16a2f61 100644 --- a/context_request.go +++ b/context_request.go @@ -39,7 +39,7 @@ type ContextRequest struct { validation contractsvalidate.Validation } -func NewContextRequest() contractshttp.ContextRequest { +func NewContextRequest() *ContextRequest { return contextRequestPool.Get().(*ContextRequest) } diff --git a/context_response.go b/context_response.go index 84f9c19..389f1dd 100644 --- a/context_response.go +++ b/context_response.go @@ -19,7 +19,7 @@ type ContextResponse struct { origin contractshttp.ResponseOrigin } -func NewContextResponse() contractshttp.ContextResponse { +func NewContextResponse() *ContextResponse { return contextResponsePool.Get().(*ContextResponse) } diff --git a/utils.go b/utils.go index a2bc8bb..7fa0df5 100644 --- a/utils.go +++ b/utils.go @@ -26,7 +26,7 @@ func middlewaresToGinHandlers(middlewares []httpcontract.Middleware) []gin.Handl func handlerToGinHandler(handler httpcontract.HandlerFunc) gin.HandlerFunc { return func(c *gin.Context) { - context := NewContext().(*Context) + context := NewContext() defer func() { contextRequestPool.Put(context.request) contextResponsePool.Put(context.response) @@ -45,7 +45,7 @@ func handlerToGinHandler(handler httpcontract.HandlerFunc) gin.HandlerFunc { func middlewareToGinHandler(middleware httpcontract.Middleware) gin.HandlerFunc { return func(c *gin.Context) { - context := NewContext().(*Context) + context := NewContext() defer func() { contextRequestPool.Put(context.request) contextResponsePool.Put(context.response)