// Package git_hook... // // Description : git_hook... // // Author : go_developer@163.com<白茶清欢> // // Date : 2021-10-13 11:11 上午 package main import ( "encoding/json" "git.zhangdeman.cn/zhangdeman/git-hook/define" "git.zhangdeman.cn/zhangdeman/gopkg/git_hook" "git.zhangdeman.cn/zhangdeman/gopkg/util" "github.com/gin-gonic/gin" ) var ( // CLIParamConfig ... CLIParamConfig map[string]string // TaskList 任务列表 TaskList []define.Task ) func main() { parseCLIParam() // 初始化配置 byteData, err := util.ReadFileContent(CLIParamConfig["config_path"] + "/task.json") if nil != err { panic("任务配置文件读取失败 : " + err.Error()) } if err = json.Unmarshal(byteData, &TaskList); nil != err { panic("任务配置文件解析失败 : " + err.Error()) } router := gin.Default() // 注册回调路由 _ = git_hook.RegisterGitHookRouter(router, func(ctx *gin.Context, hookData *git_hook.HookData) *git_hook.ResponseData { if hookData.Ref != "refs/heads/master" { // 不是master分支, 不触发相应逻辑 return &git_hook.ResponseData{ Code: 0, Message: "成功接收到web hook通知, 非master分支,不做任何处理", Data: hookData, } } return &git_hook.ResponseData{ Code: 0, Message: "成功接收到web hook通知", Data: hookData, } }) _ = router.Run(":12590") } func parseCLIParam() { paramList := []string{"config_path"} CLIParamConfig = util.ParseCLIParameter(paramList) }