From a63f196e0bd0a217dc3f8616d52da7c06bdf9cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 12 Nov 2021 11:40:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E8=82=8C=E5=A4=84=E7=90=86=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=9A=84=E5=93=8D=E5=BA=94=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git_hook/abstract.go | 2 +- git_hook/define.go | 11 +++++++++++ git_hook/register.go | 11 +++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/git_hook/abstract.go b/git_hook/abstract.go index 4f3ee73..96ed2aa 100644 --- a/git_hook/abstract.go +++ b/git_hook/abstract.go @@ -14,4 +14,4 @@ import "github.com/gin-gonic/gin" // Author : go_developer@163.com<白茶清欢> // // Date : 6:42 下午 2021/11/11 -type IGitHookEventHandler func(ctx *gin.Context, hookData *HookData) +type IGitHookEventHandler func(ctx *gin.Context, hookData *HookData) *ResponseData diff --git a/git_hook/define.go b/git_hook/define.go index 4d5fcf3..31a37ae 100644 --- a/git_hook/define.go +++ b/git_hook/define.go @@ -152,3 +152,14 @@ type CommitAuthor struct { Email string `json:"email"` // 邮箱 Username string `json:"username"` // 用户名 } + +// ResponseData 处理结果的返回值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:37 上午 2021/11/12 +type ResponseData struct { + Code interface{} `json:"code"` + Message string `json:"message"` + Data interface{} `json:"data"` +} diff --git a/git_hook/register.go b/git_hook/register.go index 2543a07..01e644d 100644 --- a/git_hook/register.go +++ b/git_hook/register.go @@ -31,8 +31,15 @@ func RegisterGitHookRouter(router *gin.Engine, handler IGitHookEventHandler) err if err = ctx.ShouldBindJSON(&hookData); nil != err { ctx.JSON(http.StatusBadRequest, gin.H{"code": -1, "message": err.Error()}) } - handler(ctx, &hookData) - // TODO : 响应数据 + responseData := handler(ctx, &hookData) + if nil == responseData { + responseData = &ResponseData{ + Code: 100, + Message: "处理完成(未设置返回值,系统默认返回此信息)", + Data: map[string]interface{} + } + } + ctx.JSON(http.StatusOK, responseData) }) return nil }