From 019689087d4ebd3a69309d115c53b394ec54192f Mon Sep 17 00:00:00 2001 From: MaysWind Date: Fri, 19 Sep 2025 23:40:37 +0800 Subject: [PATCH] code refactor --- pkg/api/model_context_protocols.go | 4 +--- pkg/core/common_types.go | 4 ++++ pkg/utils/api.go | 7 +++---- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 pkg/core/common_types.go diff --git a/pkg/api/model_context_protocols.go b/pkg/api/model_context_protocols.go index 7c81f403..a5af8fd9 100644 --- a/pkg/api/model_context_protocols.go +++ b/pkg/api/model_context_protocols.go @@ -3,8 +3,6 @@ package api import ( "encoding/json" - "github.com/gin-gonic/gin" - "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -233,7 +231,7 @@ func (a *ModelContextProtocolAPI) CallToolHandler(c *core.WebContext, jsonRPCReq // PingHandler return the ping response for model context protocol func (a *ModelContextProtocolAPI) PingHandler(c *core.WebContext, jsonRPCRequest *core.JSONRPCRequest) (any, *errs.Error) { - return gin.H{}, nil + return core.O{}, nil } // GetTransactionService implements the MCPAvailableServices interface diff --git a/pkg/core/common_types.go b/pkg/core/common_types.go new file mode 100644 index 00000000..d3bf8e05 --- /dev/null +++ b/pkg/core/common_types.go @@ -0,0 +1,4 @@ +package core + +// O is a shortcut for map[string]any +type O map[string]any diff --git a/pkg/utils/api.go b/pkg/utils/api.go index 1edf41c1..75fd7e42 100644 --- a/pkg/utils/api.go +++ b/pkg/utils/api.go @@ -5,7 +5,6 @@ import ( "net/http" "reflect" - "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "github.com/mayswind/ezbookkeeping/pkg/core" @@ -14,7 +13,7 @@ import ( // PrintJsonSuccessResult writes success response in json format to current http context func PrintJsonSuccessResult(c *core.WebContext, result any) { - c.JSON(http.StatusOK, gin.H{ + c.JSON(http.StatusOK, core.O{ "success": true, "result": result, }) @@ -46,7 +45,7 @@ func PrintJsonErrorResult(c *core.WebContext, err *errs.Error) { } } - result := gin.H{ + result := core.O{ "success": false, "errorCode": err.Code(), "errorMessage": errorMessage, @@ -163,7 +162,7 @@ func WriteEventStreamJsonErrorResult(c *core.WebContext, originalErr *errs.Error } } - result := gin.H{ + result := core.O{ "success": false, "errorCode": originalErr.Code(), "errorMessage": errorMessage,