diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..74296b14 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: Run golangci-lint + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + name: Run golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Print All environment variables + run: env | sort + + - name: Set up Go + uses: actions/setup-go@v5 + + - name: Install golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: latest + + - name: Run golangci-lint + run: golangci-lint run ./... diff --git a/.github/workflows/main.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/test.yml diff --git a/.gitignore b/.gitignore index c5688307..9864f6da 100644 --- a/.gitignore +++ b/.gitignore @@ -32,10 +32,8 @@ go.work.sum /conf/remote/ +gs/examples/bookman/.cover/ gs/examples/bookman/conf/ gs/examples/bookman/log/*.log -gs/examples/bookman/.cover/covcounters.* -gs/examples/bookman/.cover/covmeta.* -gs/examples/bookman/.cover/cover.txt coverage.txt \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index bd1318d4..a9ce3811 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,39 +1,3 @@ -# 贡献者行为准则 - -首先,感谢你关注并支持 Go-Spring 项目! - -为营造一个开放、友善、包容和专业的社区氛围,我们制定了本行为准则。无论你是报告问题、提交代码、参与讨论,还是以其他形式参与项目,都请遵循以下准则。 - -## 我们的承诺 - -我们承诺为每一位参与者提供一个免受骚扰、歧视和攻击性行为干扰的环境。我们欢迎来自不同背景、经验和身份的贡献者,共同建设一个多元、包容的社区。 - -## 倡导的行为 - -- 保持尊重、礼貌的沟通方式; -- 乐于接受建设性的意见与反馈; -- 尊重不同的观点与技术选择; -- 在协作中体现耐心与包容; -- 积极参与,共建积极向上的社区氛围。 - -## 不被接受的行为 - -- 使用歧视性、侮辱性或攻击性的言语与行为; -- 进行人身攻击、骚扰或威胁; -- 发布淫秽内容或不当链接; -- 蓄意干扰他人正常贡献; -- 冒充他人或侵犯他人隐私。 - -## 执行与维护 - -项目维护者有权也有责任删除、修改或拒绝任何违反行为准则的评论、提交、代码、Wiki 编辑、Issue 或其他形式的贡献内容,必要时可采取进一步措施。 - -## 如何报告问题 - -若你遇到违反行为准则的情况,请通过电子邮件联系项目维护者,或通过 Issue 匿名举报。我们承诺认真对待每一份举报,并确保信息保密。 - ---- - # Contributor Code of Conduct Thank you for your interest in and support of the Go-Spring project! @@ -73,3 +37,39 @@ further action as necessary. If you witness or experience a violation of this Code of Conduct, please contact the maintainers via email or submit an anonymous issue. All reports will be handled with discretion and taken seriously. + +--- + +# 贡献者行为准则 + +首先,感谢你关注并支持 Go-Spring 项目! + +为营造一个开放、友善、包容和专业的社区氛围,我们制定了本行为准则。无论你是报告问题、提交代码、参与讨论,还是以其他形式参与项目,都请遵循以下准则。 + +## 我们的承诺 + +我们承诺为每一位参与者提供一个免受骚扰、歧视和攻击性行为干扰的环境。我们欢迎来自不同背景、经验和身份的贡献者,共同建设一个多元、包容的社区。 + +## 倡导的行为 + +- 保持尊重、礼貌的沟通方式; +- 乐于接受建设性的意见与反馈; +- 尊重不同的观点与技术选择; +- 在协作中体现耐心与包容; +- 积极参与,共建积极向上的社区氛围。 + +## 不被接受的行为 + +- 使用歧视性、侮辱性或攻击性的言语与行为; +- 进行人身攻击、骚扰或威胁; +- 发布淫秽内容或不当链接; +- 蓄意干扰他人正常贡献; +- 冒充他人或侵犯他人隐私。 + +## 执行与维护 + +项目维护者有权也有责任删除、修改或拒绝任何违反行为准则的评论、提交、代码、Wiki 编辑、Issue 或其他形式的贡献内容,必要时可采取进一步措施。 + +## 如何报告问题 + +若你遇到违反行为准则的情况,请通过电子邮件联系项目维护者,或通过 Issue 匿名举报。我们承诺认真对待每一份举报,并确保信息保密。 diff --git a/conf/bind_test.go b/conf/bind_test.go index f5931c21..9cfea5ae 100644 --- a/conf/bind_test.go +++ b/conf/bind_test.go @@ -49,7 +49,7 @@ func PointConverter(val string) (image.Point, error) { } func PointSplitter(str string) ([]string, error) { - if !(strings.HasPrefix(str, "(") && strings.HasSuffix(str, ")")) { + if !strings.HasPrefix(str, "(") || !strings.HasSuffix(str, ")") { return nil, errors.New("split error") } var ret []string diff --git a/gs/examples/bookman/.cover/cover.html b/gs/examples/bookman/.cover/cover.html deleted file mode 100644 index 3ad5e775..00000000 --- a/gs/examples/bookman/.cover/cover.html +++ /dev/null @@ -1,7612 +0,0 @@ - - - - - - bookman: Go Coverage Report - - - -
- -
- not tracked - - no coverage - low coverage - * - * - * - * - * - * - * - * - high coverage - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - diff --git a/gs/examples/bookman/main.go b/gs/examples/bookman/main.go index 4e039397..e01c2ccd 100644 --- a/gs/examples/bookman/main.go +++ b/gs/examples/bookman/main.go @@ -54,7 +54,10 @@ func runTest(ctx context.Context) error { if err != nil { panic(err) } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + _ = err + }() fmt.Print(string(b)) time.Sleep(time.Millisecond * 400) }) diff --git a/gs/examples/bookman/run.sh b/gs/examples/bookman/run.sh deleted file mode 100644 index 45e07632..00000000 --- a/gs/examples/bookman/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -export GOCOVERDIR=.cover -rm -rf ./.cover/* -go run -race -cover -covermode=atomic main.go -go tool covdata textfmt -i=.cover -o ./.cover/cover.txt -go tool cover -html=./.cover/cover.txt -o ./.cover/cover.html \ No newline at end of file diff --git a/gs/examples/bookman/src/dao/book_dao/book_dao.go b/gs/examples/bookman/src/dao/book_dao/book_dao.go index 91f0225d..69007707 100644 --- a/gs/examples/bookman/src/dao/book_dao/book_dao.go +++ b/gs/examples/bookman/src/dao/book_dao/book_dao.go @@ -59,7 +59,8 @@ func (dao *BookDao) ListBooks() ([]Book, error) { // GetBook retrieves a book by its ISBN. func (dao *BookDao) GetBook(isbn string) (Book, error) { - r, _ := dao.Store[isbn] + r, ok := dao.Store[isbn] + _ = ok return r, nil } diff --git a/gs/internal/gs_arg/arg.go b/gs/internal/gs_arg/arg.go index e07d57d4..8920d73a 100644 --- a/gs/internal/gs_arg/arg.go +++ b/gs/internal/gs_arg/arg.go @@ -78,7 +78,7 @@ func Index(n int, arg gs.Arg) gs.Arg { // GetArgValue panics if called directly. IndexArg must be processed by ArgList. func (arg IndexArg) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error) { - panic(util.UnimplementedMethod) + panic(util.ErrUnimplementedMethod) } // ValueArg represents a fixed-value argument. diff --git a/gs/internal/gs_cond/cond.go b/gs/internal/gs_cond/cond.go index f275112a..cfd60f3a 100755 --- a/gs/internal/gs_cond/cond.go +++ b/gs/internal/gs_cond/cond.go @@ -269,7 +269,7 @@ func OnExpression(expression string) gs.Condition { // Matches checks if the condition is met according to the provided context. func (c *onExpression) Matches(ctx gs.CondContext) (bool, error) { - err := util.UnimplementedMethod + err := util.ErrUnimplementedMethod return false, errutil.WrapError(err, "condition matches error: %s", c) } diff --git a/gs/internal/gs_cond/cond_test.go b/gs/internal/gs_cond/cond_test.go index 67d06ebe..3bd3cecc 100644 --- a/gs/internal/gs_cond/cond_test.go +++ b/gs/internal/gs_cond/cond_test.go @@ -337,7 +337,7 @@ func TestOnExpression(t *testing.T) { ctx := NewMockCondContext(ctrl) cond := OnExpression("1+1==2") _, err := cond.Matches(ctx) - assert.True(t, errors.Is(err, util.UnimplementedMethod)) + assert.True(t, errors.Is(err, util.ErrUnimplementedMethod)) } func TestNot(t *testing.T) { diff --git a/gs/internal/gs_conf/conf.go b/gs/internal/gs_conf/conf.go index db078148..fa19cacc 100644 --- a/gs/internal/gs_conf/conf.go +++ b/gs/internal/gs_conf/conf.go @@ -107,12 +107,8 @@ func (c *AppConfig) Refresh() (conf.Properties, error) { var sources []PropertyCopier sources = append(sources, NewNamedPropertyCopier("sys", sysconf.Clone())) - for _, file := range localFiles { - sources = append(sources, file) - } - for _, file := range remoteFiles { - sources = append(sources, file) - } + sources = append(sources, localFiles...) + sources = append(sources, remoteFiles...) sources = append(sources, NewNamedPropertyCopier("remote", c.RemoteProp)) sources = append(sources, NewNamedPropertyCopier("env", c.Environment)) sources = append(sources, NewNamedPropertyCopier("cmd", c.CommandArgs)) @@ -156,9 +152,7 @@ func (c *BootConfig) Refresh() (conf.Properties, error) { var sources []PropertyCopier sources = append(sources, NewNamedPropertyCopier("sys", sysconf.Clone())) - for _, file := range localFiles { - sources = append(sources, file) - } + sources = append(sources, localFiles...) sources = append(sources, NewNamedPropertyCopier("env", c.Environment)) sources = append(sources, NewNamedPropertyCopier("cmd", c.CommandArgs)) diff --git a/gs/internal/gs_core/injecting/injecting_test.go b/gs/internal/gs_core/injecting/injecting_test.go index 3ece3059..c58ac9c8 100644 --- a/gs/internal/gs_core/injecting/injecting_test.go +++ b/gs/internal/gs_core/injecting/injecting_test.go @@ -211,6 +211,7 @@ type LazyA struct { } type LazyB struct { + // nolint dummy int `value:"${dummy:=9}"` } @@ -954,6 +955,7 @@ func TestForceClean(t *testing.T) { assert.Nil(t, r.beansByType) runtime.GC() + time.Sleep(100 * time.Millisecond) assert.That(t, release).Equal(map[string]struct{}{ "biz": {}, "sys": {}, diff --git a/gs/internal/gs_dync/dync_test.go b/gs/internal/gs_dync/dync_test.go index 296a974d..dc2b737d 100644 --- a/gs/internal/gs_dync/dync_test.go +++ b/gs/internal/gs_dync/dync_test.go @@ -147,6 +147,7 @@ func TestDync(t *testing.T) { "config.s4.value": "123", }) err = p.Refresh(prop) + assert.Nil(t, err) assert.That(t, p.ObjectsCount()).Equal(2) assert.That(t, cfg.S1.Value.Value()).Equal(99) assert.That(t, cfg.S2.Value.Value()).Equal(456) @@ -157,6 +158,7 @@ func TestDync(t *testing.T) { "config.s3.value": "xyz", }) err = p.Refresh(prop) + assert.Nil(t, err) assert.That(t, p.ObjectsCount()).Equal(2) assert.That(t, cfg.S1.Value.Value()).Equal(99) assert.That(t, cfg.S2.Value.Value()).Equal(456) diff --git a/util/error.go b/util/error.go index 18784932..7e56a850 100644 --- a/util/error.go +++ b/util/error.go @@ -20,8 +20,8 @@ import ( "errors" ) -// ForbiddenMethod throws this error when calling a method is prohibited. -var ForbiddenMethod = errors.New("forbidden method") +// ErrForbiddenMethod throws this error when calling a method is prohibited. +var ErrForbiddenMethod = errors.New("forbidden method") -// UnimplementedMethod throws this error when calling an unimplemented method. -var UnimplementedMethod = errors.New("unimplemented method") +// ErrUnimplementedMethod throws this error when calling an unimplemented method. +var ErrUnimplementedMethod = errors.New("unimplemented method")