增加task任务配置解析
This commit is contained in:
parent
ba67c79b0d
commit
4b517be8a8
22
define/task.go
Normal file
22
define/task.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Package define...
|
||||||
|
//
|
||||||
|
// Description : define...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2021-11-12 4:57 下午
|
||||||
|
package define
|
||||||
|
|
||||||
|
import "git.zhangdeman.cn/zhangdeman/gopkg/cmd"
|
||||||
|
|
||||||
|
// Task ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 4:59 下午 2021/11/12
|
||||||
|
type Task struct {
|
||||||
|
WorkDir string `json:"work_dir"`
|
||||||
|
Command string `json:"command"`
|
||||||
|
Script string `json:"script"`
|
||||||
|
Parameter []cmd.Parameter `json:"parameter"`
|
||||||
|
}
|
30
git_hook.go
30
git_hook.go
@ -8,15 +8,38 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.zhangdeman.cn/zhangdeman/git-hook/define"
|
||||||
"git.zhangdeman.cn/zhangdeman/gopkg/git_hook"
|
"git.zhangdeman.cn/zhangdeman/gopkg/git_hook"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/gopkg/util"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// CLIParamConfig ...
|
||||||
|
CLIParamConfig map[string]string
|
||||||
|
// TaskList 任务列表
|
||||||
|
TaskList []define.Task
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
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()
|
router := gin.Default()
|
||||||
// 注册回调路由
|
// 注册回调路由
|
||||||
_ = git_hook.RegisterGitHookRouter(router, func(ctx *gin.Context, hookData *git_hook.HookData) *git_hook.ResponseData {
|
_ = git_hook.RegisterGitHookRouter(router, func(ctx *gin.Context, hookData *git_hook.HookData) *git_hook.ResponseData {
|
||||||
if hookData.Ref != "refs/heads/master" {
|
if hookData.Ref != "refs/heads/master" {
|
||||||
// 不是master分支, 不触发相应逻辑
|
// 不是master分支, 不触发相应逻辑
|
||||||
return &git_hook.ResponseData{
|
return &git_hook.ResponseData{
|
||||||
Code: 0,
|
Code: 0,
|
||||||
@ -32,3 +55,8 @@ func main() {
|
|||||||
})
|
})
|
||||||
_ = router.Run(":12590")
|
_ = router.Run(":12590")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseCLIParam() {
|
||||||
|
paramList := []string{"config_path"}
|
||||||
|
CLIParamConfig = util.ParseCLIParameter(paramList)
|
||||||
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -21,6 +21,7 @@ require (
|
|||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/ugorji/go/codec v1.1.7 // indirect
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
|
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
|
||||||
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
|
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
|
||||||
|
5
go.sum
5
go.sum
@ -1,7 +1,3 @@
|
|||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211111140656-6287bc062fd8 h1:8Q8gDw9KrO2RkernimnXD8lPAu63YS2bwuMBK5nfI2o=
|
|
||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211111140656-6287bc062fd8/go.mod h1:+ga94Zdtpve/XVHlc3UbnrxXoNw9HCuGRowxtJsePag=
|
|
||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112034039-2c436b1a6c2f h1:KOJxfoNlRTaNRHa0yUT5rW08Ol2gZJmsnhm1w9YsTq4=
|
|
||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112034039-2c436b1a6c2f/go.mod h1:+ga94Zdtpve/XVHlc3UbnrxXoNw9HCuGRowxtJsePag=
|
|
||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112083432-82f944f28aad h1:mNVzkO4DZDVZ6G66JCaxace9wUx2vKfZqddzj6SqnLQ=
|
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112083432-82f944f28aad h1:mNVzkO4DZDVZ6G66JCaxace9wUx2vKfZqddzj6SqnLQ=
|
||||||
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112083432-82f944f28aad/go.mod h1:+ga94Zdtpve/XVHlc3UbnrxXoNw9HCuGRowxtJsePag=
|
git.zhangdeman.cn/zhangdeman/gopkg v0.0.0-20211112083432-82f944f28aad/go.mod h1:+ga94Zdtpve/XVHlc3UbnrxXoNw9HCuGRowxtJsePag=
|
||||||
github.com/Shopify/sarama v1.29.1/go.mod h1:mdtqvCSg8JOxk8PmpTNGyo6wzd4BMm4QXSfDnTXmgkE=
|
github.com/Shopify/sarama v1.29.1/go.mod h1:mdtqvCSg8JOxk8PmpTNGyo6wzd4BMm4QXSfDnTXmgkE=
|
||||||
@ -114,6 +110,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
github.com/shirou/gopsutil v3.21.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v3.21.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
|
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
Loading…
Reference in New Issue
Block a user