From 274953cabc716cb1fe7d8551b0cbec231600625c Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 15:27:06 +0800 Subject: [PATCH 1/7] refactor: use cli framework and handlers structure --- cli/0module.go | 13 +++++++++ cli/app.go | 59 +++++++++++++++++++++++++++++++++++++++ cli/commands/0module.go | 11 ++++++++ cli/commands/fabing.go | 57 +++++++++++++++++++++++++++++++++++++ cli/commands/fadian.go | 54 +++++++++++++++++++++++++++++++++++ cli/commands/not_found.go | 12 ++++++++ data/bootstrap.go | 8 ++---- data/sections/fabing.txt | 42 ++++++++++++++-------------- data/sections/fadian.txt | 16 +++++------ entry/bootstrap.go | 22 ++------------- entry/entry.go | 4 +-- go.mod | 15 +++++++--- go.sum | 15 ++++++++++ internal/log/0module.go | 2 +- internal/log/log.go | 24 ++++++++-------- main.go | 30 ++++++++++++-------- service/0module.go | 21 -------------- service/fabing/init.go | 11 -------- service/fabing/service.go | 39 -------------------------- service/fadian/init.go | 11 -------- service/fadian/service.go | 39 -------------------------- service/runner/runner.go | 45 ----------------------------- 22 files changed, 301 insertions(+), 249 deletions(-) create mode 100644 cli/0module.go create mode 100644 cli/app.go create mode 100644 cli/commands/0module.go create mode 100644 cli/commands/fabing.go create mode 100644 cli/commands/fadian.go create mode 100644 cli/commands/not_found.go delete mode 100644 service/0module.go delete mode 100644 service/fabing/init.go delete mode 100644 service/fabing/service.go delete mode 100644 service/fadian/init.go delete mode 100644 service/fadian/service.go delete mode 100644 service/runner/runner.go diff --git a/cli/0module.go b/cli/0module.go new file mode 100644 index 0000000..fb63eb4 --- /dev/null +++ b/cli/0module.go @@ -0,0 +1,13 @@ +package cli + +import ( + "github.com/afadian/fadian-go/cli/commands" + "go.uber.org/fx" +) + +func Module() fx.Option { + return fx.Options( + commands.Module(), + fx.Invoke(InvokeApp), + ) +} diff --git a/cli/app.go b/cli/app.go new file mode 100644 index 0000000..0cefc16 --- /dev/null +++ b/cli/app.go @@ -0,0 +1,59 @@ +package cli + +import ( + "context" + "fmt" + "go.uber.org/zap" + "os" + "time" + + "github.com/urfave/cli/v2" + "go.uber.org/fx" +) + +type Params struct { + fx.In + Version string `name:"version"` + Commit string `name:"commit"` + + Commands []*cli.Command `group:"root_commands"` + HandleNotFound cli.CommandNotFoundFunc +} + +func InvokeApp(lc fx.Lifecycle, params Params) { + app := &cli.App{ + Name: "fadian-go", + Usage: "发癫", + Version: fmt.Sprintf("%s-%s", params.Version, params.Commit), + Copyright: fmt.Sprintf("2022-%d © 爱发癫 All Rights Reserved", time.Now().Year()), + Authors: []*cli.Author{ + {Name: "AH Dark", Email: "ahdark@outlook.com"}, + {Name: "Kevin Williams", Email: ""}, // TODO: add email + {Name: "Purofle", Email: ""}, // TODO: add email + }, + EnableBashCompletion: true, + CommandNotFound: params.HandleNotFound, + Commands: params.Commands, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "debug", + Aliases: []string{"d"}, + Usage: "是否开启调试模式", + EnvVars: []string{"DEBUG"}, + }, + &cli.IntFlag{ + Name: "num", + Usage: "重复次数", + Value: 1, + }, + }, + } + + lc.Append(fx.Hook{ + OnStart: func(ctx context.Context) error { + return app.RunContext(ctx, os.Args) + }, + }) + + zap.L().Debug("app initialized") +} diff --git a/cli/commands/0module.go b/cli/commands/0module.go new file mode 100644 index 0000000..5c24452 --- /dev/null +++ b/cli/commands/0module.go @@ -0,0 +1,11 @@ +package commands + +import "go.uber.org/fx" + +func Module() fx.Option { + return fx.Module("cli.commands", + fx.Provide(HandleNotFound), + fx.Provide(fx.Annotate(HandleFabing, fx.ResultTags(`group:"root_commands"`))), + fx.Provide(fx.Annotate(HandleFadian, fx.ResultTags(`group:"root_commands"`))), + ) +} diff --git a/cli/commands/fabing.go b/cli/commands/fabing.go new file mode 100644 index 0000000..7e5252e --- /dev/null +++ b/cli/commands/fabing.go @@ -0,0 +1,57 @@ +package commands + +import ( + "bytes" + "fmt" + "github.com/afadian/fadian-go/data/sections" + "github.com/samber/lo" + "github.com/urfave/cli/v2" + "github.com/vinta/pangu" + "go.uber.org/zap" + "strings" + "text/template" +) + +func HandleFabing() (*cli.Command, error) { + tpl, err := template.New("fabing").Parse(sections.FabingText) + if err != nil { + zap.L().Error("failed to parse fabing template", zap.Error(err)) + return nil, err + } + + zap.L().Debug("fabing template parsed", zap.String("template", sections.FabingText)) + + type FabingParams struct { + Name string + } + + return &cli.Command{ + Name: "fabing", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "name", + Aliases: []string{"n"}, + Usage: "name to be fabing", + Required: true, + }, + }, + Action: func(c *cli.Context) error { + buf := bytes.NewBuffer([]byte{}) + if err := tpl.Execute(buf, FabingParams{ + Name: c.String("name"), + }); err != nil { + zap.L().Error("failed to execute fabing template", zap.Error(err)) + return err + } + + str := pangu.SpacingText(buf.String()) + zap.L().Debug("fabing text generated", zap.String("text", str)) + + fmt.Sprintln(strings.Join(lo.RepeatBy(c.Int("num"), func(_ int) string { + return str + }), "\n")) + + return nil + }, + }, nil +} diff --git a/cli/commands/fadian.go b/cli/commands/fadian.go new file mode 100644 index 0000000..3624be2 --- /dev/null +++ b/cli/commands/fadian.go @@ -0,0 +1,54 @@ +package commands + +import ( + "bytes" + "fmt" + "github.com/afadian/fadian-go/data/sections" + "github.com/samber/lo" + "github.com/urfave/cli/v2" + "github.com/vinta/pangu" + "go.uber.org/zap" + "strings" + "text/template" +) + +func HandleFadian() (*cli.Command, error) { + tpl, err := template.New("fadian").Parse(sections.FadianText) + if err != nil { + zap.L().Error("failed to parse fadian template", zap.Error(err)) + return nil, err + } + + type FadianParams struct { + Name string + } + + return &cli.Command{ + Name: "fadian", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "name", + Aliases: []string{"n"}, + Usage: "name to be fadian", + Required: true, + }, + }, + Action: func(c *cli.Context) error { + buf := bytes.NewBuffer([]byte{}) + if err := tpl.Execute(buf, FadianParams{ + Name: c.String("name"), + }); err != nil { + zap.L().Error("failed to execute fadian template", zap.Error(err)) + return err + } + + str := pangu.SpacingText(buf.String()) + + fmt.Println(strings.Join(lo.RepeatBy(c.Int("num"), func(_ int) string { + return str + }), "\n")) + + return nil + }, + }, nil +} diff --git a/cli/commands/not_found.go b/cli/commands/not_found.go new file mode 100644 index 0000000..776cc1d --- /dev/null +++ b/cli/commands/not_found.go @@ -0,0 +1,12 @@ +package commands + +import ( + "github.com/urfave/cli/v2" + "go.uber.org/zap" +) + +func HandleNotFound() cli.CommandNotFoundFunc { + return func(context *cli.Context, command string) { + zap.L().Error("command not found", zap.String("command", command)) + } +} diff --git a/data/bootstrap.go b/data/bootstrap.go index f4b8b38..10717fe 100644 --- a/data/bootstrap.go +++ b/data/bootstrap.go @@ -1,9 +1,7 @@ package data type BootstrapParams struct { - Name string - IsInteractive bool - IsFabing bool - Num int - Debug bool + Version string + Commit string + Debug bool } diff --git a/data/sections/fabing.txt b/data/sections/fabing.txt index 025e57b..4f61804 100644 --- a/data/sections/fabing.txt +++ b/data/sections/fabing.txt @@ -1,31 +1,31 @@ -$name……🤤 + {{ .Name }} ……🤤 嘿嘿………🤤, -……好可爱……嘿嘿……$name🤤, -……$name……我的🤤, +……好可爱……嘿嘿…… {{ .Name }} 🤤, +…… {{ .Name }} ……我的🤤, ……嘿嘿……🤤, -………亲爱的……赶紧让我抱一抱……啊啊啊$name软软的脸蛋🤤还有软软的小手手……🤤, -…$name……不会有人来伤害你的…🤤, +………亲爱的……赶紧让我抱一抱……啊啊啊 {{ .Name }} 软软的脸蛋🤤还有软软的小手手……🤤, +… {{ .Name }} ……不会有人来伤害你的…🤤, 你就让我保护你吧嘿嘿嘿嘿嘿嘿嘿嘿🤤, ……太可爱了……🤤, -……美丽可爱的$name……像珍珠一样……🤤, -嘿嘿……$name……🤤, +……美丽可爱的 {{ .Name }} ……像珍珠一样……🤤, +嘿嘿…… {{ .Name }} ……🤤, 嘿嘿……🤤, -……好想一口吞掉……🤤……但是舍不得啊……我的$name🤤, +……好想一口吞掉……🤤……但是舍不得啊……我的 {{ .Name }} 🤤, ……嘿嘿……🤤, -我的宝贝……我最可爱的$name……🤤, -没有$name……我就要死掉了呢……🤤, +我的宝贝……我最可爱的 {{ .Name }} ……🤤, +没有 {{ .Name }} ……我就要死掉了呢……🤤, 我的……🤤, -嘿嘿……可爱的$name……嘿嘿🤤, -……可爱的$name……嘿嘿🤤🤤, -……可爱的$name……🤤, +嘿嘿……可爱的 {{ .Name }} ……嘿嘿🤤, +……可爱的 {{ .Name }} ……嘿嘿🤤🤤, +……可爱的 {{ .Name }} ……🤤, ……嘿嘿🤤, -……可爱的$name…(吸)身上的味道……好好闻~🤤, +……可爱的 {{ .Name }} …(吸)身上的味道……好好闻~🤤, …嘿嘿🤤, -……摸摸~……可爱的$name……再贴近我一点嘛……(蹭蹭)嘿嘿🤤, -……可爱的$name……嘿嘿🤤, -……~亲一口~……可爱的$name……嘿嘿🤤, -……抱抱你~可爱的$name~(舔)喜欢~真的好喜欢~……(蹭蹭)🤤, -脑袋要融化了呢~已经……除了$name以外~什么都不会想了呢~🤤, +……摸摸~……可爱的 {{ .Name }} ……再贴近我一点嘛……(蹭蹭)嘿嘿🤤, +……可爱的 {{ .Name }} ……嘿嘿🤤, +……~亲一口~……可爱的 {{ .Name }} ……嘿嘿🤤, +……抱抱你~可爱的 {{ .Name }} ~(舔)喜欢~真的好喜欢~……(蹭蹭)🤤, +脑袋要融化了呢~已经……除了 {{ .Name }} 以外~什么都不会想了呢~🤤, 嘿嘿🤤, -……可爱的$name……嘿嘿🤤, -……可爱的$name……我的~……嘿嘿🤤 +……可爱的 {{ .Name }} ……嘿嘿🤤, +……可爱的 {{ .Name }} ……我的~……嘿嘿🤤 diff --git a/data/sections/fadian.txt b/data/sections/fadian.txt index 69070e4..521f1d1 100644 --- a/data/sections/fadian.txt +++ b/data/sections/fadian.txt @@ -1,18 +1,18 @@ -我好想做$name小姐的狗啊。 -可是$name小姐说她喜欢的是猫,我哭了。 +我好想做 {{ .Name }} 小姐的狗啊。 +可是 {{ .Name }} 小姐说她喜欢的是猫,我哭了。 我知道既不是狗也不是猫的我为什么要哭的。因为我其实是一只老鼠。 -我从没奢望$name小姐能喜欢自己。我明白的,所有人都喜欢理解余裕上手天才打钱的萌萌的狗狗或者猫猫,没有人会喜欢阴湿带病的老鼠。 -但我还是问了$name小姐:“我能不能做你的狗?” +我从没奢望 {{ .Name }} 小姐能喜欢自己。我明白的,所有人都喜欢理解余裕上手天才打钱的萌萌的狗狗或者猫猫,没有人会喜欢阴湿带病的老鼠。 +但我还是问了 {{ .Name }} 小姐:“我能不能做你的狗?” 我知道我是注定做不了狗的。但如果她喜欢狗,我就可以一直在身边看着她了,哪怕她怀里抱着的永远都是狗。 可是她说喜欢的是猫。 她现在还在看着我,还在逗我开心,是因为猫还没有出现,只有我这老鼠每天蹑手蹑脚地从洞里爬出来,远远地和她对视。 等她喜欢的猫来了的时候,我就该重新滚回我的洞了吧。 但我还是好喜欢她,她能在我还在她身边的时候多看我几眼吗? -$name小姐说接下来的每个圣诞夜都要和大家一起过。我不知道大家指哪些人。好希望这个集合能够对我做一次胞吞。 -猫猫还在害怕$name小姐。 +{{ .Name }} 小姐说接下来的每个圣诞夜都要和大家一起过。我不知道大家指哪些人。好希望这个集合能够对我做一次胞吞。 +猫猫还在害怕 {{ .Name }} 小姐。 我会去把她爱的猫猫引来的。 我知道稍有不慎,我就会葬身猫口。 -那时候$name小姐大概会把我的身体好好地装起来扔到门外吧。 +那时候 {{ .Name }} 小姐大概会把我的身体好好地装起来扔到门外吧。 那我就成了一包鼠条,嘻嘻。 我希望她能把我扔得近一点,因为我还是好喜欢她。会一直喜欢下去的。 -我的灵魂透过窗户向里面看去,挂着的铃铛在轻轻鸣响,$name小姐慵懒地靠在沙发上,表演得非常温顺的橘猫坐在她的肩膀。壁炉的火光照在她的脸庞,我冻僵的心脏在风里微微发烫。 +我的灵魂透过窗户向里面看去,挂着的铃铛在轻轻鸣响, {{ .Name }} 小姐慵懒地靠在沙发上,表演得非常温顺的橘猫坐在她的肩膀。壁炉的火光照在她的脸庞,我冻僵的心脏在风里微微发烫。 diff --git a/entry/bootstrap.go b/entry/bootstrap.go index 0583628..12387a3 100644 --- a/entry/bootstrap.go +++ b/entry/bootstrap.go @@ -2,8 +2,6 @@ package entry import ( "context" - "github.com/afadian/fadian-go/service/runner" - "os" "go.uber.org/fx" "go.uber.org/zap" @@ -16,7 +14,9 @@ func Initialize(ctx context.Context, params *data.BootstrapParams) *fx.App { opts := []fx.Option{ fx.Supply( fx.Annotate(ctx, fx.As(new(context.Context))), - params, + fx.Annotate(params.Version, fx.ResultTags(`name:"version"`)), + fx.Annotate(params.Commit, fx.ResultTags(`name:"commit"`)), + fx.Annotate(params.Debug, fx.ResultTags(`name:"debug"`)), ), } @@ -29,21 +29,5 @@ func Initialize(ctx context.Context, params *data.BootstrapParams) *fx.App { opts = append(opts, fx.WithLogger(log.FX)) } - opts = append(opts, fx.Invoke(run)) - return fx.New(opts...) } - -func run(_ context.Context, runner runner.Service, lc fx.Lifecycle) { - lc.Append(fx.Hook{ - OnStart: func(ctx context.Context) error { - if err := runner.Run(ctx); err != nil { - zap.L().Error("run failed", zap.Error(err)) - return err - } - - os.Exit(0) - return nil - }, - }) -} diff --git a/entry/entry.go b/entry/entry.go index 886c70c..dadd131 100644 --- a/entry/entry.go +++ b/entry/entry.go @@ -3,13 +3,13 @@ package entry import ( "go.uber.org/fx" + "github.com/afadian/fadian-go/cli" "github.com/afadian/fadian-go/internal/log" - "github.com/afadian/fadian-go/service" ) func AppEntry() []fx.Option { return []fx.Option{ log.Module(), - service.Module(), + cli.Module(), } } diff --git a/go.mod b/go.mod index 35e3017..f987798 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,20 @@ module github.com/afadian/fadian-go go 1.19 require ( - github.com/samber/lo v1.37.0 // indirect - github.com/vinta/pangu v3.0.0+incompatible // indirect + github.com/samber/lo v1.37.0 + github.com/urfave/cli/v2 v2.25.7 + github.com/vinta/pangu v3.0.0+incompatible + go.uber.org/fx v1.19.1 + go.uber.org/zap v1.24.0 +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/dig v1.16.1 // indirect - go.uber.org/fx v1.19.1 // indirect go.uber.org/multierr v1.9.0 // indirect - go.uber.org/zap v1.24.0 // indirect golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e // indirect golang.org/x/sys v0.4.0 // indirect ) diff --git a/go.sum b/go.sum index b036ab7..bdb609a 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,27 @@ +github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/vinta/pangu v3.0.0+incompatible h1:kqW9Q5BrmWJkLJXLdxwbyPDjlizHUTpOCmHFCKfg1ZA= github.com/vinta/pangu v3.0.0+incompatible/go.mod h1:8n5gJh5l7U0Rbz6mjRK/09AiL0Bm+ugibEB+JhvxNNk= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/dig v1.16.1 h1:+alNIBsl0qfY0j6epRubp/9obgtrObRAc5aD+6jbWY8= go.uber.org/dig v1.16.1/go.mod h1:557JTAUZT5bUK0SvCwikmLPPtdQhfvLYtO5tJgQSbnk= go.uber.org/fx v1.19.1 h1:JwYIYAQzXBuBBwSZ1/tn/95pnQO/Sp3yE8lWj9eSAzI= go.uber.org/fx v1.19.1/go.mod h1:bGK+AEy7XUwTBkqCsK/vDyFF0JJOA6X5KWpNC0e6qTA= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= @@ -16,3 +30,4 @@ golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e h1:nEzRHNOazEST44vMvEwxGxnYG golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/log/0module.go b/internal/log/0module.go index 562cbfb..5baaed2 100644 --- a/internal/log/0module.go +++ b/internal/log/0module.go @@ -5,7 +5,7 @@ import "go.uber.org/fx" func Module() fx.Option { return fx.Module( "logger", - fx.Provide(NewLogger), + fx.Provide(fx.Annotate(NewLogger, fx.ParamTags(`name:"debug"`))), fx.Invoke(ConfigureLogger), ) } diff --git a/internal/log/log.go b/internal/log/log.go index 2ae5e8e..2a7e71e 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -1,24 +1,24 @@ package log import ( - "github.com/afadian/fadian-go/data" + "context" + "github.com/samber/lo" + "go.uber.org/fx" "go.uber.org/zap" ) -func NewLogger(params *data.BootstrapParams) *zap.Logger { - var logger *zap.Logger - var err error - if params.Debug { - logger, err = zap.NewDevelopment() - } else { - logger, err = zap.NewProduction() - } - +func NewLogger(debug bool, lc fx.Lifecycle) (*zap.Logger, error) { + logger, err := lo.If(debug, zap.NewDevelopment).Else(zap.NewProduction)() if err != nil { zap.L().Panic("initial logger failed", zap.Error(err)) + return nil, err } - defer logger.Sync() + lc.Append(fx.Hook{ + OnStop: func(context.Context) error { + return logger.Sync() + }, + }) - return logger + return logger, nil } diff --git a/main.go b/main.go index dfcecd1..f8a7c9b 100644 --- a/main.go +++ b/main.go @@ -3,29 +3,37 @@ package main import ( "context" "flag" - "github.com/afadian/fadian-go/data" - "github.com/afadian/fadian-go/entry" "go.uber.org/fx" + + "github.com/afadian/fadian-go/data" + "github.com/afadian/fadian-go/entry" ) var ( - app *fx.App ctx = context.Background() + app *fx.App + + version = "0.0.1" + commit = "0000000" + debug = false ) func init() { - var params data.BootstrapParams - flag.StringVar(¶ms.Name, "name", "", "发癫对象") - flag.BoolVar(¶ms.IsInteractive, "i", false, "是否进入交互模式") - flag.BoolVar(¶ms.IsFabing, "f", false, "是否进入发病模式") - flag.IntVar(¶ms.Num, "num", 1, "发病/发癫次数") - flag.BoolVar(¶ms.Debug, "d", false, "是否开启调试模式") + flag.BoolVar(&debug, "d", false, "是否开启调试模式") flag.Parse() - app = entry.Initialize(ctx, ¶ms) + app = entry.Initialize(ctx, &data.BootstrapParams{ + Debug: debug, + Version: version, + Commit: commit, + }) } func main() { - app.Run() + if err := app.Start(ctx); err != nil { + panic(err) + } + + app.Wait() } diff --git a/service/0module.go b/service/0module.go deleted file mode 100644 index 1291837..0000000 --- a/service/0module.go +++ /dev/null @@ -1,21 +0,0 @@ -package service - -import ( - "go.uber.org/fx" - - "github.com/afadian/fadian-go/service/fabing" - "github.com/afadian/fadian-go/service/fadian" - "github.com/afadian/fadian-go/service/runner" -) - -func Module() fx.Option { - return fx.Module("service", - fx.Provide(fadian.Initialize), - fx.Provide(fadian.NewService), - - fx.Provide(fabing.Initialize), - fx.Provide(fabing.NewService), - - fx.Provide(runner.NewService), - ) -} diff --git a/service/fabing/init.go b/service/fabing/init.go deleted file mode 100644 index 650b0da..0000000 --- a/service/fabing/init.go +++ /dev/null @@ -1,11 +0,0 @@ -package fabing - -import ( - "github.com/afadian/fadian-go/data/sections" -) - -type BaseText string - -func Initialize() BaseText { - return BaseText(sections.FabingText) -} diff --git a/service/fabing/service.go b/service/fabing/service.go deleted file mode 100644 index 10f8228..0000000 --- a/service/fabing/service.go +++ /dev/null @@ -1,39 +0,0 @@ -package fabing - -import ( - "strings" - - "github.com/samber/lo" - "github.com/vinta/pangu" - "go.uber.org/fx" - - "github.com/afadian/fadian-go/internal/util" -) - -type Service interface { - Fabing(name string, repeat int) string -} - -type ServiceImpl struct { - fx.In - - BaseText BaseText -} - -var _ Service = (*ServiceImpl)(nil) - -func NewService(svc ServiceImpl) Service { - return &svc -} - -func (s *ServiceImpl) Fabing(name string, num int) string { - str := util.ReplaceString(string(s.BaseText), map[string]string{ - "$name": name, - }) - - str = pangu.SpacingText(str) - - return strings.Join(lo.RepeatBy(num, func(_ int) string { - return str - }), "\n") -} diff --git a/service/fadian/init.go b/service/fadian/init.go deleted file mode 100644 index fee2fb9..0000000 --- a/service/fadian/init.go +++ /dev/null @@ -1,11 +0,0 @@ -package fadian - -import ( - "github.com/afadian/fadian-go/data/sections" -) - -type BaseText string - -func Initialize() BaseText { - return BaseText(sections.FadianText) -} diff --git a/service/fadian/service.go b/service/fadian/service.go deleted file mode 100644 index e5aaf74..0000000 --- a/service/fadian/service.go +++ /dev/null @@ -1,39 +0,0 @@ -package fadian - -import ( - "strings" - - "github.com/samber/lo" - "github.com/vinta/pangu" - "go.uber.org/fx" - - "github.com/afadian/fadian-go/internal/util" -) - -type Service interface { - Fadian(name string, repeat int) string -} - -type ServiceImpl struct { - fx.In - - BaseText BaseText -} - -var _ Service = (*ServiceImpl)(nil) - -func NewService(svc ServiceImpl) Service { - return &svc -} - -func (s *ServiceImpl) Fadian(name string, num int) string { - str := util.ReplaceString(string(s.BaseText), map[string]string{ - "$name": name, - }) - - str = pangu.SpacingText(str) - - return strings.Join(lo.RepeatBy(num, func(_ int) string { - return str - }), "\n") -} diff --git a/service/runner/runner.go b/service/runner/runner.go deleted file mode 100644 index 4ff52d1..0000000 --- a/service/runner/runner.go +++ /dev/null @@ -1,45 +0,0 @@ -package runner - -import ( - "context" - "fmt" - - "go.uber.org/fx" - - "github.com/afadian/fadian-go/data" - "github.com/afadian/fadian-go/service/fabing" - "github.com/afadian/fadian-go/service/fadian" -) - -type Service interface { - Run(ctx context.Context) error -} - -type ServiceImpl struct { - fx.In - - BootstrapParams *data.BootstrapParams - FabingService fabing.Service - FadianService fadian.Service -} - -func NewService(svc ServiceImpl) Service { - return &svc -} - -func (svc *ServiceImpl) Run(_ context.Context) error { - if svc.BootstrapParams.IsInteractive { - fmt.Print("请输入姓名:") - if _, err := fmt.Scanln(&svc.BootstrapParams.Name); err != nil { - return err - } - } - - if svc.BootstrapParams.IsFabing { - fmt.Println(svc.FabingService.Fabing(svc.BootstrapParams.Name, svc.BootstrapParams.Num)) - } else { - fmt.Println(svc.FadianService.Fadian(svc.BootstrapParams.Name, svc.BootstrapParams.Num)) - } - - return nil -} From c8eb4fa1ef4a5f8b2967c2ac11218b5ec6568e73 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 21:15:34 +0800 Subject: [PATCH 2/7] fix: conflict on flags package and cli framework --- cli/0module.go | 1 + cli/app.go | 20 +++++++++++++++----- cli/commands/fabing.go | 5 +++-- cli/commands/fadian.go | 5 +++-- data/bootstrap.go | 9 ++++++--- entry/bootstrap.go | 15 ++++----------- internal/log/0module.go | 2 +- internal/log/fx.go | 6 +++++- internal/log/log.go | 10 ++++++++-- main.go | 7 ------- 10 files changed, 46 insertions(+), 34 deletions(-) diff --git a/cli/0module.go b/cli/0module.go index fb63eb4..43ef016 100644 --- a/cli/0module.go +++ b/cli/0module.go @@ -8,6 +8,7 @@ import ( func Module() fx.Option { return fx.Options( commands.Module(), + fx.Provide(NewApp), fx.Invoke(InvokeApp), ) } diff --git a/cli/app.go b/cli/app.go index 0cefc16..a5691ab 100644 --- a/cli/app.go +++ b/cli/app.go @@ -20,7 +20,7 @@ type Params struct { HandleNotFound cli.CommandNotFoundFunc } -func InvokeApp(lc fx.Lifecycle, params Params) { +func NewApp(params Params) *cli.App { app := &cli.App{ Name: "fadian-go", Usage: "发癫", @@ -37,7 +37,7 @@ func InvokeApp(lc fx.Lifecycle, params Params) { Flags: []cli.Flag{ &cli.BoolFlag{ Name: "debug", - Aliases: []string{"d"}, + Hidden: true, Usage: "是否开启调试模式", EnvVars: []string{"DEBUG"}, }, @@ -49,11 +49,21 @@ func InvokeApp(lc fx.Lifecycle, params Params) { }, } + app.Setup() + + zap.L().Debug("app initialized") + + return app +} + +func InvokeApp(app *cli.App, lc fx.Lifecycle) { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { - return app.RunContext(ctx, os.Args) + if err := app.RunContext(ctx, os.Args); err != nil { + zap.L().Warn("app run failed", zap.Error(err)) + } + + return nil }, }) - - zap.L().Debug("app initialized") } diff --git a/cli/commands/fabing.go b/cli/commands/fabing.go index 7e5252e..973cd33 100644 --- a/cli/commands/fabing.go +++ b/cli/commands/fabing.go @@ -26,12 +26,13 @@ func HandleFabing() (*cli.Command, error) { } return &cli.Command{ - Name: "fabing", + Name: "fabing", + Usage: "发病", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, - Usage: "name to be fabing", + Usage: "对谁发病", Required: true, }, }, diff --git a/cli/commands/fadian.go b/cli/commands/fadian.go index 3624be2..e7a6d85 100644 --- a/cli/commands/fadian.go +++ b/cli/commands/fadian.go @@ -24,12 +24,13 @@ func HandleFadian() (*cli.Command, error) { } return &cli.Command{ - Name: "fadian", + Name: "fadian", + Usage: "发癫", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, - Usage: "name to be fadian", + Usage: "对谁发癫", Required: true, }, }, diff --git a/data/bootstrap.go b/data/bootstrap.go index 10717fe..76a0257 100644 --- a/data/bootstrap.go +++ b/data/bootstrap.go @@ -1,7 +1,10 @@ package data type BootstrapParams struct { - Version string - Commit string - Debug bool + Version string `name:"version"` + Commit string `name:"commit"` +} + +type SystemConfig struct { + Debug bool } diff --git a/entry/bootstrap.go b/entry/bootstrap.go index 12387a3..6b739b4 100644 --- a/entry/bootstrap.go +++ b/entry/bootstrap.go @@ -2,12 +2,11 @@ package entry import ( "context" - - "go.uber.org/fx" - "go.uber.org/zap" + "os" "github.com/afadian/fadian-go/data" "github.com/afadian/fadian-go/internal/log" + "go.uber.org/fx" ) func Initialize(ctx context.Context, params *data.BootstrapParams) *fx.App { @@ -16,18 +15,12 @@ func Initialize(ctx context.Context, params *data.BootstrapParams) *fx.App { fx.Annotate(ctx, fx.As(new(context.Context))), fx.Annotate(params.Version, fx.ResultTags(`name:"version"`)), fx.Annotate(params.Commit, fx.ResultTags(`name:"commit"`)), - fx.Annotate(params.Debug, fx.ResultTags(`name:"debug"`)), + fx.Annotate(os.Getenv("DEBUG") == "true", fx.ResultTags(`name:"debug"`)), ), } opts = append(opts, AppEntry()...) - - if !params.Debug { - opts = append(opts, fx.NopLogger) - } else { - zap.L().Debug("using debug mode") - opts = append(opts, fx.WithLogger(log.FX)) - } + opts = append(opts, fx.WithLogger(log.FX)) return fx.New(opts...) } diff --git a/internal/log/0module.go b/internal/log/0module.go index 5baaed2..562cbfb 100644 --- a/internal/log/0module.go +++ b/internal/log/0module.go @@ -5,7 +5,7 @@ import "go.uber.org/fx" func Module() fx.Option { return fx.Module( "logger", - fx.Provide(fx.Annotate(NewLogger, fx.ParamTags(`name:"debug"`))), + fx.Provide(NewLogger), fx.Invoke(ConfigureLogger), ) } diff --git a/internal/log/fx.go b/internal/log/fx.go index 4041899..14152b8 100644 --- a/internal/log/fx.go +++ b/internal/log/fx.go @@ -5,7 +5,11 @@ import ( "go.uber.org/zap" ) -func FX(logger *zap.Logger) fxevent.Logger { +func FX(p DebugParam, logger *zap.Logger) fxevent.Logger { + if !p.Debug { + return &fxevent.NopLogger + } + return &fxevent.ZapLogger{ Logger: logger, } diff --git a/internal/log/log.go b/internal/log/log.go index 2a7e71e..f8cc3d7 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -2,13 +2,19 @@ package log import ( "context" + "github.com/samber/lo" "go.uber.org/fx" "go.uber.org/zap" ) -func NewLogger(debug bool, lc fx.Lifecycle) (*zap.Logger, error) { - logger, err := lo.If(debug, zap.NewDevelopment).Else(zap.NewProduction)() +type DebugParam struct { + fx.In + Debug bool `name:"debug"` +} + +func NewLogger(p DebugParam, lc fx.Lifecycle) (*zap.Logger, error) { + logger, err := lo.If(p.Debug, zap.NewDevelopment).Else(zap.NewProduction)() if err != nil { zap.L().Panic("initial logger failed", zap.Error(err)) return nil, err diff --git a/main.go b/main.go index f8a7c9b..d0607af 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,6 @@ package main import ( "context" - "flag" - "go.uber.org/fx" "github.com/afadian/fadian-go/data" @@ -16,15 +14,10 @@ var ( version = "0.0.1" commit = "0000000" - debug = false ) func init() { - flag.BoolVar(&debug, "d", false, "是否开启调试模式") - flag.Parse() - app = entry.Initialize(ctx, &data.BootstrapParams{ - Debug: debug, Version: version, Commit: commit, }) From c77c62cb0605c5a579f5e43fad25bb6664e3f3a3 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 21:30:50 +0800 Subject: [PATCH 3/7] doc: updated README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1c323e9..f761798 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,48 @@ ## Usage +### Command Line + +```bash +$ ./fadian-go --help + +USAGE: + fadian-go [global options] command [command options] [arguments...] + +COMMANDS: + fadian 发癫 + fabing 发病 + help, h Shows a list of commands or help for one command + +GLOBAL OPTIONS: + --num value 重复次数 (default: 1) + --help, -h show help + --version, -v print the version + +OPTIONS: + --name value, -n value 对谁发病/发癫 + --interactive, -i 是否交互式发病 (default: false) + --help, -h show help ``` -Usage of fadian-go: - -d 是否开启调试模式 - -f 是否进入发病模式 - -i 是否进入交互模式 - -name string 发癫对象 - -num int 发病/发癫次数 (default 1) + +If you want to use interactive mode, you can use `-i` or `--interactive` option. + +### Debug + +You should set `DEBUG` environment variable to `true` to enable debug mode. + +```bash +DEBUG=true ./fadian-go ``` -## Build with source code +## Build -1. Clone this repository: `git clone https://github.com/afadian/fadian-go.git` +1. Clone this repository: `git clone git@github.com:afadian/fadian.git` 2. Run `cd fadian-go` to enter the project directory. 3. Run `go mod download` to download dependencies. 4. Run `go build -o fadian-go` to build the project. 5. Run `./fadian-go` to run the project. + +## License + +This project is licensed under the GNU Affero General Public License v3.0. See [LICENSE](LICENSE) for more details. From 007ddc68a788696e3db2c67ff6462ff5293039a8 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 21:32:16 +0800 Subject: [PATCH 4/7] feat: implemented interactive mode --- cli/app.go | 4 ++-- cli/commands/fabing.go | 41 ++++++++++++++++++++++++++++++--------- cli/commands/fadian.go | 25 ++++++++++++++++++++---- data/sections/fabing.txt | 42 ++++++++++++++++++++-------------------- data/sections/fadian.txt | 16 +++++++-------- internal/log/log.go | 5 ++++- 6 files changed, 88 insertions(+), 45 deletions(-) diff --git a/cli/app.go b/cli/app.go index a5691ab..9eb0225 100644 --- a/cli/app.go +++ b/cli/app.go @@ -28,8 +28,8 @@ func NewApp(params Params) *cli.App { Copyright: fmt.Sprintf("2022-%d © 爱发癫 All Rights Reserved", time.Now().Year()), Authors: []*cli.Author{ {Name: "AH Dark", Email: "ahdark@outlook.com"}, - {Name: "Kevin Williams", Email: ""}, // TODO: add email - {Name: "Purofle", Email: ""}, // TODO: add email + {Name: "Kevin Williams", Email: "admin@utermux.dev"}, + {Name: "Purofle", Email: "purofle@gmail.com"}, }, EnableBashCompletion: true, CommandNotFound: params.HandleNotFound, diff --git a/cli/commands/fabing.go b/cli/commands/fabing.go index 973cd33..3f509ad 100644 --- a/cli/commands/fabing.go +++ b/cli/commands/fabing.go @@ -2,14 +2,17 @@ package commands import ( "bytes" + "errors" "fmt" - "github.com/afadian/fadian-go/data/sections" + "strings" + "text/template" + "github.com/samber/lo" "github.com/urfave/cli/v2" "github.com/vinta/pangu" "go.uber.org/zap" - "strings" - "text/template" + + "github.com/afadian/fadian-go/data/sections" ) func HandleFabing() (*cli.Command, error) { @@ -30,16 +33,36 @@ func HandleFabing() (*cli.Command, error) { Usage: "发病", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "name", - Aliases: []string{"n"}, - Usage: "对谁发病", - Required: true, + Name: "name", + Aliases: []string{"n"}, + Usage: "对谁发病", + Value: "", + }, + &cli.BoolFlag{ + Name: "interactive", + Aliases: []string{"i"}, + Usage: "是否交互式发病", + Value: false, }, }, Action: func(c *cli.Context) error { + name := c.String("name") + if c.Bool("interactive") { + fmt.Print("对谁发病?") + if _, err := fmt.Scan(&name); err != nil { + zap.L().Error("failed to scan name", zap.Error(err)) + return err + } + } + + if name == "" { + zap.L().Error("name is empty") + return errors.New("name is empty") + } + buf := bytes.NewBuffer([]byte{}) if err := tpl.Execute(buf, FabingParams{ - Name: c.String("name"), + Name: name, }); err != nil { zap.L().Error("failed to execute fabing template", zap.Error(err)) return err @@ -48,7 +71,7 @@ func HandleFabing() (*cli.Command, error) { str := pangu.SpacingText(buf.String()) zap.L().Debug("fabing text generated", zap.String("text", str)) - fmt.Sprintln(strings.Join(lo.RepeatBy(c.Int("num"), func(_ int) string { + fmt.Println(strings.Join(lo.RepeatBy(c.Int("num"), func(_ int) string { return str }), "\n")) diff --git a/cli/commands/fadian.go b/cli/commands/fadian.go index e7a6d85..cd04853 100644 --- a/cli/commands/fadian.go +++ b/cli/commands/fadian.go @@ -2,14 +2,17 @@ package commands import ( "bytes" + "errors" "fmt" - "github.com/afadian/fadian-go/data/sections" + "strings" + "text/template" + "github.com/samber/lo" "github.com/urfave/cli/v2" "github.com/vinta/pangu" "go.uber.org/zap" - "strings" - "text/template" + + "github.com/afadian/fadian-go/data/sections" ) func HandleFadian() (*cli.Command, error) { @@ -35,9 +38,23 @@ func HandleFadian() (*cli.Command, error) { }, }, Action: func(c *cli.Context) error { + name := c.String("name") + if c.Bool("interactive") { + fmt.Print("对谁发癫?") + if _, err := fmt.Scan(&name); err != nil { + zap.L().Error("failed to scan name", zap.Error(err)) + return err + } + } + + if name == "" { + zap.L().Error("name is empty") + return errors.New("name is empty") + } + buf := bytes.NewBuffer([]byte{}) if err := tpl.Execute(buf, FadianParams{ - Name: c.String("name"), + Name: name, }); err != nil { zap.L().Error("failed to execute fadian template", zap.Error(err)) return err diff --git a/data/sections/fabing.txt b/data/sections/fabing.txt index 4f61804..fd78c3f 100644 --- a/data/sections/fabing.txt +++ b/data/sections/fabing.txt @@ -1,31 +1,31 @@ - {{ .Name }} ……🤤 +{{ .Name }}……🤤 嘿嘿………🤤, -……好可爱……嘿嘿…… {{ .Name }} 🤤, -…… {{ .Name }} ……我的🤤, +……好可爱……嘿嘿……{{ .Name }}🤤, +……{{ .Name }}……我的🤤, ……嘿嘿……🤤, -………亲爱的……赶紧让我抱一抱……啊啊啊 {{ .Name }} 软软的脸蛋🤤还有软软的小手手……🤤, -… {{ .Name }} ……不会有人来伤害你的…🤤, +………亲爱的……赶紧让我抱一抱……啊啊啊{{ .Name }}软软的脸蛋🤤还有软软的小手手……🤤, +…{{ .Name }}……不会有人来伤害你的…🤤, 你就让我保护你吧嘿嘿嘿嘿嘿嘿嘿嘿🤤, ……太可爱了……🤤, -……美丽可爱的 {{ .Name }} ……像珍珠一样……🤤, -嘿嘿…… {{ .Name }} ……🤤, +……美丽可爱的{{ .Name }}……像珍珠一样……🤤, +嘿嘿……{{ .Name }}……🤤, 嘿嘿……🤤, -……好想一口吞掉……🤤……但是舍不得啊……我的 {{ .Name }} 🤤, +……好想一口吞掉……🤤……但是舍不得啊……我的{{ .Name }}🤤, ……嘿嘿……🤤, -我的宝贝……我最可爱的 {{ .Name }} ……🤤, -没有 {{ .Name }} ……我就要死掉了呢……🤤, +我的宝贝……我最可爱的{{ .Name }}……🤤, +没有{{ .Name }}……我就要死掉了呢……🤤, 我的……🤤, -嘿嘿……可爱的 {{ .Name }} ……嘿嘿🤤, -……可爱的 {{ .Name }} ……嘿嘿🤤🤤, -……可爱的 {{ .Name }} ……🤤, +嘿嘿……可爱的{{ .Name }}……嘿嘿🤤, +……可爱的{{ .Name }}……嘿嘿🤤🤤, +……可爱的{{ .Name }}……🤤, ……嘿嘿🤤, -……可爱的 {{ .Name }} …(吸)身上的味道……好好闻~🤤, +……可爱的{{ .Name }}…(吸)身上的味道……好好闻~🤤, …嘿嘿🤤, -……摸摸~……可爱的 {{ .Name }} ……再贴近我一点嘛……(蹭蹭)嘿嘿🤤, -……可爱的 {{ .Name }} ……嘿嘿🤤, -……~亲一口~……可爱的 {{ .Name }} ……嘿嘿🤤, -……抱抱你~可爱的 {{ .Name }} ~(舔)喜欢~真的好喜欢~……(蹭蹭)🤤, -脑袋要融化了呢~已经……除了 {{ .Name }} 以外~什么都不会想了呢~🤤, +……摸摸~……可爱的{{ .Name }}……再贴近我一点嘛……(蹭蹭)嘿嘿🤤, +……可爱的{{ .Name }}……嘿嘿🤤, +……~亲一口~……可爱的{{ .Name }}……嘿嘿🤤, +……抱抱你~可爱的{{ .Name }}~(舔)喜欢~真的好喜欢~……(蹭蹭)🤤, +脑袋要融化了呢~已经……除了{{ .Name }}以外~什么都不会想了呢~🤤, 嘿嘿🤤, -……可爱的 {{ .Name }} ……嘿嘿🤤, -……可爱的 {{ .Name }} ……我的~……嘿嘿🤤 +……可爱的{{ .Name }}……嘿嘿🤤, +……可爱的{{ .Name }}……我的~……嘿嘿🤤 diff --git a/data/sections/fadian.txt b/data/sections/fadian.txt index 521f1d1..b09c3cd 100644 --- a/data/sections/fadian.txt +++ b/data/sections/fadian.txt @@ -1,18 +1,18 @@ -我好想做 {{ .Name }} 小姐的狗啊。 -可是 {{ .Name }} 小姐说她喜欢的是猫,我哭了。 +我好想做{{ .Name }}小姐的狗啊。 +可是{{ .Name }}小姐说她喜欢的是猫,我哭了。 我知道既不是狗也不是猫的我为什么要哭的。因为我其实是一只老鼠。 -我从没奢望 {{ .Name }} 小姐能喜欢自己。我明白的,所有人都喜欢理解余裕上手天才打钱的萌萌的狗狗或者猫猫,没有人会喜欢阴湿带病的老鼠。 -但我还是问了 {{ .Name }} 小姐:“我能不能做你的狗?” +我从没奢望{{ .Name }}小姐能喜欢自己。我明白的,所有人都喜欢理解余裕上手天才打钱的萌萌的狗狗或者猫猫,没有人会喜欢阴湿带病的老鼠。 +但我还是问了{{ .Name }}小姐:“我能不能做你的狗?” 我知道我是注定做不了狗的。但如果她喜欢狗,我就可以一直在身边看着她了,哪怕她怀里抱着的永远都是狗。 可是她说喜欢的是猫。 她现在还在看着我,还在逗我开心,是因为猫还没有出现,只有我这老鼠每天蹑手蹑脚地从洞里爬出来,远远地和她对视。 等她喜欢的猫来了的时候,我就该重新滚回我的洞了吧。 但我还是好喜欢她,她能在我还在她身边的时候多看我几眼吗? -{{ .Name }} 小姐说接下来的每个圣诞夜都要和大家一起过。我不知道大家指哪些人。好希望这个集合能够对我做一次胞吞。 -猫猫还在害怕 {{ .Name }} 小姐。 +{{ .Name }}小姐说接下来的每个圣诞夜都要和大家一起过。我不知道大家指哪些人。好希望这个集合能够对我做一次胞吞。 +猫猫还在害怕{{ .Name }}小姐。 我会去把她爱的猫猫引来的。 我知道稍有不慎,我就会葬身猫口。 -那时候 {{ .Name }} 小姐大概会把我的身体好好地装起来扔到门外吧。 +那时候{{ .Name }}小姐大概会把我的身体好好地装起来扔到门外吧。 那我就成了一包鼠条,嘻嘻。 我希望她能把我扔得近一点,因为我还是好喜欢她。会一直喜欢下去的。 -我的灵魂透过窗户向里面看去,挂着的铃铛在轻轻鸣响, {{ .Name }} 小姐慵懒地靠在沙发上,表演得非常温顺的橘猫坐在她的肩膀。壁炉的火光照在她的脸庞,我冻僵的心脏在风里微微发烫。 +我的灵魂透过窗户向里面看去,挂着的铃铛在轻轻鸣响,{{ .Name }}小姐慵懒地靠在沙发上,表演得非常温顺的橘猫坐在她的肩膀。壁炉的火光照在她的脸庞,我冻僵的心脏在风里微微发烫。 diff --git a/internal/log/log.go b/internal/log/log.go index f8cc3d7..4523325 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -14,7 +14,10 @@ type DebugParam struct { } func NewLogger(p DebugParam, lc fx.Lifecycle) (*zap.Logger, error) { - logger, err := lo.If(p.Debug, zap.NewDevelopment).Else(zap.NewProduction)() + logger, err := lo.If(p.Debug, zap.NewDevelopment).Else(zap.NewProduction)( + zap.AddStacktrace(zap.PanicLevel), + zap.WithCaller(p.Debug), + ) if err != nil { zap.L().Panic("initial logger failed", zap.Error(err)) return nil, err From 838cf0c15fa2a3841592e4454f923fcdc0ebb5c4 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 21:37:35 +0800 Subject: [PATCH 5/7] deps: updated to go 1.21 --- .github/workflows/build.yml | 2 +- go.mod | 18 +++++++++--------- go.sum | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76ae61c..a61082a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.21 - name: Build run: | diff --git a/go.mod b/go.mod index f987798..34c8b2f 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,22 @@ module github.com/afadian/fadian-go -go 1.19 +go 1.21 require ( - github.com/samber/lo v1.37.0 + github.com/samber/lo v1.38.1 github.com/urfave/cli/v2 v2.25.7 github.com/vinta/pangu v3.0.0+incompatible - go.uber.org/fx v1.19.1 - go.uber.org/zap v1.24.0 + go.uber.org/fx v1.20.0 + go.uber.org/zap v1.26.0 ) require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - go.uber.org/atomic v1.10.0 // indirect - go.uber.org/dig v1.16.1 // indirect - go.uber.org/multierr v1.9.0 // indirect - golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e // indirect - golang.org/x/sys v0.4.0 // indirect + go.uber.org/atomic v1.11.0 // indirect + go.uber.org/dig v1.17.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index bdb609a..a341b2e 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= +github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= +github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= @@ -17,17 +19,31 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/dig v1.16.1 h1:+alNIBsl0qfY0j6epRubp/9obgtrObRAc5aD+6jbWY8= go.uber.org/dig v1.16.1/go.mod h1:557JTAUZT5bUK0SvCwikmLPPtdQhfvLYtO5tJgQSbnk= +go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= +go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= go.uber.org/fx v1.19.1 h1:JwYIYAQzXBuBBwSZ1/tn/95pnQO/Sp3yE8lWj9eSAzI= go.uber.org/fx v1.19.1/go.mod h1:bGK+AEy7XUwTBkqCsK/vDyFF0JJOA6X5KWpNC0e6qTA= +go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= +go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e h1:nEzRHNOazEST44vMvEwxGxnYGrzXEmxJmnti5mKSWTk= golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From 620ea45d74fc1fa9c452b7d2ad90c5bf8d603ce1 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 22:01:33 +0800 Subject: [PATCH 6/7] feat: go releaser adaption --- .github/workflows/codeql.yml | 75 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 52 ++++++++++++++++++++++ .gitignore | 3 ++ .goreleaser.yml | 81 +++++++++++++++++++++++++++++++++++ go.sum | 27 ++++-------- public-key.pem | 13 ++++++ 6 files changed, 232 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 public-key.pem diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..0ccd1c9 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,75 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + analyze: + name: Analyze + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cd6b9f3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,52 @@ +name: Tag Release + +on: + push: + tags: + - '*' + +permissions: + contents: write + packages: write + +jobs: + release: + name: Release + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + + - name: Release + uses: goreleaser/goreleaser-action@v4 + if: startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ github.token }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.gitignore b/.gitignore index 8b6de37..519de3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +### GoReleaser template +/dist/ + ### VisualStudioCode template .vscode/* !.vscode/settings.json diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..8e2d13b --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,81 @@ +project_name: fadian-go + +before: + hooks: + - go mod tidy + +builds: + - id: fadian-go + main: . + binary: fadian-go + env: + - CGO_ENABLED=0 + - >- + {{- if eq .Os "darwin" }} + {{- if eq .Arch "amd64"}}CC=o64-clang{{- end }} + {{- if eq .Arch "arm64"}}CC=aarch64-apple-darwin20.2-clang{{- end }} + {{- end }} + {{- if eq .Os "windows" }} + {{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }} + {{- end }} + ldflags: + - -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} + goos: + - "linux" + - "windows" + - "darwin" + goarch: + - "amd64" + - "arm64" + +universal_binaries: + - id: fadian-go + +signs: + - artifacts: checksum + args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"] + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + files: + - src: data/* + dst: data + info: + owner: root + group: root + mtime: "{{ .CommitDate }}" + mode: 0644 + +release: + github: + owner: afadian + name: fadian-go + draft: true + replace_existing_draft: true + prerelease: auto + mode: append + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ incpatch .Version }}-snapshot" + +changelog: + sort: asc + filters: + exclude: + - '^doc:' + - '^test:' diff --git a/go.sum b/go.sum index a341b2e..f8817d9 100644 --- a/go.sum +++ b/go.sum @@ -1,49 +1,38 @@ github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= -github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/vinta/pangu v3.0.0+incompatible h1:kqW9Q5BrmWJkLJXLdxwbyPDjlizHUTpOCmHFCKfg1ZA= github.com/vinta/pangu v3.0.0+incompatible/go.mod h1:8n5gJh5l7U0Rbz6mjRK/09AiL0Bm+ugibEB+JhvxNNk= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.16.1 h1:+alNIBsl0qfY0j6epRubp/9obgtrObRAc5aD+6jbWY8= -go.uber.org/dig v1.16.1/go.mod h1:557JTAUZT5bUK0SvCwikmLPPtdQhfvLYtO5tJgQSbnk= go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI= go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU= -go.uber.org/fx v1.19.1 h1:JwYIYAQzXBuBBwSZ1/tn/95pnQO/Sp3yE8lWj9eSAzI= -go.uber.org/fx v1.19.1/go.mod h1:bGK+AEy7XUwTBkqCsK/vDyFF0JJOA6X5KWpNC0e6qTA= go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= -go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= -golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e h1:nEzRHNOazEST44vMvEwxGxnYGrzXEmxJmnti5mKSWTk= -golang.org/x/exp v0.0.0-20230126173853-a67bb567ff2e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/public-key.pem b/public-key.pem new file mode 100644 index 0000000..4dbd5f3 --- /dev/null +++ b/public-key.pem @@ -0,0 +1,13 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mDMEZR7ALhYJKwYBBAHaRw8BAQdAEedxjRlBUIKNxID/spuJ0qBx/BAKlDPgds8d +h45TBB+0J1B1cm9mbGUgKE9yZyBPd25lcikgPHB1cm9mbGVAZ21haWwuY29tPoiT +BBMWCgA7FiEEn3n5/2NcyOON/tylGwFJMFWTb3IFAmUewC4CGwMFCwkIBwICIgIG +FQoJCAsCBBYCAwECHgcCF4AACgkQGwFJMFWTb3LI4wEAkv9/tfk4Tt8NP8zPcQp1 +DjGtqoCRhCl+99rVETOvcD4BAIIh+EF0CqXjRNi/GNFABa9nQvYyl+aKGlOnu7ul +YCoOuDgEZR7ALhIKKwYBBAGXVQEFAQEHQAO5b3sdKs0vgbHN8xhGXm40w4RHQCqw +CHTd26yNKDkRAwEIB4h4BBgWCgAgFiEEn3n5/2NcyOON/tylGwFJMFWTb3IFAmUe +wC4CGwwACgkQGwFJMFWTb3I2TQEA3TDdHuEtH5+Gs+cLVG9X4djg0+am6IncLsdp +v5yAHgwBAM6DeFF8zVcTMCX7rdh6J3VC3sxzzbPeYInC6DIPQPIF +=5JZV +-----END PGP PUBLIC KEY BLOCK----- From c1ffe8d93f8c2ae8f27acd164d5c6b7766fe3ec5 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Thu, 5 Oct 2023 22:11:13 +0800 Subject: [PATCH 7/7] chore: updated goreleaser files --- .goreleaser.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 8e2d13b..f899c34 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -50,13 +50,9 @@ archives: - goos: windows format: zip files: - - src: data/* - dst: data - info: - owner: root - group: root - mtime: "{{ .CommitDate }}" - mode: 0644 + - LICENSE + - README.md + - public-key.pem release: github: