From 8d1bd191df2997ad2680079b921919f8f69b3939 Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Tue, 7 Mar 2023 19:07:31 +0800 Subject: [PATCH] ci: support husky feat: fix lint issues --- .husky.toml | 39 ++++++++++++++++++++++++++++++++++++ go.mod | 1 - go.sum | 1 - middleware/rbac.go | 2 +- providers/dictionary/dict.go | 7 ++----- 5 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 .husky.toml diff --git a/.husky.toml b/.husky.toml new file mode 100644 index 0000000..fd9baf9 --- /dev/null +++ b/.husky.toml @@ -0,0 +1,39 @@ +# version-file which will write or read current semver +version-file = "internal/version/version" + +# hook scripts +[hooks] + +# after version calc, +# with use the {{ .Version }} to upgrade other files. +post-version = [ + "sed -i -e 's/\"version\": \"[^\"]*\"/\"version\": \"{{ .Version }}\"/g' testdata/package.json", + "sed -i -e 's/version: [^\\n]*/version: {{ .Version }}/g' testdata/pubspec.yaml" +] + +# git hook pre commit +pre-commit = [ + "golangci-lint run", + "husky lint-staged", +] + +# git hook commit msg +commit-msg = [ + "husky lint-commit", +] + +# list staged files do some pre-process and git add +[lint-staged] +"*.go" = [ + "goimports -l -w", + "gofmt -l -w", +] + +# commit msg rule default support conventional commits +[lint-commit] +# could check if this exists +# email = "^(.+@gmail.com|.+@qq.com)$" +# optional custom types check regex +# types = "^(feat|fix|build|chore|ci|docs|perf|refactor|revert|style|test)$" +# optional header check regex +# header = "^(?P\w+)(\((?P[\w/.-]+)\))?(?P!)?:( +)?(?P
.+)" \ No newline at end of file diff --git a/go.mod b/go.mod index dfbe5f8..bb08453 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/rogeecn/fabfile v1.3.0 github.com/rogeecn/gen v1.0.11 - github.com/satori/go.uuid v1.2.0 github.com/smartystreets/goconvey v1.7.2 github.com/spf13/cobra v1.5.0 github.com/spf13/viper v1.15.0 diff --git a/go.sum b/go.sum index d596601..0e3d3f3 100644 --- a/go.sum +++ b/go.sum @@ -338,7 +338,6 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= diff --git a/middleware/rbac.go b/middleware/rbac.go index 6df4b9f..4ef3250 100644 --- a/middleware/rbac.go +++ b/middleware/rbac.go @@ -36,7 +36,7 @@ func CheckPermission(config *config.Config, rbac rbac.IRbac) gin.HandlerFunc { // 获取用户的角色 role := strconv.Itoa(int(claims.Role)) - if rbac.Can(role, method, path) == false { + if !rbac.Can(role, method, path) { gen.NewBusError(http.StatusForbidden, http.StatusForbidden, "未登录或非法访问").JSON(c, false) c.Abort() return diff --git a/providers/dictionary/dict.go b/providers/dictionary/dict.go index bf40364..29214d2 100644 --- a/providers/dictionary/dict.go +++ b/providers/dictionary/dict.go @@ -6,7 +6,6 @@ import ( "context" "errors" "log" - "time" ) type Dict struct { @@ -37,9 +36,8 @@ func NewDictionary(query *query.Query) (*Dict, error) { } func (dict *Dict) Load() error { - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) dictTable := dict.query.SysDictionary - items, err := dictTable.WithContext(ctx).Where(dictTable.Status.Is(true)).Find() + items, err := dictTable.WithContext(context.Background()).Where(dictTable.Status.Is(true)).Find() if err != nil { return err } @@ -50,9 +48,8 @@ func (dict *Dict) Load() error { dict.mapAlias[item.Alias_] = item.ID } - ctx, _ = context.WithTimeout(context.Background(), time.Second*5) dictDetailTable := dict.query.SysDictionaryDetail - dictItems, err := dictDetailTable.WithContext(ctx). + dictItems, err := dictDetailTable.WithContext(context.Background()). Where(dictDetailTable.Status.Is(true)). Where(dictDetailTable.ID.In(ids...)). Order(dictDetailTable.Weight.Desc()).