Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: zeromicro/go-zero
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.7.6
Choose a base ref
...
head repository: zeromicro/go-zero
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.0
Choose a head ref

Commits on Jan 2, 2025

  1. Copy the full SHA
    4ac8b49 View commit details

Commits on Jan 4, 2025

  1. chore: update go version (#4540)

    Signed-off-by: kevin <wanjunfeng@gmail.com>
    kevwan authored Jan 4, 2025
    Copy the full SHA
    e1787b4 View commit details

Commits on Jan 7, 2025

  1. chore(deps): bump golang.org/x/time from 0.8.0 to 0.9.0 (#4547)

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 7, 2025
    Copy the full SHA
    5f4190b View commit details
  2. chore(deps): bump golang.org/x/sys from 0.28.0 to 0.29.0 (#4548)

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 7, 2025
    Copy the full SHA
    74ba0bc View commit details

Commits on Jan 9, 2025

  1. chore(deps): bump google.golang.org/protobuf from 1.36.1 to 1.36.2 in…

    … /tools/goctl (#4553)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 9, 2025
    Copy the full SHA
    2c9310a View commit details

Commits on Jan 10, 2025

  1. chore(deps): bump golang.org/x/net from 0.33.0 to 0.34.0 (#4554)

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 10, 2025
    Copy the full SHA
    730c3c5 View commit details
  2. chore(deps): bump google.golang.org/protobuf from 1.36.1 to 1.36.2 (#…

    …4556)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 10, 2025
    Copy the full SHA
    fa46746 View commit details

Commits on Jan 11, 2025

  1. chore(deps): bump go.mongodb.org/mongo-driver from 1.17.1 to 1.17.2 (#…

    …4561)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 11, 2025
    Copy the full SHA
    024f285 View commit details

Commits on Jan 12, 2025

  1. Copy the full SHA
    11c47d2 View commit details
  2. feat/conf_map_required (#4405)

    Co-authored-by: aiden.ma <Aiden.ma@yijinin.com>
    MarkJoyMa and aiden.ma authored Jan 12, 2025
    Copy the full SHA
    12071d1 View commit details

Commits on Jan 14, 2025

  1. Copy the full SHA
    f05234a View commit details
  2. chore: code format (#4572)

    kevwan authored Jan 14, 2025
    Copy the full SHA
    b25c45b View commit details

Commits on Jan 16, 2025

  1. chore(deps): bump google.golang.org/protobuf from 1.36.2 to 1.36.3 in…

    … /tools/goctl (#4575)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 16, 2025
    Copy the full SHA
    68da9ed View commit details
  2. chore(deps): bump google.golang.org/protobuf from 1.36.2 to 1.36.3 (#…

    …4574)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 16, 2025
    Copy the full SHA
    3d931d7 View commit details

Commits on Jan 18, 2025

  1. Copy the full SHA
    b650c8c View commit details

Commits on Jan 22, 2025

  1. fix memory leak of grpc resolver (#4490)

    Co-authored-by: nk <kui.niu@akuvox.com>
    sauryniu and nk authored Jan 22, 2025
    Copy the full SHA
    17d98f6 View commit details
  2. fix: routinegroup & etcd watch goroutine leak (#4514)

    Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
    Nanosk07 and kevwan authored Jan 22, 2025
    Copy the full SHA
    33011c7 View commit details
  3. Copy the full SHA
    bf88310 View commit details
  4. Copy the full SHA
    6138f85 View commit details
  5. Copy the full SHA
    e6d1b47 View commit details
  6. feat/sqlx_metric (#4587)

    Co-authored-by: aiden.ma <Aiden.ma@yijinin.com>
    MarkJoyMa and aiden.ma authored Jan 22, 2025
    Copy the full SHA
    030c859 View commit details
  7. Copy the full SHA
    1023800 View commit details
  8. Copy the full SHA
    520d2a2 View commit details
  9. Copy the full SHA
    238c92a View commit details
  10. Copy the full SHA
    cbcacf3 View commit details
  11. Copy the full SHA
    00e0db5 View commit details
  12. Copy the full SHA
    37b54d1 View commit details
  13. chore: add redis test (#4593)

    kevwan authored Jan 22, 2025
    Copy the full SHA
    4307ce4 View commit details

Commits on Jan 25, 2025

  1. chore(deps): bump google.golang.org/protobuf from 1.36.3 to 1.36.4 in…

    … /tools/goctl (#4602)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 25, 2025
    Copy the full SHA
    114311e View commit details
  2. Copy the full SHA
    44504e8 View commit details
  3. chore(deps): bump google.golang.org/protobuf from 1.36.3 to 1.36.4 (#…

    …4601)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 25, 2025
    Copy the full SHA
    7d05a4b View commit details
  4. Copy the full SHA
    64e8c94 View commit details
  5. Copy the full SHA
    a32f6d7 View commit details

Commits on Jan 27, 2025

  1. Potential fix for code scanning alert no. 57: Arbitrary file access d…

    …uring archive extraction ("Zip Slip") (#4604)
    
    Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
    kevwan and github-advanced-security[bot] authored Jan 27, 2025
    Copy the full SHA
    c71829c View commit details
  2. Copy the full SHA
    d415ba3 View commit details

Commits on Jan 28, 2025

  1. Copy the full SHA
    39ce17b View commit details
  2. feat: support freebsd (#4609)

    kevwan authored Jan 28, 2025
    Copy the full SHA
    0bc4206 View commit details
  3. Copy the full SHA
    ae09d0e View commit details
Showing with 2,121 additions and 413 deletions.
  1. +2 −2 .github/workflows/release.yaml
  2. +1 −1 .github/workflows/reviewdog.yml
  3. +2 −2 core/breaker/nopbreaker_test.go
  4. +12 −3 core/conf/config.go
  5. +63 −14 core/conf/config_test.go
  6. +12 −0 core/conf/validate.go
  7. +81 −0 core/conf/validate_test.go
  8. +232 −113 core/discov/internal/registry.go
  9. +208 −23 core/discov/internal/registry_test.go
  10. +1 −0 core/discov/internal/updatelistener.go
  11. +7 −6 core/discov/publisher.go
  12. +8 −1 core/discov/subscriber.go
  13. +25 −0 core/discov/subscriber_test.go
  14. +1 −1 core/fs/files.go
  15. +28 −0 core/logc/logs.go
  16. +36 −0 core/logc/logs_test.go
  17. +8 −0 core/logx/logger.go
  18. +31 −0 core/logx/logs.go
  19. +125 −0 core/logx/logs_test.go
  20. +24 −0 core/logx/richlogger.go
  21. +20 −0 core/logx/richlogger_test.go
  22. +17 −0 core/mapping/unmarshaler.go
  23. +17 −2 core/mapping/unmarshaler_test.go
  24. +1 −1 core/proc/goroutines.go
  25. +1 −1 core/proc/goroutines_test.go
  26. +1 −1 core/proc/profile.go
  27. +1 −1 core/proc/shutdown.go
  28. +1 −1 core/proc/shutdown_test.go
  29. +1 −1 core/proc/signals.go
  30. +1 −1 core/proc/signals_test.go
  31. +4 −0 core/stores/redis/conf.go
  32. +14 −4 core/stores/redis/redis.go
  33. +4 −4 core/stores/redis/redis_test.go
  34. +1 −0 core/stores/sqlx/metrics.go
  35. +21 −0 core/stores/sqlx/sqlmanager.go
  36. +1 −1 core/stringx/node_fuzz_test.go
  37. +14 −4 gateway/config.go
  38. +159 −61 gateway/server.go
  39. +196 −3 gateway/server_test.go
  40. +10 −10 go.mod
  41. +31 −18 go.sum
  42. +4 −0 internal/health/health.go
  43. +3 −3 internal/health/health_test.go
  44. +2 −2 rest/handler/authhandler.go
  45. +2 −2 rest/handler/breakerhandler.go
  46. +3 −3 rest/handler/contentsecurityhandler.go
  47. +6 −5 rest/handler/cryptionhandler.go
  48. +4 −3 rest/handler/cryptionhandler_test.go
  49. +2 −2 rest/handler/sheddinghandler.go
  50. +0 −4 rest/httpc/internal/metricsinterceptor_test.go
  51. +0 −1 rest/httpc/requests.go
  52. +17 −5 rest/httpx/requests.go
  53. +114 −2 rest/httpx/requests_test.go
  54. +2 −1 rest/httpx/responses.go
  55. +10 −0 rest/httpx/util.go
  56. +2 −2 rest/internal/security/contentsecurity.go
  57. +1 −0 tools/goctl/api/cmd.go
  58. +9 −3 tools/goctl/api/gogen/gen.go
  59. +1 −1 tools/goctl/api/gogen/gen_test.go
  60. +80 −0 tools/goctl/api/gogen/genhandlerstest.go
  61. +90 −0 tools/goctl/api/gogen/genlogictest.go
  62. +81 −0 tools/goctl/api/gogen/handler_test.tpl
  63. +69 −0 tools/goctl/api/gogen/logic_test.tpl
  64. +4 −0 tools/goctl/api/gogen/template.go
  65. +1 −1 tools/goctl/api/new/newservice.go
  66. +3 −3 tools/goctl/go.mod
  67. +20 −4 tools/goctl/go.sum
  68. +2 −1 tools/goctl/internal/flags/default_en.json
  69. +1 −1 tools/goctl/migrate/cancel.go
  70. +2 −1 tools/goctl/pkg/parser/api/ast/infostatement.go
  71. +4 −1 tools/goctl/pkg/parser/api/ast/kvexpression.go
  72. +4 −2 tools/goctl/pkg/parser/api/ast/servicestatement.go
  73. +16 −5 tools/goctl/pkg/parser/api/parser/parser.go
  74. +26 −26 tools/goctl/pkg/parser/api/parser/parser_test.go
  75. +4 −4 tools/goctl/pkg/parser/api/parser/testdata/example.api
  76. +1 −11 tools/goctl/pkg/parser/api/scanner/scanner.go
  77. +71 −18 tools/goctl/pkg/parser/api/scanner/scanner_test.go
  78. +0 −2 tools/goctl/pkg/parser/api/token/token.go
  79. +1 −1 tools/goctl/util/pathx/readlink.go
  80. +8 −0 tools/goctl/util/zipx/zipx.go
  81. +5 −5 zrpc/internal/serverinterceptors/recoverinterceptor.go
  82. +16 −1 zrpc/resolver/internal/discovbuilder.go
  83. +4 −4 zrpc/resolver/internal/kubebuilder.go
  84. +3 −3 zrpc/server_test.go
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://dl.google.com/go/go1.20.14.linux-amd64.tar.gz"
goversion: "https://dl.google.com/go/go1.21.13.linux-amd64.tar.gz"
project_path: "tools/goctl"
binary_name: "goctl"
extra_files: tools/goctl/readme.md tools/goctl/readme-cn.md
extra_files: tools/goctl/readme.md tools/goctl/readme-cn.md
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@ jobs:
# Report all results.
filter_mode: nofilter
# Exit with 1 when it find at least one finding.
fail_on_error: true
fail_level: any
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1019,-SA1029,-SA5008
4 changes: 2 additions & 2 deletions core/breaker/nopbreaker_test.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ import (
func TestNopBreaker(t *testing.T) {
b := NopBreaker()
assert.Equal(t, nopBreakerName, b.Name())
p, err := b.Allow()
_, err := b.Allow()
assert.Nil(t, err)
p, err = b.AllowCtx(context.Background())
p, err := b.AllowCtx(context.Background())
assert.Nil(t, err)
p.Accept()
for i := 0; i < 1000; i++ {
15 changes: 12 additions & 3 deletions core/conf/config.go
Original file line number Diff line number Diff line change
@@ -62,7 +62,11 @@ func Load(file string, v any, opts ...Option) error {
return loader([]byte(os.ExpandEnv(string(content))), v)
}

return loader(content, v)
if err = loader(content, v); err != nil {
return err
}

return validate(v)
}

// LoadConfig loads config into v from file, .json, .yaml and .yml are acceptable.
@@ -85,7 +89,12 @@ func LoadFromJsonBytes(content []byte, v any) error {

lowerCaseKeyMap := toLowerCaseKeyMap(m, info)

return mapping.UnmarshalJsonMap(lowerCaseKeyMap, v, mapping.WithCanonicalKeyFunc(toLowerCase))
if err = mapping.UnmarshalJsonMap(lowerCaseKeyMap, v,
mapping.WithCanonicalKeyFunc(toLowerCase)); err != nil {
return err
}

return validate(v)
}

// LoadConfigFromJsonBytes loads config into v from content json bytes.
@@ -192,7 +201,7 @@ func buildFieldsInfo(tp reflect.Type, fullName string) (*fieldInfo, error) {
case reflect.Array, reflect.Slice, reflect.Map:
return buildFieldsInfo(mapping.Deref(tp.Elem()), fullName)
case reflect.Chan, reflect.Func:
return nil, fmt.Errorf("unsupported type: %s", tp.Kind())
return nil, fmt.Errorf("unsupported type: %s, fullName: %s", tp.Kind(), fullName)
default:
return &fieldInfo{
children: make(map[string]*fieldInfo),
77 changes: 63 additions & 14 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conf

import (
"errors"
"os"
"reflect"
"testing"
@@ -40,9 +41,8 @@ func TestConfigJson(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test, func(t *testing.T) {
tmpfile, err := createTempFile(test, text)
tmpfile, err := createTempFile(t, test, text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -82,9 +82,8 @@ c = "${FOO}"
d = "abcd!@#$112"
`
t.Setenv("FOO", "2")
tmpfile, err := createTempFile(".toml", text)
tmpfile, err := createTempFile(t, ".toml", text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -105,9 +104,8 @@ b = 1
c = "FOO"
d = "abcd"
`
tmpfile, err := createTempFile(".toml", text)
tmpfile, err := createTempFile(t, ".toml", text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -127,9 +125,8 @@ func TestConfigWithLower(t *testing.T) {
text := `a = "foo"
b = 1
`
tmpfile, err := createTempFile(".toml", text)
tmpfile, err := createTempFile(t, ".toml", text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -207,9 +204,8 @@ c = "${FOO}"
d = "abcd!@#112"
`
t.Setenv("FOO", "2")
tmpfile, err := createTempFile(".toml", text)
tmpfile, err := createTempFile(t, ".toml", text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -241,9 +237,8 @@ func TestConfigJsonEnv(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test, func(t *testing.T) {
tmpfile, err := createTempFile(test, text)
tmpfile, err := createTempFile(t, test, text)
assert.Nil(t, err)
defer os.Remove(tmpfile)

var val struct {
A string `json:"a"`
@@ -1217,11 +1212,44 @@ Name = "bar"
})
}

func Test_LoadBadConfig(t *testing.T) {
type Config struct {
Name string `json:"name,options=foo|bar"`
}

file, err := createTempFile(t, ".json", `{"name": "baz"}`)
assert.NoError(t, err)

var c Config
err = Load(file, &c)
assert.Error(t, err)
}

func Test_getFullName(t *testing.T) {
assert.Equal(t, "a.b", getFullName("a", "b"))
assert.Equal(t, "a", getFullName("", "a"))
}

func TestValidate(t *testing.T) {
t.Run("normal config", func(t *testing.T) {
var c mockConfig
err := LoadFromJsonBytes([]byte(`{"val": "hello", "number": 8}`), &c)
assert.NoError(t, err)
})

t.Run("error no int", func(t *testing.T) {
var c mockConfig
err := LoadFromJsonBytes([]byte(`{"val": "hello"}`), &c)
assert.Error(t, err)
})

t.Run("error no string", func(t *testing.T) {
var c mockConfig
err := LoadFromJsonBytes([]byte(`{"number": 8}`), &c)
assert.Error(t, err)
})
}

func Test_buildFieldsInfo(t *testing.T) {
type ParentSt struct {
Name string
@@ -1311,13 +1339,13 @@ func Test_buildFieldsInfo(t *testing.T) {
}
}

func createTempFile(ext, text string) (string, error) {
func createTempFile(t *testing.T, ext, text string) (string, error) {
tmpFile, err := os.CreateTemp(os.TempDir(), hash.Md5Hex([]byte(text))+"*"+ext)
if err != nil {
return "", err
}

if err := os.WriteFile(tmpFile.Name(), []byte(text), os.ModeTemporary); err != nil {
if err = os.WriteFile(tmpFile.Name(), []byte(text), os.ModeTemporary); err != nil {
return "", err
}

@@ -1326,5 +1354,26 @@ func createTempFile(ext, text string) (string, error) {
return "", err
}

t.Cleanup(func() {
_ = os.Remove(filename)
})

return filename, nil
}

type mockConfig struct {
Val string
Number int
}

func (m mockConfig) Validate() error {
if len(m.Val) == 0 {
return errors.New("val is empty")
}

if m.Number == 0 {
return errors.New("number is zero")
}

return nil
}
12 changes: 12 additions & 0 deletions core/conf/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package conf

import "github.com/zeromicro/go-zero/core/validation"

// validate validates the value if it implements the Validator interface.
func validate(v any) error {
if val, ok := v.(validation.Validator); ok {
return val.Validate()
}

return nil
}
81 changes: 81 additions & 0 deletions core/conf/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package conf

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
)

type mockType int

func (m mockType) Validate() error {
if m < 10 {
return errors.New("invalid value")
}

return nil
}

type anotherMockType int

func Test_validate(t *testing.T) {
tests := []struct {
name string
v any
wantErr bool
}{
{
name: "invalid",
v: mockType(5),
wantErr: true,
},
{
name: "valid",
v: mockType(10),
wantErr: false,
},
{
name: "not validator",
v: anotherMockType(5),
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validate(tt.v)
assert.Equal(t, tt.wantErr, err != nil)
})
}
}

type mockVal struct {
}

func (m mockVal) Validate() error {
return errors.New("invalid value")
}

func Test_validateValPtr(t *testing.T) {
tests := []struct {
name string
v any
wantErr bool
}{
{
name: "invalid",
v: mockVal{},
},
{
name: "invalid value",
v: &mockVal{},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Error(t, validate(tt.v))
})
}
}
Loading