mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-27 16:45:28 +08:00
Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3315e60272 | ||
|
|
327ef73700 | ||
|
|
eb11521655 | ||
|
|
4c37545e55 | ||
|
|
2f47c1fba4 | ||
|
|
16d54d0ace | ||
|
|
9925bcbf99 | ||
|
|
38a5ecb796 | ||
|
|
af78fc7c5f | ||
|
|
790302b486 | ||
|
|
6a0672b801 | ||
|
|
560c61612c | ||
|
|
6a988dc4a9 | ||
|
|
15842c3c7a | ||
|
|
f2914a74df | ||
|
|
f113d512e8 | ||
|
|
7a4818da59 | ||
|
|
48d0709ca6 | ||
|
|
f747585518 | ||
|
|
507ff96546 | ||
|
|
651eabb4c6 | ||
|
|
e6b4372056 | ||
|
|
24073969a1 | ||
|
|
ca797ed22c | ||
|
|
e347d3f8f8 | ||
|
|
396393b336 | ||
|
|
1f0531b254 | ||
|
|
77fb271a06 | ||
|
|
af7cf79963 | ||
|
|
7926d396d7 | ||
|
|
080cd3df84 | ||
|
|
c4e1a6a2d8 | ||
|
|
4e71e95e44 | ||
|
|
84db9bcd15 | ||
|
|
b28f79ac11 | ||
|
|
e134e77b2b | ||
|
|
f669d84ce8 | ||
|
|
9213b8ac27 | ||
|
|
ae09d0e56d | ||
|
|
0bc4206d08 | ||
|
|
39ce17bfd2 | ||
|
|
d415ba39e2 | ||
|
|
c71829c8de | ||
|
|
a32f6d7642 | ||
|
|
64e8c94198 | ||
|
|
7d05a4bc93 | ||
|
|
44504e8df7 | ||
|
|
114311e51b | ||
|
|
4307ce45fc | ||
|
|
37b54d1fc7 | ||
|
|
00e0db5def | ||
|
|
cbcacf31c1 | ||
|
|
238c92aaa9 | ||
|
|
520d2a2075 | ||
|
|
1023800b02 | ||
|
|
030c859171 | ||
|
|
e6d1b47a43 | ||
|
|
6138f85470 | ||
|
|
bf883101d7 | ||
|
|
33011c7ed1 | ||
|
|
17d98f69e0 | ||
|
|
b650c8c425 | ||
|
|
3d931d7030 | ||
|
|
68da9ed51a | ||
|
|
b25c45b352 | ||
|
|
f05234a967 | ||
|
|
12071d17b4 | ||
|
|
11c47d23df | ||
|
|
024f285f86 | ||
|
|
fa4674611a | ||
|
|
730c3c5246 | ||
|
|
2c9310ac3a | ||
|
|
74ba0bcd50 | ||
|
|
5f4190b6c6 | ||
|
|
e1787b4ccb | ||
|
|
4ac8b492ef | ||
|
|
cdd068575c | ||
|
|
e89e2d8a75 | ||
|
|
acd2b94bd9 | ||
|
|
6a0c8047f4 | ||
|
|
cfe03ea9e1 | ||
|
|
48d21ef8ad | ||
|
|
28a001c5f9 | ||
|
|
22a41cacc7 | ||
|
|
fcc246933c | ||
|
|
5c3679ffe7 | ||
|
|
eaa01ccb9f | ||
|
|
b8206fb46a | ||
|
|
1c3876810e | ||
|
|
1d9159ea39 | ||
|
|
2159d112c3 | ||
|
|
f57874a51f | ||
|
|
8625864d43 | ||
|
|
8f9ba3ec11 | ||
|
|
a1d9bc08f0 | ||
|
|
b9d7f1cc77 | ||
|
|
6700910f64 | ||
|
|
9c4ed394a7 | ||
|
|
fd07a9c6e4 | ||
|
|
b8c239630c | ||
|
|
672ea55736 | ||
|
|
f7097866bf | ||
|
|
796b2bd1b0 | ||
|
|
e1e5fb2071 | ||
|
|
89ecb50005 | ||
|
|
dbed1ea042 | ||
|
|
ad291daf78 | ||
|
|
13746a3706 | ||
|
|
f03b13f632 | ||
|
|
f6f64b1286 | ||
|
|
300a415f5d | ||
|
|
c5de546f8a |
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@@ -22,7 +22,7 @@ jobs:
|
|||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
goos: ${{ matrix.goos }}
|
goos: ${{ matrix.goos }}
|
||||||
goarch: ${{ matrix.goarch }}
|
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"
|
project_path: "tools/goctl"
|
||||||
binary_name: "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
.github/workflows/reviewdog.yml
vendored
2
.github/workflows/reviewdog.yml
vendored
@@ -14,6 +14,6 @@ jobs:
|
|||||||
# Report all results.
|
# Report all results.
|
||||||
filter_mode: nofilter
|
filter_mode: nofilter
|
||||||
# Exit with 1 when it find at least one finding.
|
# Exit with 1 when it find at least one finding.
|
||||||
fail_on_error: true
|
fail_level: any
|
||||||
# Set staticcheck flags
|
# Set staticcheck flags
|
||||||
staticcheck_flags: -checks=inherit,-SA1019,-SA1029,-SA5008
|
staticcheck_flags: -checks=inherit,-SA1019,-SA1029,-SA5008
|
||||||
|
|||||||
37
.github/workflows/version-check.yml
vendored
Normal file
37
.github/workflows/version-check.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: Release Version Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'tools/goctl/v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
version-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
|
||||||
|
- name: Extract tag version
|
||||||
|
id: get_version
|
||||||
|
run: |
|
||||||
|
# Extract version from tools/goctl/v* format
|
||||||
|
echo "VERSION=${GITHUB_REF#refs/tags/tools/goctl/v}" >> $GITHUB_ENV
|
||||||
|
echo "Extracted version: $VERSION"
|
||||||
|
|
||||||
|
- name: Check version in goctl source code
|
||||||
|
run: |
|
||||||
|
# Change to goctl directory
|
||||||
|
cd tools/goctl
|
||||||
|
|
||||||
|
# Check version in BuildVersion constant
|
||||||
|
VERSION_IN_CODE=$(grep -r "const BuildVersion =" . | grep -o '".*"' | tr -d '"')
|
||||||
|
if [ "$VERSION_IN_CODE" != "$VERSION" ]; then
|
||||||
|
echo "Version mismatch: Version in code ($VERSION_IN_CODE) doesn't match tag version ($VERSION)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -11,9 +11,9 @@ import (
|
|||||||
func TestNopBreaker(t *testing.T) {
|
func TestNopBreaker(t *testing.T) {
|
||||||
b := NopBreaker()
|
b := NopBreaker()
|
||||||
assert.Equal(t, nopBreakerName, b.Name())
|
assert.Equal(t, nopBreakerName, b.Name())
|
||||||
p, err := b.Allow()
|
_, err := b.Allow()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
p, err = b.AllowCtx(context.Background())
|
p, err := b.AllowCtx(context.Background())
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
p.Accept()
|
p.Accept()
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
|
|||||||
@@ -62,7 +62,11 @@ func Load(file string, v any, opts ...Option) error {
|
|||||||
return loader([]byte(os.ExpandEnv(string(content))), v)
|
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.
|
// 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)
|
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.
|
// 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:
|
case reflect.Array, reflect.Slice, reflect.Map:
|
||||||
return buildFieldsInfo(mapping.Deref(tp.Elem()), fullName)
|
return buildFieldsInfo(mapping.Deref(tp.Elem()), fullName)
|
||||||
case reflect.Chan, reflect.Func:
|
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:
|
default:
|
||||||
return &fieldInfo{
|
return &fieldInfo{
|
||||||
children: make(map[string]*fieldInfo),
|
children: make(map[string]*fieldInfo),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -40,9 +41,8 @@ func TestConfigJson(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
test := test
|
||||||
t.Run(test, func(t *testing.T) {
|
t.Run(test, func(t *testing.T) {
|
||||||
tmpfile, err := createTempFile(test, text)
|
tmpfile, err := createTempFile(t, test, text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
@@ -82,9 +82,8 @@ c = "${FOO}"
|
|||||||
d = "abcd!@#$112"
|
d = "abcd!@#$112"
|
||||||
`
|
`
|
||||||
t.Setenv("FOO", "2")
|
t.Setenv("FOO", "2")
|
||||||
tmpfile, err := createTempFile(".toml", text)
|
tmpfile, err := createTempFile(t, ".toml", text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
@@ -105,9 +104,8 @@ b = 1
|
|||||||
c = "FOO"
|
c = "FOO"
|
||||||
d = "abcd"
|
d = "abcd"
|
||||||
`
|
`
|
||||||
tmpfile, err := createTempFile(".toml", text)
|
tmpfile, err := createTempFile(t, ".toml", text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
@@ -127,9 +125,8 @@ func TestConfigWithLower(t *testing.T) {
|
|||||||
text := `a = "foo"
|
text := `a = "foo"
|
||||||
b = 1
|
b = 1
|
||||||
`
|
`
|
||||||
tmpfile, err := createTempFile(".toml", text)
|
tmpfile, err := createTempFile(t, ".toml", text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
@@ -207,9 +204,8 @@ c = "${FOO}"
|
|||||||
d = "abcd!@#112"
|
d = "abcd!@#112"
|
||||||
`
|
`
|
||||||
t.Setenv("FOO", "2")
|
t.Setenv("FOO", "2")
|
||||||
tmpfile, err := createTempFile(".toml", text)
|
tmpfile, err := createTempFile(t, ".toml", text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
@@ -241,9 +237,8 @@ func TestConfigJsonEnv(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
test := test
|
||||||
t.Run(test, func(t *testing.T) {
|
t.Run(test, func(t *testing.T) {
|
||||||
tmpfile, err := createTempFile(test, text)
|
tmpfile, err := createTempFile(t, test, text)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(tmpfile)
|
|
||||||
|
|
||||||
var val struct {
|
var val struct {
|
||||||
A string `json:"a"`
|
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) {
|
func Test_getFullName(t *testing.T) {
|
||||||
assert.Equal(t, "a.b", getFullName("a", "b"))
|
assert.Equal(t, "a.b", getFullName("a", "b"))
|
||||||
assert.Equal(t, "a", getFullName("", "a"))
|
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) {
|
func Test_buildFieldsInfo(t *testing.T) {
|
||||||
type ParentSt struct {
|
type ParentSt struct {
|
||||||
Name string
|
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)
|
tmpFile, err := os.CreateTemp(os.TempDir(), hash.Md5Hex([]byte(text))+"*"+ext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1326,5 +1354,26 @@ func createTempFile(ext, text string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
_ = os.Remove(filename)
|
||||||
|
})
|
||||||
|
|
||||||
return filename, nil
|
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
core/conf/validate.go
Normal file
12
core/conf/validate.go
Normal file
@@ -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
core/conf/validate_test.go
Normal file
81
core/conf/validate_test.go
Normal file
@@ -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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,22 +10,24 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
|
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/contextx"
|
|
||||||
"github.com/zeromicro/go-zero/core/lang"
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
|
"github.com/zeromicro/go-zero/core/mathx"
|
||||||
"github.com/zeromicro/go-zero/core/syncx"
|
"github.com/zeromicro/go-zero/core/syncx"
|
||||||
"github.com/zeromicro/go-zero/core/threading"
|
"github.com/zeromicro/go-zero/core/threading"
|
||||||
|
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
|
||||||
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const coolDownDeviation = 0.05
|
||||||
|
|
||||||
var (
|
var (
|
||||||
registry = Registry{
|
registry = Registry{
|
||||||
clusters: make(map[string]*cluster),
|
clusters: make(map[string]*cluster),
|
||||||
}
|
}
|
||||||
connManager = syncx.NewResourceManager()
|
connManager = syncx.NewResourceManager()
|
||||||
errClosed = errors.New("etcd monitor chan has been closed")
|
coolDownUnstable = mathx.NewUnstable(coolDownDeviation)
|
||||||
|
errClosed = errors.New("etcd monitor chan has been closed")
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Registry is a registry that manages the etcd client connections.
|
// A Registry is a registry that manages the etcd client connections.
|
||||||
@@ -41,33 +43,92 @@ func GetRegistry() *Registry {
|
|||||||
|
|
||||||
// GetConn returns an etcd client connection associated with given endpoints.
|
// GetConn returns an etcd client connection associated with given endpoints.
|
||||||
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
||||||
c, _ := r.getCluster(endpoints)
|
c, _ := r.getOrCreateCluster(endpoints)
|
||||||
return c.getClient()
|
return c.getClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
||||||
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener, exactMatch bool) error {
|
func (r *Registry) Monitor(endpoints []string, key string, exactMatch bool, l UpdateListener) error {
|
||||||
c, exists := r.getCluster(endpoints)
|
wkey := watchKey{
|
||||||
|
key: key,
|
||||||
|
exactMatch: exactMatch,
|
||||||
|
}
|
||||||
|
|
||||||
|
c, exists := r.getOrCreateCluster(endpoints)
|
||||||
// if exists, the existing values should be updated to the listener.
|
// if exists, the existing values should be updated to the listener.
|
||||||
if exists {
|
if exists {
|
||||||
kvs := c.getCurrent(key)
|
c.lock.Lock()
|
||||||
for _, kv := range kvs {
|
watcher, ok := c.watchers[wkey]
|
||||||
l.OnAdd(kv)
|
if ok {
|
||||||
|
watcher.listeners = append(watcher.listeners, l)
|
||||||
|
}
|
||||||
|
c.lock.Unlock()
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
kvs := c.getCurrent(wkey)
|
||||||
|
for _, kv := range kvs {
|
||||||
|
l.OnAdd(kv)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.monitor(key, l, exactMatch)
|
return c.monitor(wkey, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) getCluster(endpoints []string) (c *cluster, exists bool) {
|
func (r *Registry) Unmonitor(endpoints []string, key string, exactMatch bool, l UpdateListener) {
|
||||||
|
c, exists := r.getCluster(endpoints)
|
||||||
|
if !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
wkey := watchKey{
|
||||||
|
key: key,
|
||||||
|
exactMatch: exactMatch,
|
||||||
|
}
|
||||||
|
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
watcher, ok := c.watchers[wkey]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, listener := range watcher.listeners {
|
||||||
|
if listener == l {
|
||||||
|
watcher.listeners = append(watcher.listeners[:i], watcher.listeners[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(watcher.listeners) == 0 {
|
||||||
|
if watcher.cancel != nil {
|
||||||
|
watcher.cancel()
|
||||||
|
}
|
||||||
|
delete(c.watchers, wkey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) getCluster(endpoints []string) (*cluster, bool) {
|
||||||
clusterKey := getClusterKey(endpoints)
|
clusterKey := getClusterKey(endpoints)
|
||||||
|
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
c, exists = r.clusters[clusterKey]
|
c, ok := r.clusters[clusterKey]
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
|
|
||||||
|
return c, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) getOrCreateCluster(endpoints []string) (c *cluster, exists bool) {
|
||||||
|
c, exists = r.getCluster(endpoints)
|
||||||
if !exists {
|
if !exists {
|
||||||
|
clusterKey := getClusterKey(endpoints)
|
||||||
|
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
// double-check locking
|
// double-check locking
|
||||||
c, exists = r.clusters[clusterKey]
|
c, exists = r.clusters[clusterKey]
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -79,30 +140,51 @@ func (r *Registry) getCluster(endpoints []string) (c *cluster, exists bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type cluster struct {
|
type (
|
||||||
endpoints []string
|
watchKey struct {
|
||||||
key string
|
key string
|
||||||
values map[string]map[string]string
|
exactMatch bool
|
||||||
listeners map[string][]UpdateListener
|
}
|
||||||
watchGroup *threading.RoutineGroup
|
|
||||||
done chan lang.PlaceholderType
|
watchValue struct {
|
||||||
lock sync.RWMutex
|
listeners []UpdateListener
|
||||||
exactMatch bool
|
values map[string]string
|
||||||
}
|
cancel context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster struct {
|
||||||
|
endpoints []string
|
||||||
|
key string
|
||||||
|
watchers map[watchKey]*watchValue
|
||||||
|
watchGroup *threading.RoutineGroup
|
||||||
|
done chan lang.PlaceholderType
|
||||||
|
lock sync.RWMutex
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func newCluster(endpoints []string) *cluster {
|
func newCluster(endpoints []string) *cluster {
|
||||||
return &cluster{
|
return &cluster{
|
||||||
endpoints: endpoints,
|
endpoints: endpoints,
|
||||||
key: getClusterKey(endpoints),
|
key: getClusterKey(endpoints),
|
||||||
values: make(map[string]map[string]string),
|
watchers: make(map[watchKey]*watchValue),
|
||||||
listeners: make(map[string][]UpdateListener),
|
|
||||||
watchGroup: threading.NewRoutineGroup(),
|
watchGroup: threading.NewRoutineGroup(),
|
||||||
done: make(chan lang.PlaceholderType),
|
done: make(chan lang.PlaceholderType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) context(cli EtcdClient) context.Context {
|
func (c *cluster) addListener(key watchKey, l UpdateListener) {
|
||||||
return contextx.ValueOnlyFrom(cli.Ctx())
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
watcher, ok := c.watchers[key]
|
||||||
|
if ok {
|
||||||
|
watcher.listeners = append(watcher.listeners, l)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val := newWatchValue()
|
||||||
|
val.listeners = []UpdateListener{l}
|
||||||
|
c.watchers[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) getClient() (EtcdClient, error) {
|
func (c *cluster) getClient() (EtcdClient, error) {
|
||||||
@@ -116,12 +198,17 @@ func (c *cluster) getClient() (EtcdClient, error) {
|
|||||||
return val.(EtcdClient), nil
|
return val.(EtcdClient), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) getCurrent(key string) []KV {
|
func (c *cluster) getCurrent(key watchKey) []KV {
|
||||||
c.lock.RLock()
|
c.lock.RLock()
|
||||||
defer c.lock.RUnlock()
|
defer c.lock.RUnlock()
|
||||||
|
|
||||||
|
watcher, ok := c.watchers[key]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var kvs []KV
|
var kvs []KV
|
||||||
for k, v := range c.values[key] {
|
for k, v := range watcher.values {
|
||||||
kvs = append(kvs, KV{
|
kvs = append(kvs, KV{
|
||||||
Key: k,
|
Key: k,
|
||||||
Val: v,
|
Val: v,
|
||||||
@@ -131,43 +218,23 @@ func (c *cluster) getCurrent(key string) []KV {
|
|||||||
return kvs
|
return kvs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) handleChanges(key string, kvs []KV) {
|
func (c *cluster) handleChanges(key watchKey, kvs []KV) {
|
||||||
var add []KV
|
|
||||||
var remove []KV
|
|
||||||
|
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
listeners := append([]UpdateListener(nil), c.listeners[key]...)
|
watcher, ok := c.watchers[key]
|
||||||
vals, ok := c.values[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
add = kvs
|
c.lock.Unlock()
|
||||||
vals = make(map[string]string)
|
return
|
||||||
for _, kv := range kvs {
|
|
||||||
vals[kv.Key] = kv.Val
|
|
||||||
}
|
|
||||||
c.values[key] = vals
|
|
||||||
} else {
|
|
||||||
m := make(map[string]string)
|
|
||||||
for _, kv := range kvs {
|
|
||||||
m[kv.Key] = kv.Val
|
|
||||||
}
|
|
||||||
for k, v := range vals {
|
|
||||||
if val, ok := m[k]; !ok || v != val {
|
|
||||||
remove = append(remove, KV{
|
|
||||||
Key: k,
|
|
||||||
Val: v,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for k, v := range m {
|
|
||||||
if val, ok := vals[k]; !ok || v != val {
|
|
||||||
add = append(add, KV{
|
|
||||||
Key: k,
|
|
||||||
Val: v,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.values[key] = m
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listeners := append([]UpdateListener(nil), watcher.listeners...)
|
||||||
|
// watcher.values cannot be nil
|
||||||
|
vals := watcher.values
|
||||||
|
newVals := make(map[string]string, len(kvs)+len(vals))
|
||||||
|
for _, kv := range kvs {
|
||||||
|
newVals[kv.Key] = kv.Val
|
||||||
|
}
|
||||||
|
add, remove := calculateChanges(vals, newVals)
|
||||||
|
watcher.values = newVals
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
|
|
||||||
for _, kv := range add {
|
for _, kv := range add {
|
||||||
@@ -182,20 +249,22 @@ func (c *cluster) handleChanges(key string, kvs []KV) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
|
func (c *cluster) handleWatchEvents(ctx context.Context, key watchKey, events []*clientv3.Event) {
|
||||||
c.lock.RLock()
|
c.lock.RLock()
|
||||||
listeners := append([]UpdateListener(nil), c.listeners[key]...)
|
watcher, ok := c.watchers[key]
|
||||||
|
if !ok {
|
||||||
|
c.lock.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
listeners := append([]UpdateListener(nil), watcher.listeners...)
|
||||||
c.lock.RUnlock()
|
c.lock.RUnlock()
|
||||||
|
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
switch ev.Type {
|
switch ev.Type {
|
||||||
case clientv3.EventTypePut:
|
case clientv3.EventTypePut:
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
if vals, ok := c.values[key]; ok {
|
watcher.values[string(ev.Kv.Key)] = string(ev.Kv.Value)
|
||||||
vals[string(ev.Kv.Key)] = string(ev.Kv.Value)
|
|
||||||
} else {
|
|
||||||
c.values[key] = map[string]string{string(ev.Kv.Key): string(ev.Kv.Value)}
|
|
||||||
}
|
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
for _, l := range listeners {
|
for _, l := range listeners {
|
||||||
l.OnAdd(KV{
|
l.OnAdd(KV{
|
||||||
@@ -205,9 +274,7 @@ func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
|
|||||||
}
|
}
|
||||||
case clientv3.EventTypeDelete:
|
case clientv3.EventTypeDelete:
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
if vals, ok := c.values[key]; ok {
|
delete(watcher.values, string(ev.Kv.Key))
|
||||||
delete(vals, string(ev.Kv.Key))
|
|
||||||
}
|
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
for _, l := range listeners {
|
for _, l := range listeners {
|
||||||
l.OnDelete(KV{
|
l.OnDelete(KV{
|
||||||
@@ -216,20 +283,20 @@ func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
logx.Errorf("Unknown event type: %v", ev.Type)
|
logc.Errorf(ctx, "Unknown event type: %v", ev.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) load(cli EtcdClient, key string) int64 {
|
func (c *cluster) load(cli EtcdClient, key watchKey) int64 {
|
||||||
var resp *clientv3.GetResponse
|
var resp *clientv3.GetResponse
|
||||||
for {
|
for {
|
||||||
var err error
|
var err error
|
||||||
ctx, cancel := context.WithTimeout(c.context(cli), RequestTimeout)
|
ctx, cancel := context.WithTimeout(cli.Ctx(), RequestTimeout)
|
||||||
if c.exactMatch {
|
if key.exactMatch {
|
||||||
resp, err = cli.Get(ctx, key)
|
resp, err = cli.Get(ctx, key.key)
|
||||||
} else {
|
} else {
|
||||||
resp, err = cli.Get(ctx, makeKeyPrefix(key), clientv3.WithPrefix())
|
resp, err = cli.Get(ctx, makeKeyPrefix(key.key), clientv3.WithPrefix())
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
@@ -237,8 +304,8 @@ func (c *cluster) load(cli EtcdClient, key string) int64 {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
logx.Errorf("%s, key is %s", err.Error(), key)
|
logc.Errorf(cli.Ctx(), "%s, key: %s, exactMatch: %t", err.Error(), key.key, key.exactMatch)
|
||||||
time.Sleep(coolDownInterval)
|
time.Sleep(coolDownUnstable.AroundDuration(coolDownInterval))
|
||||||
}
|
}
|
||||||
|
|
||||||
var kvs []KV
|
var kvs []KV
|
||||||
@@ -254,17 +321,13 @@ func (c *cluster) load(cli EtcdClient, key string) int64 {
|
|||||||
return resp.Header.Revision
|
return resp.Header.Revision
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) monitor(key string, l UpdateListener, exactMatch bool) error {
|
func (c *cluster) monitor(key watchKey, l UpdateListener) error {
|
||||||
c.lock.Lock()
|
|
||||||
c.listeners[key] = append(c.listeners[key], l)
|
|
||||||
c.exactMatch = exactMatch
|
|
||||||
c.lock.Unlock()
|
|
||||||
|
|
||||||
cli, err := c.getClient()
|
cli, err := c.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.addListener(key, l)
|
||||||
rev := c.load(cli, key)
|
rev := c.load(cli, key)
|
||||||
c.watchGroup.Run(func() {
|
c.watchGroup.Run(func() {
|
||||||
c.watch(cli, key, rev)
|
c.watch(cli, key, rev)
|
||||||
@@ -286,16 +349,22 @@ func (c *cluster) newClient() (EtcdClient, error) {
|
|||||||
|
|
||||||
func (c *cluster) reload(cli EtcdClient) {
|
func (c *cluster) reload(cli EtcdClient) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
|
// cancel the previous watches
|
||||||
close(c.done)
|
close(c.done)
|
||||||
c.watchGroup.Wait()
|
c.watchGroup.Wait()
|
||||||
|
var keys []watchKey
|
||||||
|
for wk, wval := range c.watchers {
|
||||||
|
keys = append(keys, wk)
|
||||||
|
if wval.cancel != nil {
|
||||||
|
wval.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.done = make(chan lang.PlaceholderType)
|
c.done = make(chan lang.PlaceholderType)
|
||||||
c.watchGroup = threading.NewRoutineGroup()
|
c.watchGroup = threading.NewRoutineGroup()
|
||||||
var keys []string
|
|
||||||
for k := range c.listeners {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
|
|
||||||
|
// start new watches
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
k := key
|
k := key
|
||||||
c.watchGroup.Run(func() {
|
c.watchGroup.Run(func() {
|
||||||
@@ -305,7 +374,7 @@ func (c *cluster) reload(cli EtcdClient) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) watch(cli EtcdClient, key string, rev int64) {
|
func (c *cluster) watch(cli EtcdClient, key watchKey, rev int64) {
|
||||||
for {
|
for {
|
||||||
err := c.watchStream(cli, key, rev)
|
err := c.watchStream(cli, key, rev)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -313,30 +382,17 @@ func (c *cluster) watch(cli EtcdClient, key string, rev int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rev != 0 && errors.Is(err, rpctypes.ErrCompacted) {
|
if rev != 0 && errors.Is(err, rpctypes.ErrCompacted) {
|
||||||
logx.Errorf("etcd watch stream has been compacted, try to reload, rev %d", rev)
|
logc.Errorf(cli.Ctx(), "etcd watch stream has been compacted, try to reload, rev %d", rev)
|
||||||
rev = c.load(cli, key)
|
rev = c.load(cli, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// log the error and retry
|
// log the error and retry
|
||||||
logx.Error(err)
|
logc.Error(cli.Ctx(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) watchStream(cli EtcdClient, key string, rev int64) error {
|
func (c *cluster) watchStream(cli EtcdClient, key watchKey, rev int64) error {
|
||||||
var (
|
ctx, rch := c.setupWatch(cli, key, rev)
|
||||||
rch clientv3.WatchChan
|
|
||||||
ops []clientv3.OpOption
|
|
||||||
watchKey = key
|
|
||||||
)
|
|
||||||
if !c.exactMatch {
|
|
||||||
watchKey = makeKeyPrefix(key)
|
|
||||||
ops = append(ops, clientv3.WithPrefix())
|
|
||||||
}
|
|
||||||
if rev != 0 {
|
|
||||||
ops = append(ops, clientv3.WithRev(rev+1))
|
|
||||||
}
|
|
||||||
|
|
||||||
rch = cli.Watch(clientv3.WithRequireLeader(c.context(cli)), watchKey, ops...)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -351,13 +407,47 @@ func (c *cluster) watchStream(cli EtcdClient, key string, rev int64) error {
|
|||||||
return fmt.Errorf("etcd monitor chan error: %w", wresp.Err())
|
return fmt.Errorf("etcd monitor chan error: %w", wresp.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
c.handleWatchEvents(key, wresp.Events)
|
c.handleWatchEvents(ctx, key, wresp.Events)
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
case <-c.done:
|
case <-c.done:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cluster) setupWatch(cli EtcdClient, key watchKey, rev int64) (context.Context, clientv3.WatchChan) {
|
||||||
|
var (
|
||||||
|
rch clientv3.WatchChan
|
||||||
|
ops []clientv3.OpOption
|
||||||
|
wkey = key.key
|
||||||
|
)
|
||||||
|
|
||||||
|
if !key.exactMatch {
|
||||||
|
wkey = makeKeyPrefix(key.key)
|
||||||
|
ops = append(ops, clientv3.WithPrefix())
|
||||||
|
}
|
||||||
|
if rev != 0 {
|
||||||
|
ops = append(ops, clientv3.WithRev(rev+1))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(cli.Ctx())
|
||||||
|
if watcher, ok := c.watchers[key]; ok {
|
||||||
|
watcher.cancel = cancel
|
||||||
|
} else {
|
||||||
|
val := newWatchValue()
|
||||||
|
val.cancel = cancel
|
||||||
|
|
||||||
|
c.lock.Lock()
|
||||||
|
c.watchers[key] = val
|
||||||
|
c.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
rch = cli.Watch(clientv3.WithRequireLeader(ctx), wkey, ops...)
|
||||||
|
|
||||||
|
return ctx, rch
|
||||||
|
}
|
||||||
|
|
||||||
func (c *cluster) watchConnState(cli EtcdClient) {
|
func (c *cluster) watchConnState(cli EtcdClient) {
|
||||||
watcher := newStateWatcher()
|
watcher := newStateWatcher()
|
||||||
watcher.addListener(func() {
|
watcher.addListener(func() {
|
||||||
@@ -386,6 +476,28 @@ func DialClient(endpoints []string) (EtcdClient, error) {
|
|||||||
return clientv3.New(cfg)
|
return clientv3.New(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calculateChanges(oldVals, newVals map[string]string) (add, remove []KV) {
|
||||||
|
for k, v := range newVals {
|
||||||
|
if val, ok := oldVals[k]; !ok || v != val {
|
||||||
|
add = append(add, KV{
|
||||||
|
Key: k,
|
||||||
|
Val: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range oldVals {
|
||||||
|
if val, ok := newVals[k]; !ok || v != val {
|
||||||
|
remove = append(remove, KV{
|
||||||
|
Key: k,
|
||||||
|
Val: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return add, remove
|
||||||
|
}
|
||||||
|
|
||||||
func getClusterKey(endpoints []string) string {
|
func getClusterKey(endpoints []string) string {
|
||||||
sort.Strings(endpoints)
|
sort.Strings(endpoints)
|
||||||
return strings.Join(endpoints, endpointsSeparator)
|
return strings.Join(endpoints, endpointsSeparator)
|
||||||
@@ -394,3 +506,10 @@ func getClusterKey(endpoints []string) string {
|
|||||||
func makeKeyPrefix(key string) string {
|
func makeKeyPrefix(key string) string {
|
||||||
return fmt.Sprintf("%s%c", key, Delimiter)
|
return fmt.Sprintf("%s%c", key, Delimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewClient returns a watchValue that make sure values are not nil.
|
||||||
|
func newWatchValue() *watchValue {
|
||||||
|
return &watchValue{
|
||||||
|
values: make(map[string]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/lang"
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
"github.com/zeromicro/go-zero/core/threading"
|
||||||
"go.etcd.io/etcd/api/v3/etcdserverpb"
|
"go.etcd.io/etcd/api/v3/etcdserverpb"
|
||||||
"go.etcd.io/etcd/api/v3/mvccpb"
|
"go.etcd.io/etcd/api/v3/mvccpb"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
@@ -38,9 +39,9 @@ func setMockClient(cli EtcdClient) func() {
|
|||||||
|
|
||||||
func TestGetCluster(t *testing.T) {
|
func TestGetCluster(t *testing.T) {
|
||||||
AddAccount([]string{"first"}, "foo", "bar")
|
AddAccount([]string{"first"}, "foo", "bar")
|
||||||
c1, _ := GetRegistry().getCluster([]string{"first"})
|
c1, _ := GetRegistry().getOrCreateCluster([]string{"first"})
|
||||||
c2, _ := GetRegistry().getCluster([]string{"second"})
|
c2, _ := GetRegistry().getOrCreateCluster([]string{"second"})
|
||||||
c3, _ := GetRegistry().getCluster([]string{"first"})
|
c3, _ := GetRegistry().getOrCreateCluster([]string{"first"})
|
||||||
assert.Equal(t, c1, c3)
|
assert.Equal(t, c1, c3)
|
||||||
assert.NotEqual(t, c1, c2)
|
assert.NotEqual(t, c1, c2)
|
||||||
}
|
}
|
||||||
@@ -50,6 +51,36 @@ func TestGetClusterKey(t *testing.T) {
|
|||||||
getClusterKey([]string{"remotehost:5678", "localhost:1234"}))
|
getClusterKey([]string{"remotehost:5678", "localhost:1234"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmonitor(t *testing.T) {
|
||||||
|
t.Run("no listener", func(t *testing.T) {
|
||||||
|
reg := &Registry{
|
||||||
|
clusters: map[string]*cluster{},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
reg.Unmonitor([]string{"any"}, "any", false, nil)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("no value", func(t *testing.T) {
|
||||||
|
reg := &Registry{
|
||||||
|
clusters: map[string]*cluster{
|
||||||
|
"any": {
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
{
|
||||||
|
key: "any",
|
||||||
|
}: {
|
||||||
|
values: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
reg.Unmonitor([]string{"any"}, "another", false, nil)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestCluster_HandleChanges(t *testing.T) {
|
func TestCluster_HandleChanges(t *testing.T) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
l := NewMockUpdateListener(ctrl)
|
l := NewMockUpdateListener(ctrl)
|
||||||
@@ -78,8 +109,14 @@ func TestCluster_HandleChanges(t *testing.T) {
|
|||||||
Val: "4",
|
Val: "4",
|
||||||
})
|
})
|
||||||
c := newCluster([]string{"any"})
|
c := newCluster([]string{"any"})
|
||||||
c.listeners["any"] = []UpdateListener{l}
|
key := watchKey{
|
||||||
c.handleChanges("any", []KV{
|
key: "any",
|
||||||
|
exactMatch: false,
|
||||||
|
}
|
||||||
|
c.watchers[key] = &watchValue{
|
||||||
|
listeners: []UpdateListener{l},
|
||||||
|
}
|
||||||
|
c.handleChanges(key, []KV{
|
||||||
{
|
{
|
||||||
Key: "first",
|
Key: "first",
|
||||||
Val: "1",
|
Val: "1",
|
||||||
@@ -92,8 +129,8 @@ func TestCluster_HandleChanges(t *testing.T) {
|
|||||||
assert.EqualValues(t, map[string]string{
|
assert.EqualValues(t, map[string]string{
|
||||||
"first": "1",
|
"first": "1",
|
||||||
"second": "2",
|
"second": "2",
|
||||||
}, c.values["any"])
|
}, c.watchers[key].values)
|
||||||
c.handleChanges("any", []KV{
|
c.handleChanges(key, []KV{
|
||||||
{
|
{
|
||||||
Key: "third",
|
Key: "third",
|
||||||
Val: "3",
|
Val: "3",
|
||||||
@@ -106,7 +143,7 @@ func TestCluster_HandleChanges(t *testing.T) {
|
|||||||
assert.EqualValues(t, map[string]string{
|
assert.EqualValues(t, map[string]string{
|
||||||
"third": "3",
|
"third": "3",
|
||||||
"fourth": "4",
|
"fourth": "4",
|
||||||
}, c.values["any"])
|
}, c.watchers[key].values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCluster_Load(t *testing.T) {
|
func TestCluster_Load(t *testing.T) {
|
||||||
@@ -126,9 +163,11 @@ func TestCluster_Load(t *testing.T) {
|
|||||||
}, nil)
|
}, nil)
|
||||||
cli.EXPECT().Ctx().Return(context.Background())
|
cli.EXPECT().Ctx().Return(context.Background())
|
||||||
c := &cluster{
|
c := &cluster{
|
||||||
values: make(map[string]map[string]string),
|
watchers: make(map[watchKey]*watchValue),
|
||||||
}
|
}
|
||||||
c.load(cli, "any")
|
c.load(cli, watchKey{
|
||||||
|
key: "any",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCluster_Watch(t *testing.T) {
|
func TestCluster_Watch(t *testing.T) {
|
||||||
@@ -160,11 +199,16 @@ func TestCluster_Watch(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
c := &cluster{
|
c := &cluster{
|
||||||
listeners: make(map[string][]UpdateListener),
|
watchers: make(map[watchKey]*watchValue),
|
||||||
values: make(map[string]map[string]string),
|
}
|
||||||
|
key := watchKey{
|
||||||
|
key: "any",
|
||||||
}
|
}
|
||||||
listener := NewMockUpdateListener(ctrl)
|
listener := NewMockUpdateListener(ctrl)
|
||||||
c.listeners["any"] = []UpdateListener{listener}
|
c.watchers[key] = &watchValue{
|
||||||
|
listeners: []UpdateListener{listener},
|
||||||
|
values: make(map[string]string),
|
||||||
|
}
|
||||||
listener.EXPECT().OnAdd(gomock.Any()).Do(func(kv KV) {
|
listener.EXPECT().OnAdd(gomock.Any()).Do(func(kv KV) {
|
||||||
assert.Equal(t, "hello", kv.Key)
|
assert.Equal(t, "hello", kv.Key)
|
||||||
assert.Equal(t, "world", kv.Val)
|
assert.Equal(t, "world", kv.Val)
|
||||||
@@ -173,7 +217,7 @@ func TestCluster_Watch(t *testing.T) {
|
|||||||
listener.EXPECT().OnDelete(gomock.Any()).Do(func(_ any) {
|
listener.EXPECT().OnDelete(gomock.Any()).Do(func(_ any) {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}).MaxTimes(1)
|
}).MaxTimes(1)
|
||||||
go c.watch(cli, "any", 0)
|
go c.watch(cli, key, 0)
|
||||||
ch <- clientv3.WatchResponse{
|
ch <- clientv3.WatchResponse{
|
||||||
Events: []*clientv3.Event{
|
Events: []*clientv3.Event{
|
||||||
{
|
{
|
||||||
@@ -211,17 +255,111 @@ func TestClusterWatch_RespFailures(t *testing.T) {
|
|||||||
ch := make(chan clientv3.WatchResponse)
|
ch := make(chan clientv3.WatchResponse)
|
||||||
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
||||||
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
||||||
c := new(cluster)
|
c := &cluster{
|
||||||
|
watchers: make(map[watchKey]*watchValue),
|
||||||
|
}
|
||||||
c.done = make(chan lang.PlaceholderType)
|
c.done = make(chan lang.PlaceholderType)
|
||||||
go func() {
|
go func() {
|
||||||
ch <- resp
|
ch <- resp
|
||||||
close(c.done)
|
close(c.done)
|
||||||
}()
|
}()
|
||||||
c.watch(cli, "any", 0)
|
key := watchKey{
|
||||||
|
key: "any",
|
||||||
|
}
|
||||||
|
c.watch(cli, key, 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCluster_getCurrent(t *testing.T) {
|
||||||
|
t.Run("no value", func(t *testing.T) {
|
||||||
|
c := &cluster{
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
{
|
||||||
|
key: "any",
|
||||||
|
}: {
|
||||||
|
values: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Nil(t, c.getCurrent(watchKey{
|
||||||
|
key: "another",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCluster_handleWatchEvents(t *testing.T) {
|
||||||
|
t.Run("no value", func(t *testing.T) {
|
||||||
|
c := &cluster{
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
{
|
||||||
|
key: "any",
|
||||||
|
}: {
|
||||||
|
values: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
c.handleWatchEvents(context.Background(), watchKey{
|
||||||
|
key: "another",
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCluster_addListener(t *testing.T) {
|
||||||
|
t.Run("has listener", func(t *testing.T) {
|
||||||
|
c := &cluster{
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
{
|
||||||
|
key: "any",
|
||||||
|
}: {
|
||||||
|
listeners: make([]UpdateListener, 0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
c.addListener(watchKey{
|
||||||
|
key: "any",
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("no listener", func(t *testing.T) {
|
||||||
|
c := &cluster{
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
{
|
||||||
|
key: "any",
|
||||||
|
}: {
|
||||||
|
listeners: make([]UpdateListener, 0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
c.addListener(watchKey{
|
||||||
|
key: "another",
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCluster_reload(t *testing.T) {
|
||||||
|
c := &cluster{
|
||||||
|
watchers: map[watchKey]*watchValue{},
|
||||||
|
watchGroup: threading.NewRoutineGroup(),
|
||||||
|
done: make(chan lang.PlaceholderType),
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
cli := NewMockEtcdClient(ctrl)
|
||||||
|
restore := setMockClient(cli)
|
||||||
|
defer restore()
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
c.reload(cli)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestClusterWatch_CloseChan(t *testing.T) {
|
func TestClusterWatch_CloseChan(t *testing.T) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
@@ -231,13 +369,17 @@ func TestClusterWatch_CloseChan(t *testing.T) {
|
|||||||
ch := make(chan clientv3.WatchResponse)
|
ch := make(chan clientv3.WatchResponse)
|
||||||
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
||||||
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
||||||
c := new(cluster)
|
c := &cluster{
|
||||||
|
watchers: make(map[watchKey]*watchValue),
|
||||||
|
}
|
||||||
c.done = make(chan lang.PlaceholderType)
|
c.done = make(chan lang.PlaceholderType)
|
||||||
go func() {
|
go func() {
|
||||||
close(ch)
|
close(ch)
|
||||||
close(c.done)
|
close(c.done)
|
||||||
}()
|
}()
|
||||||
c.watch(cli, "any", 0)
|
c.watch(cli, watchKey{
|
||||||
|
key: "any",
|
||||||
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValueOnlyContext(t *testing.T) {
|
func TestValueOnlyContext(t *testing.T) {
|
||||||
@@ -280,16 +422,59 @@ func TestRegistry_Monitor(t *testing.T) {
|
|||||||
GetRegistry().lock.Lock()
|
GetRegistry().lock.Lock()
|
||||||
GetRegistry().clusters = map[string]*cluster{
|
GetRegistry().clusters = map[string]*cluster{
|
||||||
getClusterKey(endpoints): {
|
getClusterKey(endpoints): {
|
||||||
listeners: map[string][]UpdateListener{},
|
watchers: map[watchKey]*watchValue{
|
||||||
values: map[string]map[string]string{
|
watchKey{
|
||||||
"foo": {
|
key: "foo",
|
||||||
"bar": "baz",
|
exactMatch: true,
|
||||||
|
}: {
|
||||||
|
values: map[string]string{
|
||||||
|
"bar": "baz",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
GetRegistry().lock.Unlock()
|
GetRegistry().lock.Unlock()
|
||||||
assert.Error(t, GetRegistry().Monitor(endpoints, "foo", new(mockListener), false))
|
assert.Error(t, GetRegistry().Monitor(endpoints, "foo", false, new(mockListener)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistry_Unmonitor(t *testing.T) {
|
||||||
|
svr, err := mockserver.StartMockServers(1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
svr.StartAt(0)
|
||||||
|
|
||||||
|
_, cancel := context.WithCancel(context.Background())
|
||||||
|
endpoints := []string{svr.Servers[0].Address}
|
||||||
|
GetRegistry().lock.Lock()
|
||||||
|
GetRegistry().clusters = map[string]*cluster{
|
||||||
|
getClusterKey(endpoints): {
|
||||||
|
watchers: map[watchKey]*watchValue{
|
||||||
|
watchKey{
|
||||||
|
key: "foo",
|
||||||
|
exactMatch: true,
|
||||||
|
}: {
|
||||||
|
values: map[string]string{
|
||||||
|
"bar": "baz",
|
||||||
|
},
|
||||||
|
cancel: cancel,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
GetRegistry().lock.Unlock()
|
||||||
|
l := new(mockListener)
|
||||||
|
assert.NoError(t, GetRegistry().Monitor(endpoints, "foo", true, l))
|
||||||
|
watchVals := GetRegistry().clusters[getClusterKey(endpoints)].watchers[watchKey{
|
||||||
|
key: "foo",
|
||||||
|
exactMatch: true,
|
||||||
|
}]
|
||||||
|
assert.Equal(t, 1, len(watchVals.listeners))
|
||||||
|
GetRegistry().Unmonitor(endpoints, "foo", true, l)
|
||||||
|
watchVals = GetRegistry().clusters[getClusterKey(endpoints)].watchers[watchKey{
|
||||||
|
key: "foo",
|
||||||
|
exactMatch: true,
|
||||||
|
}]
|
||||||
|
assert.Nil(t, watchVals)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockListener struct {
|
type mockListener struct {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateListener wraps the OnAdd and OnDelete methods.
|
// UpdateListener wraps the OnAdd and OnDelete methods.
|
||||||
|
// The implementation should be thread-safe and idempotent.
|
||||||
UpdateListener interface {
|
UpdateListener interface {
|
||||||
OnAdd(kv KV)
|
OnAdd(kv KV)
|
||||||
OnDelete(kv KV)
|
OnDelete(kv KV)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/discov/internal"
|
"github.com/zeromicro/go-zero/core/discov/internal"
|
||||||
"github.com/zeromicro/go-zero/core/lang"
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/proc"
|
"github.com/zeromicro/go-zero/core/proc"
|
||||||
"github.com/zeromicro/go-zero/core/syncx"
|
"github.com/zeromicro/go-zero/core/syncx"
|
||||||
@@ -91,12 +92,12 @@ func (p *Publisher) doKeepAlive() error {
|
|||||||
default:
|
default:
|
||||||
cli, err := p.doRegister()
|
cli, err := p.doRegister()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("etcd publisher doRegister: %s", err.Error())
|
logc.Errorf(cli.Ctx(), "etcd publisher doRegister: %s", err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.keepAliveAsync(cli); err != nil {
|
if err := p.keepAliveAsync(cli); err != nil {
|
||||||
logx.Errorf("etcd publisher keepAliveAsync: %s", err.Error())
|
logc.Errorf(cli.Ctx(), "etcd publisher keepAliveAsync: %s", err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,17 +131,17 @@ func (p *Publisher) keepAliveAsync(cli internal.EtcdClient) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
p.revoke(cli)
|
p.revoke(cli)
|
||||||
if err := p.doKeepAlive(); err != nil {
|
if err := p.doKeepAlive(); err != nil {
|
||||||
logx.Errorf("etcd publisher KeepAlive: %s", err.Error())
|
logc.Errorf(cli.Ctx(), "etcd publisher KeepAlive: %s", err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case <-p.pauseChan:
|
case <-p.pauseChan:
|
||||||
logx.Infof("paused etcd renew, key: %s, value: %s", p.key, p.value)
|
logc.Infof(cli.Ctx(), "paused etcd renew, key: %s, value: %s", p.key, p.value)
|
||||||
p.revoke(cli)
|
p.revoke(cli)
|
||||||
select {
|
select {
|
||||||
case <-p.resumeChan:
|
case <-p.resumeChan:
|
||||||
if err := p.doKeepAlive(); err != nil {
|
if err := p.doKeepAlive(); err != nil {
|
||||||
logx.Errorf("etcd publisher KeepAlive: %s", err.Error())
|
logc.Errorf(cli.Ctx(), "etcd publisher KeepAlive: %s", err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case <-p.quit.Done():
|
case <-p.quit.Done():
|
||||||
@@ -175,7 +176,7 @@ func (p *Publisher) register(client internal.EtcdClient) (clientv3.LeaseID, erro
|
|||||||
|
|
||||||
func (p *Publisher) revoke(cli internal.EtcdClient) {
|
func (p *Publisher) revoke(cli internal.EtcdClient) {
|
||||||
if _, err := cli.Revoke(cli.Ctx(), p.lease); err != nil {
|
if _, err := cli.Revoke(cli.Ctx(), p.lease); err != nil {
|
||||||
logx.Errorf("etcd publisher revoke: %s", err.Error())
|
logc.Errorf(cli.Ctx(), "etcd publisher revoke: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type (
|
|||||||
Subscriber struct {
|
Subscriber struct {
|
||||||
endpoints []string
|
endpoints []string
|
||||||
exclusive bool
|
exclusive bool
|
||||||
|
key string
|
||||||
exactMatch bool
|
exactMatch bool
|
||||||
items *container
|
items *container
|
||||||
}
|
}
|
||||||
@@ -29,13 +30,14 @@ type (
|
|||||||
func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error) {
|
func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error) {
|
||||||
sub := &Subscriber{
|
sub := &Subscriber{
|
||||||
endpoints: endpoints,
|
endpoints: endpoints,
|
||||||
|
key: key,
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(sub)
|
opt(sub)
|
||||||
}
|
}
|
||||||
sub.items = newContainer(sub.exclusive)
|
sub.items = newContainer(sub.exclusive)
|
||||||
|
|
||||||
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items, sub.exactMatch); err != nil {
|
if err := internal.GetRegistry().Monitor(endpoints, key, sub.exactMatch, sub.items); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +49,11 @@ func (s *Subscriber) AddListener(listener func()) {
|
|||||||
s.items.addListener(listener)
|
s.items.addListener(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the subscriber.
|
||||||
|
func (s *Subscriber) Close() {
|
||||||
|
internal.GetRegistry().Unmonitor(s.endpoints, s.key, s.exactMatch, s.items)
|
||||||
|
}
|
||||||
|
|
||||||
// Values returns all the subscription values.
|
// Values returns all the subscription values.
|
||||||
func (s *Subscriber) Values() []string {
|
func (s *Subscriber) Values() []string {
|
||||||
return s.items.getValues()
|
return s.items.getValues()
|
||||||
|
|||||||
@@ -225,3 +225,28 @@ func TestWithSubEtcdAccount(t *testing.T) {
|
|||||||
assert.Equal(t, user, account.User)
|
assert.Equal(t, user, account.User)
|
||||||
assert.Equal(t, "bar", account.Pass)
|
assert.Equal(t, "bar", account.Pass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWithExactMatch(t *testing.T) {
|
||||||
|
sub := new(Subscriber)
|
||||||
|
WithExactMatch()(sub)
|
||||||
|
sub.items = newContainer(sub.exclusive)
|
||||||
|
var count int32
|
||||||
|
sub.AddListener(func() {
|
||||||
|
atomic.AddInt32(&count, 1)
|
||||||
|
})
|
||||||
|
sub.items.notifyChange()
|
||||||
|
assert.Empty(t, sub.Values())
|
||||||
|
assert.Equal(t, int32(1), atomic.LoadInt32(&count))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubscriberClose(t *testing.T) {
|
||||||
|
l := newContainer(false)
|
||||||
|
sub := &Subscriber{
|
||||||
|
endpoints: []string{"localhost:12379"},
|
||||||
|
key: "foo",
|
||||||
|
items: l,
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
sub.Close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ func Debugf(ctx context.Context, format string, v ...interface{}) {
|
|||||||
getLogger(ctx).Debugf(format, v...)
|
getLogger(ctx).Debugf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debugfn writes fn result into access log.
|
||||||
|
// This is useful when the function is expensive to compute,
|
||||||
|
// and we want to log it only when necessary.
|
||||||
|
func Debugfn(ctx context.Context, fn func() any) {
|
||||||
|
getLogger(ctx).Debugfn(fn)
|
||||||
|
}
|
||||||
|
|
||||||
// Debugv writes v into access log with json content.
|
// Debugv writes v into access log with json content.
|
||||||
func Debugv(ctx context.Context, v interface{}) {
|
func Debugv(ctx context.Context, v interface{}) {
|
||||||
getLogger(ctx).Debugv(v)
|
getLogger(ctx).Debugv(v)
|
||||||
@@ -57,6 +64,13 @@ func Errorf(ctx context.Context, format string, v ...any) {
|
|||||||
getLogger(ctx).Errorf(fmt.Errorf(format, v...).Error())
|
getLogger(ctx).Errorf(fmt.Errorf(format, v...).Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorfn writes fn result into error log.
|
||||||
|
// This is useful when the function is expensive to compute,
|
||||||
|
// and we want to log it only when necessary.
|
||||||
|
func Errorfn(ctx context.Context, fn func() any) {
|
||||||
|
getLogger(ctx).Errorfn(fn)
|
||||||
|
}
|
||||||
|
|
||||||
// Errorv writes v into error log with json content.
|
// Errorv writes v into error log with json content.
|
||||||
// No call stack attached, because not elegant to pack the messages.
|
// No call stack attached, because not elegant to pack the messages.
|
||||||
func Errorv(ctx context.Context, v any) {
|
func Errorv(ctx context.Context, v any) {
|
||||||
@@ -83,6 +97,13 @@ func Infof(ctx context.Context, format string, v ...any) {
|
|||||||
getLogger(ctx).Infof(format, v...)
|
getLogger(ctx).Infof(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infofn writes fn result into access log.
|
||||||
|
// This is useful when the function is expensive to compute,
|
||||||
|
// and we want to log it only when necessary.
|
||||||
|
func Infofn(ctx context.Context, fn func() any) {
|
||||||
|
getLogger(ctx).Infofn(fn)
|
||||||
|
}
|
||||||
|
|
||||||
// Infov writes v into access log with json content.
|
// Infov writes v into access log with json content.
|
||||||
func Infov(ctx context.Context, v any) {
|
func Infov(ctx context.Context, v any) {
|
||||||
getLogger(ctx).Infov(v)
|
getLogger(ctx).Infov(v)
|
||||||
@@ -127,6 +148,13 @@ func Slowf(ctx context.Context, format string, v ...any) {
|
|||||||
getLogger(ctx).Slowf(format, v...)
|
getLogger(ctx).Slowf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Slowfn writes fn result into slow log.
|
||||||
|
// This is useful when the function is expensive to compute,
|
||||||
|
// and we want to log it only when necessary.
|
||||||
|
func Slowfn(ctx context.Context, fn func() any) {
|
||||||
|
getLogger(ctx).Slowfn(fn)
|
||||||
|
}
|
||||||
|
|
||||||
// Slowv writes v into slow log with json content.
|
// Slowv writes v into slow log with json content.
|
||||||
func Slowv(ctx context.Context, v any) {
|
func Slowv(ctx context.Context, v any) {
|
||||||
getLogger(ctx).Slowv(v)
|
getLogger(ctx).Slowv(v)
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ func TestErrorf(t *testing.T) {
|
|||||||
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorfn(t *testing.T) {
|
||||||
|
buf := logtest.NewCollector(t)
|
||||||
|
file, line := getFileLine()
|
||||||
|
Errorfn(context.Background(), func() any {
|
||||||
|
return fmt.Sprintf("foo %s", "bar")
|
||||||
|
})
|
||||||
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestErrorv(t *testing.T) {
|
func TestErrorv(t *testing.T) {
|
||||||
buf := logtest.NewCollector(t)
|
buf := logtest.NewCollector(t)
|
||||||
file, line := getFileLine()
|
file, line := getFileLine()
|
||||||
@@ -77,6 +86,15 @@ func TestInfof(t *testing.T) {
|
|||||||
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInfofn(t *testing.T) {
|
||||||
|
buf := logtest.NewCollector(t)
|
||||||
|
file, line := getFileLine()
|
||||||
|
Infofn(context.Background(), func() any {
|
||||||
|
return fmt.Sprintf("foo %s", "bar")
|
||||||
|
})
|
||||||
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestInfov(t *testing.T) {
|
func TestInfov(t *testing.T) {
|
||||||
buf := logtest.NewCollector(t)
|
buf := logtest.NewCollector(t)
|
||||||
file, line := getFileLine()
|
file, line := getFileLine()
|
||||||
@@ -105,6 +123,15 @@ func TestDebugf(t *testing.T) {
|
|||||||
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDebugfn(t *testing.T) {
|
||||||
|
buf := logtest.NewCollector(t)
|
||||||
|
file, line := getFileLine()
|
||||||
|
Debugfn(context.Background(), func() any {
|
||||||
|
return fmt.Sprintf("foo %s", "bar")
|
||||||
|
})
|
||||||
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestDebugv(t *testing.T) {
|
func TestDebugv(t *testing.T) {
|
||||||
buf := logtest.NewCollector(t)
|
buf := logtest.NewCollector(t)
|
||||||
file, line := getFileLine()
|
file, line := getFileLine()
|
||||||
@@ -148,6 +175,15 @@ func TestSlowf(t *testing.T) {
|
|||||||
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)), buf.String())
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)), buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSlowfn(t *testing.T) {
|
||||||
|
buf := logtest.NewCollector(t)
|
||||||
|
file, line := getFileLine()
|
||||||
|
Slowfn(context.Background(), func() any {
|
||||||
|
return fmt.Sprintf("foo %s", "bar")
|
||||||
|
})
|
||||||
|
assert.True(t, strings.Contains(buf.String(), fmt.Sprintf("%s:%d", file, line+1)), buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestSlowv(t *testing.T) {
|
func TestSlowv(t *testing.T) {
|
||||||
buf := logtest.NewCollector(t)
|
buf := logtest.NewCollector(t)
|
||||||
file, line := getFileLine()
|
file, line := getFileLine()
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ type Logger interface {
|
|||||||
Debug(...any)
|
Debug(...any)
|
||||||
// Debugf logs a message at debug level.
|
// Debugf logs a message at debug level.
|
||||||
Debugf(string, ...any)
|
Debugf(string, ...any)
|
||||||
|
// Debugfn logs a message at debug level.
|
||||||
|
Debugfn(func() any)
|
||||||
// Debugv logs a message at debug level.
|
// Debugv logs a message at debug level.
|
||||||
Debugv(any)
|
Debugv(any)
|
||||||
// Debugw logs a message at debug level.
|
// Debugw logs a message at debug level.
|
||||||
@@ -19,6 +21,8 @@ type Logger interface {
|
|||||||
Error(...any)
|
Error(...any)
|
||||||
// Errorf logs a message at error level.
|
// Errorf logs a message at error level.
|
||||||
Errorf(string, ...any)
|
Errorf(string, ...any)
|
||||||
|
// Errorfn logs a message at error level.
|
||||||
|
Errorfn(func() any)
|
||||||
// Errorv logs a message at error level.
|
// Errorv logs a message at error level.
|
||||||
Errorv(any)
|
Errorv(any)
|
||||||
// Errorw logs a message at error level.
|
// Errorw logs a message at error level.
|
||||||
@@ -27,6 +31,8 @@ type Logger interface {
|
|||||||
Info(...any)
|
Info(...any)
|
||||||
// Infof logs a message at info level.
|
// Infof logs a message at info level.
|
||||||
Infof(string, ...any)
|
Infof(string, ...any)
|
||||||
|
// Infofn logs a message at info level.
|
||||||
|
Infofn(func() any)
|
||||||
// Infov logs a message at info level.
|
// Infov logs a message at info level.
|
||||||
Infov(any)
|
Infov(any)
|
||||||
// Infow logs a message at info level.
|
// Infow logs a message at info level.
|
||||||
@@ -35,6 +41,8 @@ type Logger interface {
|
|||||||
Slow(...any)
|
Slow(...any)
|
||||||
// Slowf logs a message at slow level.
|
// Slowf logs a message at slow level.
|
||||||
Slowf(string, ...any)
|
Slowf(string, ...any)
|
||||||
|
// Slowfn logs a message at slow level.
|
||||||
|
Slowfn(func() any)
|
||||||
// Slowv logs a message at slow level.
|
// Slowv logs a message at slow level.
|
||||||
Slowv(any)
|
Slowv(any)
|
||||||
// Sloww logs a message at slow level.
|
// Sloww logs a message at slow level.
|
||||||
|
|||||||
@@ -100,6 +100,14 @@ func Debugf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debugfn writes function result into access log if debug level enabled.
|
||||||
|
// This is useful when the function is expensive to call and debug level disabled.
|
||||||
|
func Debugfn(fn func() any) {
|
||||||
|
if shallLog(DebugLevel) {
|
||||||
|
writeDebug(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Debugv writes v into access log with json content.
|
// Debugv writes v into access log with json content.
|
||||||
func Debugv(v any) {
|
func Debugv(v any) {
|
||||||
if shallLog(DebugLevel) {
|
if shallLog(DebugLevel) {
|
||||||
@@ -139,6 +147,13 @@ func Errorf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorfn writes function result into error log.
|
||||||
|
func Errorfn(fn func() any) {
|
||||||
|
if shallLog(ErrorLevel) {
|
||||||
|
writeError(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorStack writes v along with call stack into error log.
|
// ErrorStack writes v along with call stack into error log.
|
||||||
func ErrorStack(v ...any) {
|
func ErrorStack(v ...any) {
|
||||||
if shallLog(ErrorLevel) {
|
if shallLog(ErrorLevel) {
|
||||||
@@ -222,6 +237,14 @@ func Infof(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infofn writes function result into access log.
|
||||||
|
// This is useful when the function is expensive to call and info level disabled.
|
||||||
|
func Infofn(fn func() any) {
|
||||||
|
if shallLog(InfoLevel) {
|
||||||
|
writeInfo(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Infov writes v into access log with json content.
|
// Infov writes v into access log with json content.
|
||||||
func Infov(v any) {
|
func Infov(v any) {
|
||||||
if shallLog(InfoLevel) {
|
if shallLog(InfoLevel) {
|
||||||
@@ -348,6 +371,14 @@ func Slowf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Slowfn writes function result into slow log.
|
||||||
|
// This is useful when the function is expensive to call and slow level disabled.
|
||||||
|
func Slowfn(fn func() any) {
|
||||||
|
if shallLog(ErrorLevel) {
|
||||||
|
writeSlow(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Slowv writes v into slow log with json content.
|
// Slowv writes v into slow log with json content.
|
||||||
func Slowv(v any) {
|
func Slowv(v any) {
|
||||||
if shallLog(ErrorLevel) {
|
if shallLog(ErrorLevel) {
|
||||||
@@ -529,7 +560,7 @@ func shallLogStat() bool {
|
|||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
func writeDebug(val any, fields ...LogField) {
|
func writeDebug(val any, fields ...LogField) {
|
||||||
getWriter().Debug(val, addCaller(fields...)...)
|
getWriter().Debug(val, mergeGlobalFields(addCaller(fields...))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeError writes v into the error log.
|
// writeError writes v into the error log.
|
||||||
@@ -537,7 +568,7 @@ func writeDebug(val any, fields ...LogField) {
|
|||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
func writeError(val any, fields ...LogField) {
|
func writeError(val any, fields ...LogField) {
|
||||||
getWriter().Error(val, addCaller(fields...)...)
|
getWriter().Error(val, mergeGlobalFields(addCaller(fields...))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeInfo writes v into info log.
|
// writeInfo writes v into info log.
|
||||||
@@ -545,7 +576,7 @@ func writeError(val any, fields ...LogField) {
|
|||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
func writeInfo(val any, fields ...LogField) {
|
func writeInfo(val any, fields ...LogField) {
|
||||||
getWriter().Info(val, addCaller(fields...)...)
|
getWriter().Info(val, mergeGlobalFields(addCaller(fields...))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeSevere writes v into severe log.
|
// writeSevere writes v into severe log.
|
||||||
@@ -561,7 +592,7 @@ func writeSevere(msg string) {
|
|||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
func writeSlow(val any, fields ...LogField) {
|
func writeSlow(val any, fields ...LogField) {
|
||||||
getWriter().Slow(val, addCaller(fields...)...)
|
getWriter().Slow(val, mergeGlobalFields(addCaller(fields...))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeStack writes v into stack log.
|
// writeStack writes v into stack log.
|
||||||
@@ -577,5 +608,5 @@ func writeStack(msg string) {
|
|||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
func writeStat(msg string) {
|
func writeStat(msg string) {
|
||||||
getWriter().Stat(msg, addCaller()...)
|
getWriter().Stat(msg, mergeGlobalFields(addCaller())...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,6 +248,32 @@ func TestStructedLogDebugf(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructedLogDebugfn(t *testing.T) {
|
||||||
|
t.Run("debugfn with output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLog(t, levelDebug, w, func(v ...any) {
|
||||||
|
Debugfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("debugfn without output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLogEmpty(t, w, InfoLevel, func(v ...any) {
|
||||||
|
Debugfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructedLogDebugv(t *testing.T) {
|
func TestStructedLogDebugv(t *testing.T) {
|
||||||
w := new(mockWriter)
|
w := new(mockWriter)
|
||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
@@ -288,6 +314,32 @@ func TestStructedLogErrorf(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructedLogErrorfn(t *testing.T) {
|
||||||
|
t.Run("errorfn with output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLog(t, levelError, w, func(v ...any) {
|
||||||
|
Errorfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("errorfn without output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLogEmpty(t, w, SevereLevel, func(v ...any) {
|
||||||
|
Errorfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructedLogErrorv(t *testing.T) {
|
func TestStructedLogErrorv(t *testing.T) {
|
||||||
w := new(mockWriter)
|
w := new(mockWriter)
|
||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
@@ -328,6 +380,32 @@ func TestStructedLogInfof(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructedInfofn(t *testing.T) {
|
||||||
|
t.Run("infofn with output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLog(t, levelInfo, w, func(v ...any) {
|
||||||
|
Infofn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("infofn without output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLogEmpty(t, w, ErrorLevel, func(v ...any) {
|
||||||
|
Infofn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructedLogInfov(t *testing.T) {
|
func TestStructedLogInfov(t *testing.T) {
|
||||||
w := new(mockWriter)
|
w := new(mockWriter)
|
||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
@@ -451,6 +529,17 @@ func TestStructedLogInfoConsoleText(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInfofnWithErrorLevel(t *testing.T) {
|
||||||
|
called := false
|
||||||
|
SetLevel(ErrorLevel)
|
||||||
|
defer SetLevel(DebugLevel)
|
||||||
|
Infofn(func() any {
|
||||||
|
called = true
|
||||||
|
return "info log"
|
||||||
|
})
|
||||||
|
assert.False(t, called)
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructedLogSlow(t *testing.T) {
|
func TestStructedLogSlow(t *testing.T) {
|
||||||
w := new(mockWriter)
|
w := new(mockWriter)
|
||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
@@ -471,6 +560,32 @@ func TestStructedLogSlowf(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructedLogSlowfn(t *testing.T) {
|
||||||
|
t.Run("slowfn with output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLog(t, levelSlow, w, func(v ...any) {
|
||||||
|
Slowfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slowfn without output", func(t *testing.T) {
|
||||||
|
w := new(mockWriter)
|
||||||
|
old := writer.Swap(w)
|
||||||
|
defer writer.Store(old)
|
||||||
|
|
||||||
|
doTestStructedLogEmpty(t, w, SevereLevel, func(v ...any) {
|
||||||
|
Slowfn(func() any {
|
||||||
|
return fmt.Sprint(v...)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructedLogSlowv(t *testing.T) {
|
func TestStructedLogSlowv(t *testing.T) {
|
||||||
w := new(mockWriter)
|
w := new(mockWriter)
|
||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
@@ -847,6 +962,16 @@ func doTestStructedLogConsole(t *testing.T, w *mockWriter, write func(...any)) {
|
|||||||
assert.True(t, strings.Contains(w.String(), message))
|
assert.True(t, strings.Contains(w.String(), message))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doTestStructedLogEmpty(t *testing.T, w *mockWriter, level uint32, write func(...any)) {
|
||||||
|
olevel := atomic.LoadUint32(&logLevel)
|
||||||
|
SetLevel(level)
|
||||||
|
defer SetLevel(olevel)
|
||||||
|
|
||||||
|
const message = "hello there"
|
||||||
|
write(message)
|
||||||
|
assert.Empty(t, w.String())
|
||||||
|
}
|
||||||
|
|
||||||
func testSetLevelTwiceWithMode(t *testing.T, mode string, w *mockWriter) {
|
func testSetLevelTwiceWithMode(t *testing.T, mode string, w *mockWriter) {
|
||||||
writer.Store(nil)
|
writer.Store(nil)
|
||||||
SetUp(LogConf{
|
SetUp(LogConf{
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ func (l *richLogger) Debugf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *richLogger) Debugfn(fn func() any) {
|
||||||
|
if shallLog(DebugLevel) {
|
||||||
|
l.debug(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *richLogger) Debugv(v any) {
|
func (l *richLogger) Debugv(v any) {
|
||||||
if shallLog(DebugLevel) {
|
if shallLog(DebugLevel) {
|
||||||
l.debug(v)
|
l.debug(v)
|
||||||
@@ -76,6 +82,12 @@ func (l *richLogger) Errorf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *richLogger) Errorfn(fn func() any) {
|
||||||
|
if shallLog(ErrorLevel) {
|
||||||
|
l.err(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *richLogger) Errorv(v any) {
|
func (l *richLogger) Errorv(v any) {
|
||||||
if shallLog(ErrorLevel) {
|
if shallLog(ErrorLevel) {
|
||||||
l.err(v)
|
l.err(v)
|
||||||
@@ -100,6 +112,12 @@ func (l *richLogger) Infof(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *richLogger) Infofn(fn func() any) {
|
||||||
|
if shallLog(InfoLevel) {
|
||||||
|
l.info(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *richLogger) Infov(v any) {
|
func (l *richLogger) Infov(v any) {
|
||||||
if shallLog(InfoLevel) {
|
if shallLog(InfoLevel) {
|
||||||
l.info(v)
|
l.info(v)
|
||||||
@@ -124,6 +142,12 @@ func (l *richLogger) Slowf(format string, v ...any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *richLogger) Slowfn(fn func() any) {
|
||||||
|
if shallLog(ErrorLevel) {
|
||||||
|
l.slow(fn())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (l *richLogger) Slowv(v any) {
|
func (l *richLogger) Slowv(v any) {
|
||||||
if shallLog(ErrorLevel) {
|
if shallLog(ErrorLevel) {
|
||||||
l.slow(v)
|
l.slow(v)
|
||||||
@@ -182,7 +206,9 @@ func (l *richLogger) WithFields(fields ...LogField) Logger {
|
|||||||
|
|
||||||
func (l *richLogger) buildFields(fields ...LogField) []LogField {
|
func (l *richLogger) buildFields(fields ...LogField) []LogField {
|
||||||
fields = append(l.fields, fields...)
|
fields = append(l.fields, fields...)
|
||||||
|
// caller field should always appear together with global fields
|
||||||
fields = append(fields, Field(callerKey, getCaller(callerDepth+l.callerSkip)))
|
fields = append(fields, Field(callerKey, getCaller(callerDepth+l.callerSkip)))
|
||||||
|
fields = mergeGlobalFields(fields)
|
||||||
|
|
||||||
if l.ctx == nil {
|
if l.ctx == nil {
|
||||||
return fields
|
return fields
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ func TestTraceDebug(t *testing.T) {
|
|||||||
l.WithDuration(time.Second).Debugf(testlog)
|
l.WithDuration(time.Second).Debugf(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
|
l.WithDuration(time.Second).Debugfn(func() any {
|
||||||
|
return testlog
|
||||||
|
})
|
||||||
|
validate(t, w.String(), true, true)
|
||||||
|
w.Reset()
|
||||||
l.WithDuration(time.Second).Debugv(testlog)
|
l.WithDuration(time.Second).Debugv(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
@@ -103,6 +108,11 @@ func TestTraceError(t *testing.T) {
|
|||||||
l.WithDuration(time.Second).Errorf(testlog)
|
l.WithDuration(time.Second).Errorf(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
|
l.WithDuration(time.Second).Errorfn(func() any {
|
||||||
|
return testlog
|
||||||
|
})
|
||||||
|
validate(t, w.String(), true, true)
|
||||||
|
w.Reset()
|
||||||
l.WithDuration(time.Second).Errorv(testlog)
|
l.WithDuration(time.Second).Errorv(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
@@ -140,6 +150,11 @@ func TestTraceInfo(t *testing.T) {
|
|||||||
l.WithDuration(time.Second).Infof(testlog)
|
l.WithDuration(time.Second).Infof(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
|
l.WithDuration(time.Second).Infofn(func() any {
|
||||||
|
return testlog
|
||||||
|
})
|
||||||
|
validate(t, w.String(), true, true)
|
||||||
|
w.Reset()
|
||||||
l.WithDuration(time.Second).Infov(testlog)
|
l.WithDuration(time.Second).Infov(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
@@ -213,6 +228,11 @@ func TestTraceSlow(t *testing.T) {
|
|||||||
l.WithDuration(time.Second).Slowf(testlog)
|
l.WithDuration(time.Second).Slowf(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
|
l.WithDuration(time.Second).Slowfn(func() any {
|
||||||
|
return testlog
|
||||||
|
})
|
||||||
|
validate(t, w.String(), true, true)
|
||||||
|
w.Reset()
|
||||||
l.WithDuration(time.Second).Slowv(testlog)
|
l.WithDuration(time.Second).Slowv(testlog)
|
||||||
validate(t, w.String(), true, true)
|
validate(t, w.String(), true, true)
|
||||||
w.Reset()
|
w.Reset()
|
||||||
|
|||||||
@@ -17,15 +17,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Writer is the interface for writing logs.
|
||||||
|
// It's designed to let users customize their own log writer,
|
||||||
|
// such as writing logs to a kafka, a database, or using third-party loggers.
|
||||||
Writer interface {
|
Writer interface {
|
||||||
|
// Alert sends an alert message, if your writer implemented alerting functionality.
|
||||||
Alert(v any)
|
Alert(v any)
|
||||||
|
// Close closes the writer.
|
||||||
Close() error
|
Close() error
|
||||||
|
// Debug logs a message at debug level.
|
||||||
Debug(v any, fields ...LogField)
|
Debug(v any, fields ...LogField)
|
||||||
|
// Error logs a message at error level.
|
||||||
Error(v any, fields ...LogField)
|
Error(v any, fields ...LogField)
|
||||||
|
// Info logs a message at info level.
|
||||||
Info(v any, fields ...LogField)
|
Info(v any, fields ...LogField)
|
||||||
|
// Severe logs a message at severe level.
|
||||||
Severe(v any)
|
Severe(v any)
|
||||||
|
// Slow logs a message at slow level.
|
||||||
Slow(v any, fields ...LogField)
|
Slow(v any, fields ...LogField)
|
||||||
|
// Stack logs a message at error level.
|
||||||
Stack(v any)
|
Stack(v any)
|
||||||
|
// Stat logs a message at stat level.
|
||||||
Stat(v any, fields ...LogField)
|
Stat(v any, fields ...LogField)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,20 +336,6 @@ func buildPlainFields(fields logEntry) []string {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func combineGlobalFields(fields []LogField) []LogField {
|
|
||||||
globals := globalFields.Load()
|
|
||||||
if globals == nil {
|
|
||||||
return fields
|
|
||||||
}
|
|
||||||
|
|
||||||
gf := globals.([]LogField)
|
|
||||||
ret := make([]LogField, 0, len(gf)+len(fields))
|
|
||||||
ret = append(ret, gf...)
|
|
||||||
ret = append(ret, fields...)
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalJson(t interface{}) ([]byte, error) {
|
func marshalJson(t interface{}) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
encoder := json.NewEncoder(&buf)
|
encoder := json.NewEncoder(&buf)
|
||||||
@@ -352,6 +350,20 @@ func marshalJson(t interface{}) ([]byte, error) {
|
|||||||
return buf.Bytes(), err
|
return buf.Bytes(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mergeGlobalFields(fields []LogField) []LogField {
|
||||||
|
globals := globalFields.Load()
|
||||||
|
if globals == nil {
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
gf := globals.([]LogField)
|
||||||
|
ret := make([]LogField, 0, len(gf)+len(fields))
|
||||||
|
ret = append(ret, gf...)
|
||||||
|
ret = append(ret, fields...)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func output(writer io.Writer, level string, val any, fields ...LogField) {
|
func output(writer io.Writer, level string, val any, fields ...LogField) {
|
||||||
// only truncate string content, don't know how to truncate the values of other types.
|
// only truncate string content, don't know how to truncate the values of other types.
|
||||||
if v, ok := val.(string); ok {
|
if v, ok := val.(string); ok {
|
||||||
@@ -362,7 +374,6 @@ func output(writer io.Writer, level string, val any, fields ...LogField) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fields = combineGlobalFields(fields)
|
|
||||||
// +3 for timestamp, level and content
|
// +3 for timestamp, level and content
|
||||||
entry := make(logEntry, len(fields)+3)
|
entry := make(logEntry, len(fields)+3)
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mapping
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding"
|
"encoding"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -80,40 +81,11 @@ func (u *Unmarshaler) Unmarshal(i, v any) error {
|
|||||||
return u.unmarshal(i, v, "")
|
return u.unmarshal(i, v, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshal(i, v any, fullName string) error {
|
|
||||||
valueType := reflect.TypeOf(v)
|
|
||||||
if valueType.Kind() != reflect.Ptr {
|
|
||||||
return errValueNotSettable
|
|
||||||
}
|
|
||||||
|
|
||||||
elemType := Deref(valueType)
|
|
||||||
switch iv := i.(type) {
|
|
||||||
case map[string]any:
|
|
||||||
if elemType.Kind() != reflect.Struct {
|
|
||||||
return errTypeMismatch
|
|
||||||
}
|
|
||||||
|
|
||||||
return u.unmarshalValuer(mapValuer(iv), v, fullName)
|
|
||||||
case []any:
|
|
||||||
if elemType.Kind() != reflect.Slice {
|
|
||||||
return errTypeMismatch
|
|
||||||
}
|
|
||||||
|
|
||||||
return u.fillSlice(elemType, reflect.ValueOf(v).Elem(), iv, fullName)
|
|
||||||
default:
|
|
||||||
return errUnsupportedType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalValuer unmarshals m into v.
|
// UnmarshalValuer unmarshals m into v.
|
||||||
func (u *Unmarshaler) UnmarshalValuer(m Valuer, v any) error {
|
func (u *Unmarshaler) UnmarshalValuer(m Valuer, v any) error {
|
||||||
return u.unmarshalValuer(simpleValuer{current: m}, v, "")
|
return u.unmarshalValuer(simpleValuer{current: m}, v, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshalValuer(m Valuer, v any, fullName string) error {
|
|
||||||
return u.unmarshalWithFullName(simpleValuer{current: m}, v, fullName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *Unmarshaler) fillMap(fieldType reflect.Type, value reflect.Value,
|
func (u *Unmarshaler) fillMap(fieldType reflect.Type, value reflect.Value,
|
||||||
mapValue any, fullName string) error {
|
mapValue any, fullName string) error {
|
||||||
if !value.CanSet() {
|
if !value.CanSet() {
|
||||||
@@ -173,13 +145,14 @@ func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value,
|
|||||||
baseType := fieldType.Elem()
|
baseType := fieldType.Elem()
|
||||||
dereffedBaseType := Deref(baseType)
|
dereffedBaseType := Deref(baseType)
|
||||||
dereffedBaseKind := dereffedBaseType.Kind()
|
dereffedBaseKind := dereffedBaseType.Kind()
|
||||||
conv := reflect.MakeSlice(reflect.SliceOf(baseType), refValue.Len(), refValue.Cap())
|
|
||||||
if refValue.Len() == 0 {
|
if refValue.Len() == 0 {
|
||||||
value.Set(conv)
|
value.Set(reflect.MakeSlice(reflect.SliceOf(baseType), 0, 0))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var valid bool
|
var valid bool
|
||||||
|
conv := reflect.MakeSlice(reflect.SliceOf(baseType), refValue.Len(), refValue.Cap())
|
||||||
|
|
||||||
for i := 0; i < refValue.Len(); i++ {
|
for i := 0; i < refValue.Len(); i++ {
|
||||||
ithValue := refValue.Index(i).Interface()
|
ithValue := refValue.Index(i).Interface()
|
||||||
if ithValue == nil {
|
if ithValue == nil {
|
||||||
@@ -191,17 +164,9 @@ func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value,
|
|||||||
|
|
||||||
switch dereffedBaseKind {
|
switch dereffedBaseKind {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
target := reflect.New(dereffedBaseType)
|
if err := u.fillStructElement(baseType, conv.Index(i), ithValue, sliceFullName); err != nil {
|
||||||
val, ok := ithValue.(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return errTypeMismatch
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := u.unmarshal(val, target.Interface(), sliceFullName); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
SetValue(fieldType.Elem(), conv.Index(i), target.Elem())
|
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if err := u.fillSlice(dereffedBaseType, conv.Index(i), ithValue, sliceFullName); err != nil {
|
if err := u.fillSlice(dereffedBaseType, conv.Index(i), ithValue, sliceFullName); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -236,7 +201,7 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
|||||||
return errUnsupportedType
|
return errUnsupportedType
|
||||||
}
|
}
|
||||||
|
|
||||||
baseFieldType := Deref(fieldType.Elem())
|
baseFieldType := fieldType.Elem()
|
||||||
baseFieldKind := baseFieldType.Kind()
|
baseFieldKind := baseFieldType.Kind()
|
||||||
conv := reflect.MakeSlice(reflect.SliceOf(baseFieldType), len(slice), cap(slice))
|
conv := reflect.MakeSlice(reflect.SliceOf(baseFieldType), len(slice), cap(slice))
|
||||||
|
|
||||||
@@ -257,29 +222,39 @@ func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ithVal := slice.Index(index)
|
ithVal := slice.Index(index)
|
||||||
|
ithValType := ithVal.Type()
|
||||||
|
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case fmt.Stringer:
|
case fmt.Stringer:
|
||||||
return setValueFromString(baseKind, ithVal, v.String())
|
return setValueFromString(baseKind, ithVal, v.String())
|
||||||
case string:
|
case string:
|
||||||
return setValueFromString(baseKind, ithVal, v)
|
return setValueFromString(baseKind, ithVal, v)
|
||||||
case map[string]any:
|
case map[string]any:
|
||||||
return u.fillMap(ithVal.Type(), ithVal, value, fullName)
|
// deref to handle both pointer and non-pointer types.
|
||||||
|
switch Deref(ithValType).Kind() {
|
||||||
|
case reflect.Struct:
|
||||||
|
return u.fillStructElement(ithValType, ithVal, v, fullName)
|
||||||
|
case reflect.Map:
|
||||||
|
return u.fillMap(ithValType, ithVal, value, fullName)
|
||||||
|
default:
|
||||||
|
return errTypeMismatch
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// don't need to consider the difference between int, int8, int16, int32, int64,
|
// don't need to consider the difference between int, int8, int16, int32, int64,
|
||||||
// uint, uint8, uint16, uint32, uint64, because they're handled as json.Number.
|
// uint, uint8, uint16, uint32, uint64, because they're handled as json.Number.
|
||||||
if ithVal.Kind() == reflect.Ptr {
|
if ithVal.Kind() == reflect.Ptr {
|
||||||
baseType := Deref(ithVal.Type())
|
baseType := Deref(ithValType)
|
||||||
if !reflect.TypeOf(value).AssignableTo(baseType) {
|
if !reflect.TypeOf(value).AssignableTo(baseType) {
|
||||||
return errTypeMismatch
|
return errTypeMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
target := reflect.New(baseType).Elem()
|
target := reflect.New(baseType).Elem()
|
||||||
target.Set(reflect.ValueOf(value))
|
target.Set(reflect.ValueOf(value))
|
||||||
SetValue(ithVal.Type(), ithVal, target)
|
SetValue(ithValType, ithVal, target)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.TypeOf(value).AssignableTo(ithVal.Type()) {
|
if !reflect.TypeOf(value).AssignableTo(ithValType) {
|
||||||
return errTypeMismatch
|
return errTypeMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,6 +285,23 @@ func (u *Unmarshaler) fillSliceWithDefault(derefedType reflect.Type, value refle
|
|||||||
return u.fillSlice(derefedType, value, slice, fullName)
|
return u.fillSlice(derefedType, value, slice, fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Unmarshaler) fillStructElement(baseType reflect.Type, target reflect.Value,
|
||||||
|
value any, fullName string) error {
|
||||||
|
val, ok := value.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
return errTypeMismatch
|
||||||
|
}
|
||||||
|
|
||||||
|
// use Deref(baseType) to get the base type in case the type is a pointer type.
|
||||||
|
ptr := reflect.New(Deref(baseType))
|
||||||
|
if err := u.unmarshal(val, ptr.Interface(), fullName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
SetValue(baseType, target, ptr.Elem())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (u *Unmarshaler) fillUnmarshalerStruct(fieldType reflect.Type,
|
func (u *Unmarshaler) fillUnmarshalerStruct(fieldType reflect.Type,
|
||||||
value reflect.Value, targetValue string) error {
|
value reflect.Value, targetValue string) error {
|
||||||
if !value.CanSet() {
|
if !value.CanSet() {
|
||||||
@@ -612,6 +604,22 @@ func (u *Unmarshaler) processFieldNotFromString(fieldType reflect.Type, value re
|
|||||||
case valueKind == reflect.String && typeKind == reflect.Map:
|
case valueKind == reflect.String && typeKind == reflect.Map:
|
||||||
return u.fillMapFromString(value, mapValue)
|
return u.fillMapFromString(value, mapValue)
|
||||||
case valueKind == reflect.String && typeKind == reflect.Slice:
|
case valueKind == reflect.String && typeKind == reflect.Slice:
|
||||||
|
// try to find out if it's a byte slice,
|
||||||
|
// more details https://pkg.go.dev/encoding/json#Marshal
|
||||||
|
// array and slice values encode as JSON arrays,
|
||||||
|
// except that []byte encodes as a base64-encoded string,
|
||||||
|
// and a nil slice encoded as the null JSON value.
|
||||||
|
// https://stackoverflow.com/questions/34089750/marshal-byte-to-json-giving-a-strange-string
|
||||||
|
if fieldType.Elem().Kind() == reflect.Uint8 {
|
||||||
|
// check whether string type, because the kind of some other types can be string
|
||||||
|
if strVal, ok := mapValue.(string); ok {
|
||||||
|
if decodedBytes, err := base64.StdEncoding.DecodeString(strVal); err == nil {
|
||||||
|
value.Set(reflect.ValueOf(decodedBytes))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return u.fillSliceFromString(fieldType, value, mapValue, fullName)
|
return u.fillSliceFromString(fieldType, value, mapValue, fullName)
|
||||||
case valueKind == reflect.String && derefedFieldType == durationType:
|
case valueKind == reflect.String && derefedFieldType == durationType:
|
||||||
return fillDurationValue(fieldType, value, mapValue.(string))
|
return fillDurationValue(fieldType, value, mapValue.(string))
|
||||||
@@ -952,6 +960,35 @@ func (u *Unmarshaler) processNamedFieldWithoutValue(fieldType reflect.Type, valu
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Unmarshaler) unmarshal(i, v any, fullName string) error {
|
||||||
|
valueType := reflect.TypeOf(v)
|
||||||
|
if valueType.Kind() != reflect.Ptr {
|
||||||
|
return errValueNotSettable
|
||||||
|
}
|
||||||
|
|
||||||
|
elemType := Deref(valueType)
|
||||||
|
switch iv := i.(type) {
|
||||||
|
case map[string]any:
|
||||||
|
if elemType.Kind() != reflect.Struct {
|
||||||
|
return errTypeMismatch
|
||||||
|
}
|
||||||
|
|
||||||
|
return u.unmarshalValuer(mapValuer(iv), v, fullName)
|
||||||
|
case []any:
|
||||||
|
if elemType.Kind() != reflect.Slice {
|
||||||
|
return errTypeMismatch
|
||||||
|
}
|
||||||
|
|
||||||
|
return u.fillSlice(elemType, reflect.ValueOf(v).Elem(), iv, fullName)
|
||||||
|
default:
|
||||||
|
return errUnsupportedType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *Unmarshaler) unmarshalValuer(m Valuer, v any, fullName string) error {
|
||||||
|
return u.unmarshalWithFullName(simpleValuer{current: m}, v, fullName)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *Unmarshaler) unmarshalWithFullName(m valuerWithParent, v any, fullName string) error {
|
func (u *Unmarshaler) unmarshalWithFullName(m valuerWithParent, v any, fullName string) error {
|
||||||
rv := reflect.ValueOf(v)
|
rv := reflect.ValueOf(v)
|
||||||
if err := ValidatePtr(rv); err != nil {
|
if err := ValidatePtr(rv); err != nil {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/zeromicro/go-zero/core/jsonx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -351,7 +352,7 @@ func TestUnmarshalIntSliceOfPtr(t *testing.T) {
|
|||||||
assert.Error(t, UnmarshalKey(m, &in))
|
assert.Error(t, UnmarshalKey(m, &in))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("int slice with nil", func(t *testing.T) {
|
t.Run("int slice with nil element", func(t *testing.T) {
|
||||||
type inner struct {
|
type inner struct {
|
||||||
Ints []int `key:"ints"`
|
Ints []int `key:"ints"`
|
||||||
}
|
}
|
||||||
@@ -365,6 +366,21 @@ func TestUnmarshalIntSliceOfPtr(t *testing.T) {
|
|||||||
assert.Empty(t, in.Ints)
|
assert.Empty(t, in.Ints)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("int slice with nil", func(t *testing.T) {
|
||||||
|
type inner struct {
|
||||||
|
Ints []int `key:"ints"`
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[string]any{
|
||||||
|
"ints": []any(nil),
|
||||||
|
}
|
||||||
|
|
||||||
|
var in inner
|
||||||
|
if assert.NoError(t, UnmarshalKey(m, &in)) {
|
||||||
|
assert.Empty(t, in.Ints)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalIntWithDefault(t *testing.T) {
|
func TestUnmarshalIntWithDefault(t *testing.T) {
|
||||||
@@ -1374,20 +1390,80 @@ func TestUnmarshalWithFloatPtr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalIntSlice(t *testing.T) {
|
func TestUnmarshalIntSlice(t *testing.T) {
|
||||||
var v struct {
|
t.Run("int slice from int", func(t *testing.T) {
|
||||||
Ages []int `key:"ages"`
|
var v struct {
|
||||||
Slice []int `key:"slice"`
|
Ages []int `key:"ages"`
|
||||||
}
|
Slice []int `key:"slice"`
|
||||||
m := map[string]any{
|
}
|
||||||
"ages": []int{1, 2},
|
m := map[string]any{
|
||||||
"slice": []any{},
|
"ages": []int{1, 2},
|
||||||
}
|
"slice": []any{},
|
||||||
|
}
|
||||||
|
|
||||||
ast := assert.New(t)
|
ast := assert.New(t)
|
||||||
if ast.NoError(UnmarshalKey(m, &v)) {
|
if ast.NoError(UnmarshalKey(m, &v)) {
|
||||||
ast.ElementsMatch([]int{1, 2}, v.Ages)
|
ast.ElementsMatch([]int{1, 2}, v.Ages)
|
||||||
ast.Equal([]int{}, v.Slice)
|
ast.Equal([]int{}, v.Slice)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("int slice from one int", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Ages []int `key:"ages"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"ages": []int{2},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]int{2}, v.Ages)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("int slice from one int string", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Ages []int `key:"ages"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"ages": []string{"2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]int{2}, v.Ages)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("int slice from one json.Number", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Ages []int `key:"ages"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"ages": []json.Number{"2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]int{2}, v.Ages)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("int slice from one int strings", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Ages []int `key:"ages"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"ages": []string{"1,2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
ast.Error(unmarshaler.Unmarshal(m, &v))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalString(t *testing.T) {
|
func TestUnmarshalString(t *testing.T) {
|
||||||
@@ -1442,6 +1518,51 @@ func TestUnmarshalStringSliceFromString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("slice from empty string", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `key:"names"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"names": []string{""},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]string{""}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice from empty and valid string", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `key:"names"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"names": []string{","},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]string{","}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice from valid strings with comma", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `key:"names"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"names": []string{"aa,bb"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
unmarshaler := NewUnmarshaler(defaultKeyName, WithFromArray())
|
||||||
|
if ast.NoError(unmarshaler.Unmarshal(m, &v)) {
|
||||||
|
ast.ElementsMatch([]string{"aa,bb"}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("slice from string with slice error", func(t *testing.T) {
|
t.Run("slice from string with slice error", func(t *testing.T) {
|
||||||
var v struct {
|
var v struct {
|
||||||
Names []int `key:"names"`
|
Names []int `key:"names"`
|
||||||
@@ -4761,14 +4882,28 @@ func TestUnmarshal_EnvWithOptionsWrongValueString(t *testing.T) {
|
|||||||
|
|
||||||
func TestUnmarshalJsonReaderMultiArray(t *testing.T) {
|
func TestUnmarshalJsonReaderMultiArray(t *testing.T) {
|
||||||
t.Run("reader multi array", func(t *testing.T) {
|
t.Run("reader multi array", func(t *testing.T) {
|
||||||
var res struct {
|
type testRes struct {
|
||||||
A string `json:"a"`
|
A string `json:"a"`
|
||||||
B [][]string `json:"b"`
|
B [][]string `json:"b"`
|
||||||
|
C []byte `json:"c"`
|
||||||
}
|
}
|
||||||
payload := `{"a": "133", "b": [["add", "cccd"], ["eeee"]]}`
|
|
||||||
|
var res testRes
|
||||||
|
marshal := testRes{
|
||||||
|
A: "133",
|
||||||
|
B: [][]string{
|
||||||
|
{"add", "cccd"},
|
||||||
|
{"eeee"},
|
||||||
|
},
|
||||||
|
C: []byte("11122344wsss"),
|
||||||
|
}
|
||||||
|
bytes, err := jsonx.Marshal(marshal)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
payload := string(bytes)
|
||||||
reader := strings.NewReader(payload)
|
reader := strings.NewReader(payload)
|
||||||
if assert.NoError(t, UnmarshalJsonReader(reader, &res)) {
|
if assert.NoError(t, UnmarshalJsonReader(reader, &res)) {
|
||||||
assert.Equal(t, 2, len(res.B))
|
assert.Equal(t, 2, len(res.B))
|
||||||
|
assert.Equal(t, string(marshal.C), string(res.C))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -5862,6 +5997,38 @@ func TestUnmarshal_Unmarshaler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseJsonStringValue(t *testing.T) {
|
||||||
|
t.Run("string", func(t *testing.T) {
|
||||||
|
type GoodsInfo struct {
|
||||||
|
Sku int64 `json:"sku,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetReq struct {
|
||||||
|
GoodsList []*GoodsInfo `json:"goods_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
input := map[string]any{"goods_list": "[{\"sku\":11},{\"sku\":22}]"}
|
||||||
|
var v GetReq
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
assert.NoError(t, UnmarshalJsonMap(input, &v))
|
||||||
|
assert.Equal(t, 2, len(v.GoodsList))
|
||||||
|
assert.ElementsMatch(t, []int64{11, 22}, []int64{v.GoodsList[0].Sku, v.GoodsList[1].Sku})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("string with invalid type", func(t *testing.T) {
|
||||||
|
type GetReq struct {
|
||||||
|
GoodsList []*int `json:"goods_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
input := map[string]any{"goods_list": "[{\"sku\":11},{\"sku\":22}]"}
|
||||||
|
var v GetReq
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
assert.Error(t, UnmarshalJsonMap(input, &v))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkDefaultValue(b *testing.B) {
|
func BenchmarkDefaultValue(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
var a struct {
|
var a struct {
|
||||||
|
|||||||
@@ -142,89 +142,6 @@ func MapReduceChan[T, U, V any](source <-chan T, mapper MapperFunc[T, U], reduce
|
|||||||
return mapReduceWithPanicChan(source, panicChan, mapper, reducer, opts...)
|
return mapReduceWithPanicChan(source, panicChan, mapper, reducer, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapReduceWithPanicChan maps all elements from source, and reduce the output elements with given reducer.
|
|
||||||
func mapReduceWithPanicChan[T, U, V any](source <-chan T, panicChan *onceChan, mapper MapperFunc[T, U],
|
|
||||||
reducer ReducerFunc[U, V], opts ...Option) (val V, err error) {
|
|
||||||
options := buildOptions(opts...)
|
|
||||||
// output is used to write the final result
|
|
||||||
output := make(chan V)
|
|
||||||
defer func() {
|
|
||||||
// reducer can only write once, if more, panic
|
|
||||||
for range output {
|
|
||||||
panic("more than one element written in reducer")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// collector is used to collect data from mapper, and consume in reducer
|
|
||||||
collector := make(chan U, options.workers)
|
|
||||||
// if done is closed, all mappers and reducer should stop processing
|
|
||||||
done := make(chan struct{})
|
|
||||||
writer := newGuardedWriter(options.ctx, output, done)
|
|
||||||
var closeOnce sync.Once
|
|
||||||
// use atomic type to avoid data race
|
|
||||||
var retErr errorx.AtomicError
|
|
||||||
finish := func() {
|
|
||||||
closeOnce.Do(func() {
|
|
||||||
close(done)
|
|
||||||
close(output)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
cancel := once(func(err error) {
|
|
||||||
if err != nil {
|
|
||||||
retErr.Set(err)
|
|
||||||
} else {
|
|
||||||
retErr.Set(ErrCancelWithNil)
|
|
||||||
}
|
|
||||||
|
|
||||||
drain(source)
|
|
||||||
finish()
|
|
||||||
})
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
drain(collector)
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
panicChan.write(r)
|
|
||||||
}
|
|
||||||
finish()
|
|
||||||
}()
|
|
||||||
|
|
||||||
reducer(collector, writer, cancel)
|
|
||||||
}()
|
|
||||||
|
|
||||||
go executeMappers(mapperContext[T, U]{
|
|
||||||
ctx: options.ctx,
|
|
||||||
mapper: func(item T, w Writer[U]) {
|
|
||||||
mapper(item, w, cancel)
|
|
||||||
},
|
|
||||||
source: source,
|
|
||||||
panicChan: panicChan,
|
|
||||||
collector: collector,
|
|
||||||
doneChan: done,
|
|
||||||
workers: options.workers,
|
|
||||||
})
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-options.ctx.Done():
|
|
||||||
cancel(context.DeadlineExceeded)
|
|
||||||
err = context.DeadlineExceeded
|
|
||||||
case v := <-panicChan.channel:
|
|
||||||
// drain output here, otherwise for loop panic in defer
|
|
||||||
drain(output)
|
|
||||||
panic(v)
|
|
||||||
case v, ok := <-output:
|
|
||||||
if e := retErr.Load(); e != nil {
|
|
||||||
err = e
|
|
||||||
} else if ok {
|
|
||||||
val = v
|
|
||||||
} else {
|
|
||||||
err = ErrReduceNoOutput
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// MapReduceVoid maps all elements generated from given generate,
|
// MapReduceVoid maps all elements generated from given generate,
|
||||||
// and reduce the output elements with given reducer.
|
// and reduce the output elements with given reducer.
|
||||||
func MapReduceVoid[T, U any](generate GenerateFunc[T], mapper MapperFunc[T, U],
|
func MapReduceVoid[T, U any](generate GenerateFunc[T], mapper MapperFunc[T, U],
|
||||||
@@ -330,6 +247,89 @@ func executeMappers[T, U any](mCtx mapperContext[T, U]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mapReduceWithPanicChan maps all elements from source, and reduce the output elements with given reducer.
|
||||||
|
func mapReduceWithPanicChan[T, U, V any](source <-chan T, panicChan *onceChan, mapper MapperFunc[T, U],
|
||||||
|
reducer ReducerFunc[U, V], opts ...Option) (val V, err error) {
|
||||||
|
options := buildOptions(opts...)
|
||||||
|
// output is used to write the final result
|
||||||
|
output := make(chan V)
|
||||||
|
defer func() {
|
||||||
|
// reducer can only write once, if more, panic
|
||||||
|
for range output {
|
||||||
|
panic("more than one element written in reducer")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// collector is used to collect data from mapper, and consume in reducer
|
||||||
|
collector := make(chan U, options.workers)
|
||||||
|
// if done is closed, all mappers and reducer should stop processing
|
||||||
|
done := make(chan struct{})
|
||||||
|
writer := newGuardedWriter(options.ctx, output, done)
|
||||||
|
var closeOnce sync.Once
|
||||||
|
// use atomic type to avoid data race
|
||||||
|
var retErr errorx.AtomicError
|
||||||
|
finish := func() {
|
||||||
|
closeOnce.Do(func() {
|
||||||
|
close(done)
|
||||||
|
close(output)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
cancel := once(func(err error) {
|
||||||
|
if err != nil {
|
||||||
|
retErr.Set(err)
|
||||||
|
} else {
|
||||||
|
retErr.Set(ErrCancelWithNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
drain(source)
|
||||||
|
finish()
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
drain(collector)
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
panicChan.write(r)
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}()
|
||||||
|
|
||||||
|
reducer(collector, writer, cancel)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go executeMappers(mapperContext[T, U]{
|
||||||
|
ctx: options.ctx,
|
||||||
|
mapper: func(item T, w Writer[U]) {
|
||||||
|
mapper(item, w, cancel)
|
||||||
|
},
|
||||||
|
source: source,
|
||||||
|
panicChan: panicChan,
|
||||||
|
collector: collector,
|
||||||
|
doneChan: done,
|
||||||
|
workers: options.workers,
|
||||||
|
})
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-options.ctx.Done():
|
||||||
|
cancel(context.DeadlineExceeded)
|
||||||
|
err = context.DeadlineExceeded
|
||||||
|
case v := <-panicChan.channel:
|
||||||
|
// drain output here, otherwise for loop panic in defer
|
||||||
|
drain(output)
|
||||||
|
panic(v)
|
||||||
|
case v, ok := <-output:
|
||||||
|
if e := retErr.Load(); e != nil {
|
||||||
|
err = e
|
||||||
|
} else if ok {
|
||||||
|
val = v
|
||||||
|
} else {
|
||||||
|
err = ErrReduceNoOutput
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func newOptions() *mapReduceOptions {
|
func newOptions() *mapReduceOptions {
|
||||||
return &mapReduceOptions{
|
return &mapReduceOptions{
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ package proc
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// ShutdownConf is empty on windows.
|
||||||
|
type ShutdownConf struct{}
|
||||||
|
|
||||||
// AddShutdownListener returns fn itself on windows, lets callers call fn on their own.
|
// AddShutdownListener returns fn itself on windows, lets callers call fn on their own.
|
||||||
func AddShutdownListener(fn func()) func() {
|
func AddShutdownListener(fn func()) func() {
|
||||||
return fn
|
return fn
|
||||||
@@ -18,6 +21,10 @@ func AddWrapUpListener(fn func()) func() {
|
|||||||
func SetTimeToForceQuit(duration time.Duration) {
|
func SetTimeToForceQuit(duration time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup does nothing on windows.
|
||||||
|
func Setup(conf ShutdownConf) {
|
||||||
|
}
|
||||||
|
|
||||||
// Shutdown does nothing on windows.
|
// Shutdown does nothing on windows.
|
||||||
func Shutdown() {
|
func Shutdown() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
@@ -14,17 +14,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
wrapUpTime = time.Second
|
// defaultWrapUpTime is the default time to wait before calling wrap up listeners.
|
||||||
// why we use 5500 milliseconds is because most of our queue are blocking mode with 5 seconds
|
defaultWrapUpTime = time.Second
|
||||||
waitTime = 5500 * time.Millisecond
|
// defaultWaitTime is the default time to wait before force quitting.
|
||||||
|
// why we use 5500 milliseconds is because most of our queues are blocking mode with 5 seconds
|
||||||
|
defaultWaitTime = 5500 * time.Millisecond
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wrapUpListeners = new(listenerManager)
|
wrapUpListeners = new(listenerManager)
|
||||||
shutdownListeners = new(listenerManager)
|
shutdownListeners = new(listenerManager)
|
||||||
delayTimeBeforeForceQuit = waitTime
|
wrapUpTime = defaultWrapUpTime
|
||||||
|
waitTime = defaultWaitTime
|
||||||
|
shutdownLock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ShutdownConf defines the shutdown configuration for the process.
|
||||||
|
type ShutdownConf struct {
|
||||||
|
// WrapUpTime is the time to wait before calling shutdown listeners.
|
||||||
|
WrapUpTime time.Duration `json:",default=1s"`
|
||||||
|
// WaitTime is the time to wait before force quitting.
|
||||||
|
WaitTime time.Duration `json:",default=5.5s"`
|
||||||
|
}
|
||||||
|
|
||||||
// AddShutdownListener adds fn as a shutdown listener.
|
// AddShutdownListener adds fn as a shutdown listener.
|
||||||
// The returned func can be used to wait for fn getting called.
|
// The returned func can be used to wait for fn getting called.
|
||||||
func AddShutdownListener(fn func()) (waitForCalled func()) {
|
func AddShutdownListener(fn func()) (waitForCalled func()) {
|
||||||
@@ -39,7 +51,21 @@ func AddWrapUpListener(fn func()) (waitForCalled func()) {
|
|||||||
|
|
||||||
// SetTimeToForceQuit sets the waiting time before force quitting.
|
// SetTimeToForceQuit sets the waiting time before force quitting.
|
||||||
func SetTimeToForceQuit(duration time.Duration) {
|
func SetTimeToForceQuit(duration time.Duration) {
|
||||||
delayTimeBeforeForceQuit = duration
|
shutdownLock.Lock()
|
||||||
|
defer shutdownLock.Unlock()
|
||||||
|
waitTime = duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func Setup(conf ShutdownConf) {
|
||||||
|
shutdownLock.Lock()
|
||||||
|
defer shutdownLock.Unlock()
|
||||||
|
|
||||||
|
if conf.WrapUpTime > 0 {
|
||||||
|
wrapUpTime = conf.WrapUpTime
|
||||||
|
}
|
||||||
|
if conf.WaitTime > 0 {
|
||||||
|
waitTime = conf.WaitTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown calls the registered shutdown listeners, only for test purpose.
|
// Shutdown calls the registered shutdown listeners, only for test purpose.
|
||||||
@@ -61,8 +87,12 @@ func gracefulStop(signals chan os.Signal, sig syscall.Signal) {
|
|||||||
time.Sleep(wrapUpTime)
|
time.Sleep(wrapUpTime)
|
||||||
go shutdownListeners.notifyListeners()
|
go shutdownListeners.notifyListeners()
|
||||||
|
|
||||||
time.Sleep(delayTimeBeforeForceQuit - wrapUpTime)
|
shutdownLock.Lock()
|
||||||
logx.Infof("Still alive after %v, going to force kill the process...", delayTimeBeforeForceQuit)
|
remainingTime := waitTime - wrapUpTime
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
|
||||||
|
time.Sleep(remainingTime)
|
||||||
|
logx.Infof("Still alive after %v, going to force kill the process...", waitTime)
|
||||||
_ = syscall.Kill(syscall.Getpid(), sig)
|
_ = syscall.Kill(syscall.Getpid(), sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +112,9 @@ func (lm *listenerManager) addListener(fn func()) (waitForCalled func()) {
|
|||||||
})
|
})
|
||||||
lm.lock.Unlock()
|
lm.lock.Unlock()
|
||||||
|
|
||||||
|
// we can return lm.waitGroup.Wait directly,
|
||||||
|
// but we want to make the returned func more readable.
|
||||||
|
// creating an extra closure would be negligible in practice.
|
||||||
return func() {
|
return func() {
|
||||||
lm.waitGroup.Wait()
|
lm.waitGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -10,8 +11,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestShutdown(t *testing.T) {
|
func TestShutdown(t *testing.T) {
|
||||||
|
t.Cleanup(restoreSettings)
|
||||||
|
|
||||||
SetTimeToForceQuit(time.Hour)
|
SetTimeToForceQuit(time.Hour)
|
||||||
assert.Equal(t, time.Hour, delayTimeBeforeForceQuit)
|
shutdownLock.Lock()
|
||||||
|
assert.Equal(t, time.Hour, waitTime)
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
|
||||||
var val int
|
var val int
|
||||||
called := AddWrapUpListener(func() {
|
called := AddWrapUpListener(func() {
|
||||||
@@ -29,7 +34,53 @@ func TestShutdown(t *testing.T) {
|
|||||||
assert.Equal(t, 3, val)
|
assert.Equal(t, 3, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShutdownWithMultipleServices(t *testing.T) {
|
||||||
|
t.Cleanup(restoreSettings)
|
||||||
|
|
||||||
|
SetTimeToForceQuit(time.Hour)
|
||||||
|
shutdownLock.Lock()
|
||||||
|
assert.Equal(t, time.Hour, waitTime)
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
|
||||||
|
var val int32
|
||||||
|
called1 := AddShutdownListener(func() {
|
||||||
|
atomic.AddInt32(&val, 1)
|
||||||
|
})
|
||||||
|
called2 := AddShutdownListener(func() {
|
||||||
|
atomic.AddInt32(&val, 2)
|
||||||
|
})
|
||||||
|
Shutdown()
|
||||||
|
called1()
|
||||||
|
called2()
|
||||||
|
|
||||||
|
assert.Equal(t, int32(3), atomic.LoadInt32(&val))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapUpWithMultipleServices(t *testing.T) {
|
||||||
|
t.Cleanup(restoreSettings)
|
||||||
|
|
||||||
|
SetTimeToForceQuit(time.Hour)
|
||||||
|
shutdownLock.Lock()
|
||||||
|
assert.Equal(t, time.Hour, waitTime)
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
|
||||||
|
var val int32
|
||||||
|
called1 := AddWrapUpListener(func() {
|
||||||
|
atomic.AddInt32(&val, 1)
|
||||||
|
})
|
||||||
|
called2 := AddWrapUpListener(func() {
|
||||||
|
atomic.AddInt32(&val, 2)
|
||||||
|
})
|
||||||
|
WrapUp()
|
||||||
|
called1()
|
||||||
|
called2()
|
||||||
|
|
||||||
|
assert.Equal(t, int32(3), atomic.LoadInt32(&val))
|
||||||
|
}
|
||||||
|
|
||||||
func TestNotifyMoreThanOnce(t *testing.T) {
|
func TestNotifyMoreThanOnce(t *testing.T) {
|
||||||
|
t.Cleanup(restoreSettings)
|
||||||
|
|
||||||
ch := make(chan struct{}, 1)
|
ch := make(chan struct{}, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -58,3 +109,38 @@ func TestNotifyMoreThanOnce(t *testing.T) {
|
|||||||
t.Fatal("timeout, check error logs")
|
t.Fatal("timeout, check error logs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetup(t *testing.T) {
|
||||||
|
t.Run("valid time", func(t *testing.T) {
|
||||||
|
defer restoreSettings()
|
||||||
|
|
||||||
|
Setup(ShutdownConf{
|
||||||
|
WrapUpTime: time.Second * 2,
|
||||||
|
WaitTime: time.Second * 30,
|
||||||
|
})
|
||||||
|
|
||||||
|
shutdownLock.Lock()
|
||||||
|
assert.Equal(t, time.Second*2, wrapUpTime)
|
||||||
|
assert.Equal(t, time.Second*30, waitTime)
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("valid time", func(t *testing.T) {
|
||||||
|
defer restoreSettings()
|
||||||
|
|
||||||
|
Setup(ShutdownConf{})
|
||||||
|
|
||||||
|
shutdownLock.Lock()
|
||||||
|
assert.Equal(t, defaultWrapUpTime, wrapUpTime)
|
||||||
|
assert.Equal(t, defaultWaitTime, waitTime)
|
||||||
|
shutdownLock.Unlock()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func restoreSettings() {
|
||||||
|
shutdownLock.Lock()
|
||||||
|
defer shutdownLock.Unlock()
|
||||||
|
|
||||||
|
wrapUpTime = defaultWrapUpTime
|
||||||
|
waitTime = defaultWaitTime
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package proc
|
package proc
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ type (
|
|||||||
Prometheus prometheus.Config `json:",optional"`
|
Prometheus prometheus.Config `json:",optional"`
|
||||||
Telemetry trace.Config `json:",optional"`
|
Telemetry trace.Config `json:",optional"`
|
||||||
DevServer DevServerConfig `json:",optional"`
|
DevServer DevServerConfig `json:",optional"`
|
||||||
|
Shutdown proc.ShutdownConf `json:",optional"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ func (sc ServiceConf) SetUp() error {
|
|||||||
sc.Telemetry.Name = sc.Name
|
sc.Telemetry.Name = sc.Name
|
||||||
}
|
}
|
||||||
trace.StartAgent(sc.Telemetry)
|
trace.StartAgent(sc.Telemetry)
|
||||||
|
proc.Setup(sc.Shutdown)
|
||||||
proc.AddShutdownListener(func() {
|
proc.AddShutdownListener(func() {
|
||||||
trace.StopAgent()
|
trace.StopAgent()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,9 +76,14 @@ func (sg *ServiceGroup) doStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sg *ServiceGroup) doStop() {
|
func (sg *ServiceGroup) doStop() {
|
||||||
|
group := threading.NewRoutineGroup()
|
||||||
for _, service := range sg.services {
|
for _, service := range sg.services {
|
||||||
service.Stop()
|
// new variable to avoid closure problems, can be removed after go 1.22
|
||||||
|
// see https://golang.org/doc/faq#closures_and_goroutines
|
||||||
|
service := service
|
||||||
|
group.Run(service.Stop)
|
||||||
}
|
}
|
||||||
|
group.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithStart wraps a start func as a Service.
|
// WithStart wraps a start func as a Service.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ type (
|
|||||||
RedisConf struct {
|
RedisConf struct {
|
||||||
Host string
|
Host string
|
||||||
Type string `json:",default=node,options=node|cluster"`
|
Type string `json:",default=node,options=node|cluster"`
|
||||||
|
User string `json:",optional"`
|
||||||
Pass string `json:",optional"`
|
Pass string `json:",optional"`
|
||||||
Tls bool `json:",optional"`
|
Tls bool `json:",optional"`
|
||||||
NonBlock bool `json:",default=true"`
|
NonBlock bool `json:",default=true"`
|
||||||
@@ -40,6 +41,9 @@ func (rc RedisConf) NewRedis() *Redis {
|
|||||||
if rc.Type == ClusterType {
|
if rc.Type == ClusterType {
|
||||||
opts = append(opts, Cluster())
|
opts = append(opts, Cluster())
|
||||||
}
|
}
|
||||||
|
if len(rc.User) > 0 {
|
||||||
|
opts = append(opts, WithUser(rc.User))
|
||||||
|
}
|
||||||
if len(rc.Pass) > 0 {
|
if len(rc.Pass) > 0 {
|
||||||
opts = append(opts, WithPass(rc.Pass))
|
opts = append(opts, WithPass(rc.Pass))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ type (
|
|||||||
Redis struct {
|
Redis struct {
|
||||||
Addr string
|
Addr string
|
||||||
Type string
|
Type string
|
||||||
|
User string
|
||||||
Pass string
|
Pass string
|
||||||
tls bool
|
tls bool
|
||||||
brk breaker.Breaker
|
brk breaker.Breaker
|
||||||
@@ -126,6 +127,9 @@ func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) {
|
|||||||
if conf.Type == ClusterType {
|
if conf.Type == ClusterType {
|
||||||
opts = append([]Option{Cluster()}, opts...)
|
opts = append([]Option{Cluster()}, opts...)
|
||||||
}
|
}
|
||||||
|
if len(conf.User) > 0 {
|
||||||
|
opts = append([]Option{WithUser(conf.User)}, opts...)
|
||||||
|
}
|
||||||
if len(conf.Pass) > 0 {
|
if len(conf.Pass) > 0 {
|
||||||
opts = append([]Option{WithPass(conf.Pass)}, opts...)
|
opts = append([]Option{WithPass(conf.Pass)}, opts...)
|
||||||
}
|
}
|
||||||
@@ -2405,6 +2409,13 @@ func SetSlowThreshold(threshold time.Duration) {
|
|||||||
slowThreshold.Set(threshold)
|
slowThreshold.Set(threshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithHook customizes the given Redis with given durationHook.
|
||||||
|
func WithHook(hook Hook) Option {
|
||||||
|
return func(r *Redis) {
|
||||||
|
r.hooks = append(r.hooks, hook)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithPass customizes the given Redis with given password.
|
// WithPass customizes the given Redis with given password.
|
||||||
func WithPass(pass string) Option {
|
func WithPass(pass string) Option {
|
||||||
return func(r *Redis) {
|
return func(r *Redis) {
|
||||||
@@ -2419,11 +2430,10 @@ func WithTLS() Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithHook customizes the given Redis with given durationHook, only for private use now,
|
// WithUser customizes the given Redis with given username.
|
||||||
// maybe expose later.
|
func WithUser(user string) Option {
|
||||||
func WithHook(hook Hook) Option {
|
|
||||||
return func(r *Redis) {
|
return func(r *Redis) {
|
||||||
r.hooks = append(r.hooks, hook)
|
r.User = user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1996,9 +1996,9 @@ func TestSetSlowThreshold(t *testing.T) {
|
|||||||
assert.Equal(t, time.Second, slowThreshold.Load())
|
assert.Equal(t, time.Second, slowThreshold.Load())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRedis_WithPass(t *testing.T) {
|
func TestRedis_WithUserPass(t *testing.T) {
|
||||||
runOnRedis(t, func(client *Redis) {
|
runOnRedis(t, func(client *Redis) {
|
||||||
err := newRedis(client.Addr, WithPass("any")).Ping()
|
err := newRedis(client.Addr, WithUser("any"), WithPass("any")).Ping()
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -2119,9 +2119,9 @@ func TestRedisUnlink(t *testing.T) {
|
|||||||
func TestRedisTxPipeline(t *testing.T) {
|
func TestRedisTxPipeline(t *testing.T) {
|
||||||
runOnRedis(t, func(client *Redis) {
|
runOnRedis(t, func(client *Redis) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
pipe, err := newRedis(client.Addr, badType()).TxPipeline()
|
_, err := newRedis(client.Addr, badType()).TxPipeline()
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
pipe, err = client.TxPipeline()
|
pipe, err := client.TxPipeline()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
key := "key"
|
key := "key"
|
||||||
hashKey := "field"
|
hashKey := "field"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ func CreateBlockingNode(r *Redis) (ClosableNode, error) {
|
|||||||
case NodeType:
|
case NodeType:
|
||||||
client := red.NewClient(&red.Options{
|
client := red.NewClient(&red.Options{
|
||||||
Addr: r.Addr,
|
Addr: r.Addr,
|
||||||
|
Username: r.User,
|
||||||
Password: r.Pass,
|
Password: r.Pass,
|
||||||
DB: defaultDatabase,
|
DB: defaultDatabase,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: maxRetries,
|
||||||
@@ -32,6 +33,7 @@ func CreateBlockingNode(r *Redis) (ClosableNode, error) {
|
|||||||
case ClusterType:
|
case ClusterType:
|
||||||
client := red.NewClusterClient(&red.ClusterOptions{
|
client := red.NewClusterClient(&red.ClusterOptions{
|
||||||
Addrs: splitClusterAddrs(r.Addr),
|
Addrs: splitClusterAddrs(r.Addr),
|
||||||
|
Username: r.User,
|
||||||
Password: r.Pass,
|
Password: r.Pass,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: maxRetries,
|
||||||
PoolSize: 1,
|
PoolSize: 1,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func getClient(r *Redis) (*red.Client, error) {
|
|||||||
}
|
}
|
||||||
store := red.NewClient(&red.Options{
|
store := red.NewClient(&red.Options{
|
||||||
Addr: r.Addr,
|
Addr: r.Addr,
|
||||||
|
Username: r.User,
|
||||||
Password: r.Pass,
|
Password: r.Pass,
|
||||||
DB: defaultDatabase,
|
DB: defaultDatabase,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: maxRetries,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func getCluster(r *Redis) (*red.ClusterClient, error) {
|
|||||||
}
|
}
|
||||||
store := red.NewClusterClient(&red.ClusterOptions{
|
store := red.NewClusterClient(&red.ClusterOptions{
|
||||||
Addrs: splitClusterAddrs(r.Addr),
|
Addrs: splitClusterAddrs(r.Addr),
|
||||||
|
Username: r.User,
|
||||||
Password: r.Pass,
|
Password: r.Pass,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: maxRetries,
|
||||||
MinIdleConns: idleConns,
|
MinIdleConns: idleConns,
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ var (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
statGetter struct {
|
statGetter struct {
|
||||||
|
host string
|
||||||
dbName string
|
dbName string
|
||||||
hash string
|
hash string
|
||||||
poolStats func() sql.DBStats
|
poolStats func() sql.DBStats
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package sqlx
|
package sqlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/syncx"
|
"github.com/zeromicro/go-zero/core/syncx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,6 +27,23 @@ func getCachedSqlConn(driverName, server string) (*sql.DB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if driverName != mysqlDriverName {
|
||||||
|
if cfg, e := mysql.ParseDSN(server); e != nil {
|
||||||
|
// if cannot parse, don't collect the metrics
|
||||||
|
logx.Error(e)
|
||||||
|
} else {
|
||||||
|
checksum := sha256.Sum256([]byte(server))
|
||||||
|
connCollector.registerClient(&statGetter{
|
||||||
|
host: cfg.Addr,
|
||||||
|
dbName: cfg.DBName,
|
||||||
|
hash: hex.EncodeToString(checksum[:]),
|
||||||
|
poolStats: func() sql.DBStats {
|
||||||
|
return conn.Stats()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func FuzzNodeFind(f *testing.F) {
|
|||||||
fmt.Fprintf(&buf, "text:\n\t%s\n", str)
|
fmt.Fprintf(&buf, "text:\n\t%s\n", str)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
t.Errorf(buf.String())
|
t.Error(buf.String())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
assert.ElementsMatchf(t, scopes, n.find([]rune(str)), buf.String())
|
assert.ElementsMatchf(t, scopes, n.find([]rune(str)), buf.String())
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const factor = 10
|
const factor = 10
|
||||||
@@ -100,6 +101,6 @@ func (r *StableRunner[I, O]) Wait() {
|
|||||||
close(r.done)
|
close(r.done)
|
||||||
r.runner.Wait()
|
r.runner.Wait()
|
||||||
for atomic.LoadUint64(&r.consumedIndex) < atomic.LoadUint64(&r.writtenIndex) {
|
for atomic.LoadUint64(&r.consumedIndex) < atomic.LoadUint64(&r.writtenIndex) {
|
||||||
runtime.Gosched()
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,22 @@ type (
|
|||||||
Upstreams []Upstream
|
Upstreams []Upstream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HttpClientConf is the configuration for an HTTP client.
|
||||||
|
HttpClientConf struct {
|
||||||
|
Target string
|
||||||
|
Prefix string `json:",optional"`
|
||||||
|
Timeout int64 `json:",default=3000"`
|
||||||
|
}
|
||||||
|
|
||||||
// RouteMapping is a mapping between a gateway route and an upstream rpc method.
|
// RouteMapping is a mapping between a gateway route and an upstream rpc method.
|
||||||
RouteMapping struct {
|
RouteMapping struct {
|
||||||
// Method is the HTTP method, like GET, POST, PUT, DELETE.
|
// Method is the HTTP method, like GET, POST, PUT, DELETE.
|
||||||
Method string
|
Method string
|
||||||
// Path is the HTTP path.
|
// Path is the HTTP path.
|
||||||
Path string
|
Path string
|
||||||
// RpcPath is the gRPC rpc method, with format of package.service/method
|
// RpcPath is the gRPC rpc method, with format of package.service/method, optional.
|
||||||
RpcPath string
|
// If the mapping is for HTTP, it's not necessary.
|
||||||
|
RpcPath string `json:",optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upstream is the configuration for an upstream.
|
// Upstream is the configuration for an upstream.
|
||||||
@@ -27,12 +35,14 @@ type (
|
|||||||
// Name is the name of the upstream.
|
// Name is the name of the upstream.
|
||||||
Name string `json:",optional"`
|
Name string `json:",optional"`
|
||||||
// Grpc is the target of the upstream.
|
// Grpc is the target of the upstream.
|
||||||
Grpc zrpc.RpcClientConf
|
Grpc *zrpc.RpcClientConf `json:",optional"`
|
||||||
|
// Http is the target of the upstream.
|
||||||
|
Http *HttpClientConf `json:",optional=!grpc"`
|
||||||
// ProtoSets is the file list of proto set, like [hello.pb].
|
// ProtoSets is the file list of proto set, like [hello.pb].
|
||||||
// if your proto file import another proto file, you need to write multi-file slice,
|
// if your proto file import another proto file, you need to write multi-file slice,
|
||||||
// like [hello.pb, common.pb].
|
// like [hello.pb, common.pb].
|
||||||
ProtoSets []string `json:",optional"`
|
ProtoSets []string `json:",optional"`
|
||||||
// Mappings is the mapping between gateway routes and Upstream rpc methods.
|
// Mappings is the mapping between gateway routes and Upstream methods.
|
||||||
// Keep it blank if annotations are added in rpc methods.
|
// Keep it blank if annotations are added in rpc methods.
|
||||||
Mappings []RouteMapping `json:",optional"`
|
Mappings []RouteMapping `json:",optional"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,26 +3,35 @@ package gateway
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/fullstorydev/grpcurl"
|
"github.com/fullstorydev/grpcurl"
|
||||||
"github.com/golang/protobuf/jsonpb"
|
"github.com/golang/protobuf/jsonpb"
|
||||||
"github.com/jhump/protoreflect/grpcreflect"
|
"github.com/jhump/protoreflect/grpcreflect"
|
||||||
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/mr"
|
"github.com/zeromicro/go-zero/core/mr"
|
||||||
|
"github.com/zeromicro/go-zero/core/threading"
|
||||||
"github.com/zeromicro/go-zero/gateway/internal"
|
"github.com/zeromicro/go-zero/gateway/internal"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultHttpScheme = "http"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Server is a gateway server.
|
// Server is a gateway server.
|
||||||
Server struct {
|
Server struct {
|
||||||
*rest.Server
|
*rest.Server
|
||||||
upstreams []Upstream
|
upstreams []Upstream
|
||||||
|
conns []zrpc.Client
|
||||||
processHeader func(http.Header) []string
|
processHeader func(http.Header) []string
|
||||||
dialer func(conf zrpc.RpcClientConf) zrpc.Client
|
dialer func(conf zrpc.RpcClientConf) zrpc.Client
|
||||||
}
|
}
|
||||||
@@ -51,8 +60,24 @@ func (s *Server) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops the gateway server.
|
// Stop stops the gateway server.
|
||||||
|
// To get a graceful shutdown, it stops the HTTP server first, then closes gRPC connections.
|
||||||
func (s *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
|
// stop the HTTP server first, then close gRPC connections.
|
||||||
|
// in case the gRPC server is stopped first,
|
||||||
|
// the HTTP server may still be running to accept requests.
|
||||||
s.Server.Stop()
|
s.Server.Stop()
|
||||||
|
|
||||||
|
group := threading.NewRoutineGroup()
|
||||||
|
for _, conn := range s.conns {
|
||||||
|
// new variable to avoid closure problems, can be removed after go 1.22
|
||||||
|
// see https://golang.org/doc/faq#closures_and_goroutines
|
||||||
|
conn := conn
|
||||||
|
group.Run(func() {
|
||||||
|
// ignore the error when closing the connection
|
||||||
|
_ = conn.Conn().Close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
group.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) build() error {
|
func (s *Server) build() error {
|
||||||
@@ -65,51 +90,11 @@ func (s *Server) build() error {
|
|||||||
source <- up
|
source <- up
|
||||||
}
|
}
|
||||||
}, func(up Upstream, writer mr.Writer[rest.Route], cancel func(error)) {
|
}, func(up Upstream, writer mr.Writer[rest.Route], cancel func(error)) {
|
||||||
var cli zrpc.Client
|
// up.Grpc and up.Http are exclusive
|
||||||
if s.dialer != nil {
|
if up.Grpc != nil {
|
||||||
cli = s.dialer(up.Grpc)
|
s.buildGrpcRoute(up, writer, cancel)
|
||||||
} else {
|
} else if up.Http != nil {
|
||||||
cli = zrpc.MustNewClient(up.Grpc)
|
s.buildHttpRoute(up, writer)
|
||||||
}
|
|
||||||
|
|
||||||
source, err := s.createDescriptorSource(cli, up)
|
|
||||||
if err != nil {
|
|
||||||
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
methods, err := internal.GetMethods(source)
|
|
||||||
if err != nil {
|
|
||||||
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resolver := grpcurl.AnyResolverFromDescriptorSource(source)
|
|
||||||
for _, m := range methods {
|
|
||||||
if len(m.HttpMethod) > 0 && len(m.HttpPath) > 0 {
|
|
||||||
writer.Write(rest.Route{
|
|
||||||
Method: m.HttpMethod,
|
|
||||||
Path: m.HttpPath,
|
|
||||||
Handler: s.buildHandler(source, resolver, cli, m.RpcPath),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
methodSet := make(map[string]struct{})
|
|
||||||
for _, m := range methods {
|
|
||||||
methodSet[m.RpcPath] = struct{}{}
|
|
||||||
}
|
|
||||||
for _, m := range up.Mappings {
|
|
||||||
if _, ok := methodSet[m.RpcPath]; !ok {
|
|
||||||
cancel(fmt.Errorf("%s: rpc method %s not found", up.Name, m.RpcPath))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.Write(rest.Route{
|
|
||||||
Method: strings.ToUpper(m.Method),
|
|
||||||
Path: m.Path,
|
|
||||||
Handler: s.buildHandler(source, resolver, cli, m.RpcPath),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, func(pipe <-chan rest.Route, cancel func(error)) {
|
}, func(pipe <-chan rest.Route, cancel func(error)) {
|
||||||
for route := range pipe {
|
for route := range pipe {
|
||||||
@@ -118,7 +103,7 @@ func (s *Server) build() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) buildHandler(source grpcurl.DescriptorSource, resolver jsonpb.AnyResolver,
|
func (s *Server) buildGrpcHandler(source grpcurl.DescriptorSource, resolver jsonpb.AnyResolver,
|
||||||
cli zrpc.Client, rpcPath string) func(http.ResponseWriter, *http.Request) {
|
cli zrpc.Client, rpcPath string) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
parser, err := internal.NewRequestParser(r, resolver)
|
parser, err := internal.NewRequestParser(r, resolver)
|
||||||
@@ -141,31 +126,121 @@ func (s *Server) buildHandler(source grpcurl.DescriptorSource, resolver jsonpb.A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) createDescriptorSource(cli zrpc.Client, up Upstream) (grpcurl.DescriptorSource, error) {
|
func (s *Server) buildGrpcRoute(up Upstream, writer mr.Writer[rest.Route], cancel func(error)) {
|
||||||
var source grpcurl.DescriptorSource
|
var cli zrpc.Client
|
||||||
var err error
|
if s.dialer != nil {
|
||||||
|
cli = s.dialer(*up.Grpc)
|
||||||
if len(up.ProtoSets) > 0 {
|
|
||||||
source, err = grpcurl.DescriptorSourceFromProtoSets(up.ProtoSets...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
client := grpcreflect.NewClientAuto(context.Background(), cli.Conn())
|
cli = zrpc.MustNewClient(*up.Grpc)
|
||||||
source = grpcurl.DescriptorSourceFromServer(context.Background(), client)
|
}
|
||||||
|
s.conns = append(s.conns, cli)
|
||||||
|
|
||||||
|
source, err := createDescriptorSource(cli, up)
|
||||||
|
if err != nil {
|
||||||
|
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return source, nil
|
methods, err := internal.GetMethods(source)
|
||||||
|
if err != nil {
|
||||||
|
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resolver := grpcurl.AnyResolverFromDescriptorSource(source)
|
||||||
|
for _, m := range methods {
|
||||||
|
if len(m.HttpMethod) > 0 && len(m.HttpPath) > 0 {
|
||||||
|
writer.Write(rest.Route{
|
||||||
|
Method: m.HttpMethod,
|
||||||
|
Path: m.HttpPath,
|
||||||
|
Handler: s.buildGrpcHandler(source, resolver, cli, m.RpcPath),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
methodSet := make(map[string]struct{})
|
||||||
|
for _, m := range methods {
|
||||||
|
methodSet[m.RpcPath] = struct{}{}
|
||||||
|
}
|
||||||
|
for _, m := range up.Mappings {
|
||||||
|
if _, ok := methodSet[m.RpcPath]; !ok {
|
||||||
|
cancel(fmt.Errorf("%s: rpc method %s not found", up.Name, m.RpcPath))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Write(rest.Route{
|
||||||
|
Method: strings.ToUpper(m.Method),
|
||||||
|
Path: m.Path,
|
||||||
|
Handler: s.buildGrpcHandler(source, resolver, cli, m.RpcPath),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) buildHttpHandler(target *HttpClientConf) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set(httpx.ContentType, httpx.JsonContentType)
|
||||||
|
req, err := buildRequestWithNewTarget(r, target)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the timeout if it's configured, take effect only if it's greater than 0
|
||||||
|
// and less than the deadline of the original request
|
||||||
|
if target.Timeout > 0 {
|
||||||
|
timeout := time.Duration(target.Timeout) * time.Millisecond
|
||||||
|
ctx, cancel := context.WithTimeout(r.Context(), timeout)
|
||||||
|
defer cancel()
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := httpc.DoRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
for key, values := range resp.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
w.Header().Add(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
|
if _, err = io.Copy(w, resp.Body); err != nil {
|
||||||
|
// log the error with original request info
|
||||||
|
logc.Error(r.Context(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) buildHttpRoute(up Upstream, writer mr.Writer[rest.Route]) {
|
||||||
|
for _, m := range up.Mappings {
|
||||||
|
writer.Write(rest.Route{
|
||||||
|
Method: strings.ToUpper(m.Method),
|
||||||
|
Path: m.Path,
|
||||||
|
Handler: s.buildHttpHandler(up.Http),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ensureUpstreamNames() error {
|
func (s *Server) ensureUpstreamNames() error {
|
||||||
for i := 0; i < len(s.upstreams); i++ {
|
for i := 0; i < len(s.upstreams); i++ {
|
||||||
target, err := s.upstreams[i].Grpc.BuildTarget()
|
if len(s.upstreams[i].Name) > 0 {
|
||||||
if err != nil {
|
continue
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.upstreams[i].Name = target
|
if s.upstreams[i].Grpc != nil {
|
||||||
|
target, err := s.upstreams[i].Grpc.BuildTarget()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.upstreams[i].Name = target
|
||||||
|
} else if s.upstreams[i].Http != nil {
|
||||||
|
s.upstreams[i].Name = s.upstreams[i].Http.Target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -188,6 +263,53 @@ func WithHeaderProcessor(processHeader func(http.Header) []string) func(*Server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildRequestWithNewTarget(r *http.Request, target *HttpClientConf) (*http.Request, error) {
|
||||||
|
u := *r.URL
|
||||||
|
u.Host = target.Target
|
||||||
|
if len(u.Scheme) == 0 {
|
||||||
|
u.Scheme = defaultHttpScheme
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(target.Prefix) > 0 {
|
||||||
|
var err error
|
||||||
|
u.Path, err = url.JoinPath(target.Prefix, u.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newReq := &http.Request{
|
||||||
|
Method: r.Method,
|
||||||
|
URL: &u,
|
||||||
|
Header: r.Header.Clone(),
|
||||||
|
Proto: r.Proto,
|
||||||
|
ProtoMajor: r.ProtoMajor,
|
||||||
|
ProtoMinor: r.ProtoMinor,
|
||||||
|
ContentLength: r.ContentLength,
|
||||||
|
Body: io.NopCloser(r.Body),
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure the context is passed to the new request
|
||||||
|
return newReq.WithContext(r.Context()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createDescriptorSource(cli zrpc.Client, up Upstream) (grpcurl.DescriptorSource, error) {
|
||||||
|
var source grpcurl.DescriptorSource
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(up.ProtoSets) > 0 {
|
||||||
|
source, err = grpcurl.DescriptorSourceFromProtoSets(up.ProtoSets...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client := grpcreflect.NewClientAuto(context.Background(), cli.Conn())
|
||||||
|
source = grpcurl.DescriptorSourceFromServer(context.Background(), client)
|
||||||
|
}
|
||||||
|
|
||||||
|
return source, nil
|
||||||
|
}
|
||||||
|
|
||||||
// withDialer sets a dialer to create a gRPC client.
|
// withDialer sets a dialer to create a gRPC client.
|
||||||
func withDialer(dialer func(conf zrpc.RpcClientConf) zrpc.Client) func(*Server) {
|
func withDialer(dialer func(conf zrpc.RpcClientConf) zrpc.Client) func(*Server) {
|
||||||
return func(s *Server) {
|
return func(s *Server) {
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package gateway
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -46,7 +49,7 @@ func dialer() func(context.Context, string) (net.Conn, error) {
|
|||||||
func TestMustNewServer(t *testing.T) {
|
func TestMustNewServer(t *testing.T) {
|
||||||
var c GatewayConf
|
var c GatewayConf
|
||||||
assert.NoError(t, conf.FillDefault(&c))
|
assert.NoError(t, conf.FillDefault(&c))
|
||||||
// avoid popup alert on macos for asking permissions
|
// avoid popup alert on MacOS for asking permissions
|
||||||
c.DevServer.Host = "localhost"
|
c.DevServer.Host = "localhost"
|
||||||
c.Host = "localhost"
|
c.Host = "localhost"
|
||||||
c.Port = 18881
|
c.Port = 18881
|
||||||
@@ -65,7 +68,7 @@ func TestMustNewServer(t *testing.T) {
|
|||||||
RpcPath: "mock.DepositService/Deposit",
|
RpcPath: "mock.DepositService/Deposit",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Grpc: zrpc.RpcClientConf{
|
Grpc: &zrpc.RpcClientConf{
|
||||||
Endpoints: []string{"foo"},
|
Endpoints: []string{"foo"},
|
||||||
Timeout: 1000,
|
Timeout: 1000,
|
||||||
Middlewares: zrpc.ClientMiddlewaresConf{
|
Middlewares: zrpc.ClientMiddlewaresConf{
|
||||||
@@ -98,7 +101,7 @@ func TestServer_ensureUpstreamNames(t *testing.T) {
|
|||||||
var s = Server{
|
var s = Server{
|
||||||
upstreams: []Upstream{
|
upstreams: []Upstream{
|
||||||
{
|
{
|
||||||
Grpc: zrpc.RpcClientConf{
|
Grpc: &zrpc.RpcClientConf{
|
||||||
Target: "target",
|
Target: "target",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -113,7 +116,7 @@ func TestServer_ensureUpstreamNames_badEtcd(t *testing.T) {
|
|||||||
var s = Server{
|
var s = Server{
|
||||||
upstreams: []Upstream{
|
upstreams: []Upstream{
|
||||||
{
|
{
|
||||||
Grpc: zrpc.RpcClientConf{
|
Grpc: &zrpc.RpcClientConf{
|
||||||
Etcd: discov.EtcdConf{},
|
Etcd: discov.EtcdConf{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -125,3 +128,193 @@ func TestServer_ensureUpstreamNames_badEtcd(t *testing.T) {
|
|||||||
s.Start()
|
s.Start()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHttpToHttp(t *testing.T) {
|
||||||
|
server := startTestServer(t)
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
var c GatewayConf
|
||||||
|
assert.NoError(t, conf.FillDefault(&c))
|
||||||
|
c.DevServer.Host = "localhost"
|
||||||
|
c.Host = "localhost"
|
||||||
|
c.Port = 18882
|
||||||
|
|
||||||
|
s := MustNewServer(c)
|
||||||
|
s.upstreams = []Upstream{
|
||||||
|
{
|
||||||
|
Name: "test",
|
||||||
|
Mappings: []RouteMapping{
|
||||||
|
{
|
||||||
|
Method: "get",
|
||||||
|
Path: "/api/ping",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Http: &HttpClientConf{
|
||||||
|
Target: "localhost:45678",
|
||||||
|
Timeout: 3000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Mappings: []RouteMapping{
|
||||||
|
{
|
||||||
|
Method: "get",
|
||||||
|
Path: "/ping",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Http: &HttpClientConf{
|
||||||
|
Target: "localhost:45678",
|
||||||
|
Prefix: "/api",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
go s.Start()
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 200)
|
||||||
|
|
||||||
|
t.Run("/api/ping", func(t *testing.T) {
|
||||||
|
resp, err := httpc.Do(context.Background(), http.MethodGet,
|
||||||
|
"http://localhost:18882/api/ping", nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, "pong", string(body))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("/ping", func(t *testing.T) {
|
||||||
|
resp, err := httpc.Do(context.Background(), http.MethodGet,
|
||||||
|
"http://localhost:18882/ping", nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, "pong", string(body))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("no upstream", func(t *testing.T) {
|
||||||
|
resp, err := httpc.Do(context.Background(), http.MethodGet,
|
||||||
|
"http://localhost:18882/ping/bad", nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHttpToHttpBadUpstream(t *testing.T) {
|
||||||
|
var c GatewayConf
|
||||||
|
assert.NoError(t, conf.FillDefault(&c))
|
||||||
|
c.DevServer.Host = "localhost"
|
||||||
|
c.Host = "localhost"
|
||||||
|
c.Port = 18883
|
||||||
|
|
||||||
|
s := MustNewServer(c)
|
||||||
|
s.upstreams = []Upstream{
|
||||||
|
{
|
||||||
|
Mappings: []RouteMapping{
|
||||||
|
{
|
||||||
|
Method: "get",
|
||||||
|
Path: "/api/ping",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Http: &HttpClientConf{
|
||||||
|
Target: "localhost:45678",
|
||||||
|
Prefix: "\x7f/api",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
go s.Start()
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 200)
|
||||||
|
|
||||||
|
t.Run("/api/ping", func(t *testing.T) {
|
||||||
|
resp, err := httpc.Do(context.Background(), http.MethodGet,
|
||||||
|
"http://localhost:18883/api/ping", nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHttpToHttpBadWriter(t *testing.T) {
|
||||||
|
t.Run("bad url", func(t *testing.T) {
|
||||||
|
handler := new(Server).buildHttpHandler(&HttpClientConf{
|
||||||
|
Target: "http://example.com",
|
||||||
|
Timeout: 3000,
|
||||||
|
})
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(&badResponseWriter{w},
|
||||||
|
httptest.NewRequest(http.MethodGet, "http://localhost:18884", nil))
|
||||||
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("bad url", func(t *testing.T) {
|
||||||
|
var c GatewayConf
|
||||||
|
assert.NoError(t, conf.FillDefault(&c))
|
||||||
|
c.DevServer.Host = "localhost"
|
||||||
|
c.Host = "localhost"
|
||||||
|
c.Port = 18884
|
||||||
|
|
||||||
|
s := MustNewServer(c)
|
||||||
|
s.upstreams = []Upstream{
|
||||||
|
{
|
||||||
|
Mappings: []RouteMapping{
|
||||||
|
{
|
||||||
|
Method: "get",
|
||||||
|
Path: "/api/ping",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Http: &HttpClientConf{
|
||||||
|
Target: "localhost:45678",
|
||||||
|
Prefix: "\x7f/api",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
go s.Start()
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
handler := new(Server).buildHttpHandler(&HttpClientConf{
|
||||||
|
Target: "localhost:18884",
|
||||||
|
Timeout: 3000,
|
||||||
|
})
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(&badResponseWriter{w},
|
||||||
|
httptest.NewRequest(http.MethodGet, "http://localhost:18884/api/ping", nil))
|
||||||
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler function for the root route
|
||||||
|
func pingHandler(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("pong"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func startTestServer(t *testing.T) *http.Server {
|
||||||
|
http.HandleFunc("/api/ping", pingHandler)
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":45678",
|
||||||
|
Handler: http.DefaultServeMux,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
t.Errorf("failed to start server: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
type badResponseWriter struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *badResponseWriter) Write([]byte) (int, error) {
|
||||||
|
return 0, errors.New("bad writer")
|
||||||
|
}
|
||||||
|
|||||||
42
go.mod
42
go.mod
@@ -1,28 +1,28 @@
|
|||||||
module github.com/zeromicro/go-zero
|
module github.com/zeromicro/go-zero
|
||||||
|
|
||||||
go 1.20
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0
|
github.com/alicebob/miniredis/v2 v2.34.0
|
||||||
github.com/fatih/color v1.18.0
|
github.com/fatih/color v1.18.0
|
||||||
github.com/fullstorydev/grpcurl v1.9.1
|
github.com/fullstorydev/grpcurl v1.9.2
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.9.0
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.1
|
github.com/golang-jwt/jwt/v4 v4.5.1
|
||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/golang/protobuf v1.5.4
|
github.com/golang/protobuf v1.5.4
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/jackc/pgx/v5 v5.6.0
|
github.com/jackc/pgx/v5 v5.7.2
|
||||||
github.com/jhump/protoreflect v1.17.0
|
github.com/jhump/protoreflect v1.17.0
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2
|
github.com/pelletier/go-toml/v2 v2.2.2
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.21.0
|
||||||
github.com/redis/go-redis/v9 v9.7.0
|
github.com/redis/go-redis/v9 v9.7.1
|
||||||
github.com/spaolacci/murmur3 v1.1.0
|
github.com/spaolacci/murmur3 v1.1.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.10.0
|
||||||
go.etcd.io/etcd/api/v3 v3.5.15
|
go.etcd.io/etcd/api/v3 v3.5.15
|
||||||
go.etcd.io/etcd/client/v3 v3.5.15
|
go.etcd.io/etcd/client/v3 v3.5.15
|
||||||
go.mongodb.org/mongo-driver v1.17.1
|
go.mongodb.org/mongo-driver v1.17.3
|
||||||
go.opentelemetry.io/otel v1.24.0
|
go.opentelemetry.io/otel v1.24.0
|
||||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
||||||
@@ -33,12 +33,12 @@ require (
|
|||||||
go.opentelemetry.io/otel/trace v1.24.0
|
go.opentelemetry.io/otel/trace v1.24.0
|
||||||
go.uber.org/automaxprocs v1.6.0
|
go.uber.org/automaxprocs v1.6.0
|
||||||
go.uber.org/goleak v1.3.0
|
go.uber.org/goleak v1.3.0
|
||||||
golang.org/x/net v0.31.0
|
golang.org/x/net v0.35.0
|
||||||
golang.org/x/sys v0.27.0
|
golang.org/x/sys v0.30.0
|
||||||
golang.org/x/time v0.8.0
|
golang.org/x/time v0.10.0
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d
|
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d
|
||||||
google.golang.org/grpc v1.65.0
|
google.golang.org/grpc v1.65.0
|
||||||
google.golang.org/protobuf v1.35.2
|
google.golang.org/protobuf v1.36.5
|
||||||
gopkg.in/cheggaaa/pb.v1 v1.0.28
|
gopkg.in/cheggaaa/pb.v1 v1.0.28
|
||||||
gopkg.in/h2non/gock.v1 v1.1.2
|
gopkg.in/h2non/gock.v1 v1.1.2
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
@@ -77,10 +77,10 @@ require (
|
|||||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.11 // indirect
|
||||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
@@ -93,7 +93,7 @@ require (
|
|||||||
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.55.0 // indirect
|
github.com/prometheus/common v0.62.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/stretchr/objx v0.5.2 // indirect
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
@@ -109,11 +109,11 @@ require (
|
|||||||
go.uber.org/atomic v1.10.0 // indirect
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
go.uber.org/zap v1.24.0 // indirect
|
go.uber.org/zap v1.24.0 // indirect
|
||||||
golang.org/x/crypto v0.29.0 // indirect
|
golang.org/x/crypto v0.33.0 // indirect
|
||||||
golang.org/x/oauth2 v0.21.0 // indirect
|
golang.org/x/oauth2 v0.24.0 // indirect
|
||||||
golang.org/x/sync v0.9.0 // indirect
|
golang.org/x/sync v0.11.0 // indirect
|
||||||
golang.org/x/term v0.26.0 // indirect
|
golang.org/x/term v0.29.0 // indirect
|
||||||
golang.org/x/text v0.20.0 // indirect
|
golang.org/x/text v0.22.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
|||||||
92
go.sum
92
go.sum
@@ -4,13 +4,16 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
|
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
|
||||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
|
github.com/alicebob/miniredis/v2 v2.34.0 h1:mBFWMaJSNL9RwdGRyEDoAAv8OQc5UlEhLDQggTglU/0=
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
|
github.com/alicebob/miniredis/v2 v2.34.0/go.mod h1:kWShP4b58T1CW0Y5dViCd5ztzrDqRWqM3nksiyXk5s8=
|
||||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
|
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
||||||
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||||
@@ -37,8 +40,8 @@ github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU
|
|||||||
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
|
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
|
||||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
github.com/fullstorydev/grpcurl v1.9.1 h1:YxX1aCcCc4SDBQfj9uoWcTLe8t4NWrZe1y+mk83BQgo=
|
github.com/fullstorydev/grpcurl v1.9.2 h1:ObqVQTZW7aFnhuqQoppUrvep2duMBanB0UYK2Mm8euo=
|
||||||
github.com/fullstorydev/grpcurl v1.9.1/go.mod h1:i8gKLIC6s93WdU3LSmkE5vtsCxyRmihUj5FK1cNW5EM=
|
github.com/fullstorydev/grpcurl v1.9.2/go.mod h1:jLfcF55HAz6TYIJY9xFFWgsl0D7o2HlxA5Z4lUG0Tdo=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||||
@@ -52,9 +55,10 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
|
|||||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
||||||
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
github.com/go-sql-driver/mysql v1.9.0 h1:Y0zIbQXhQKmQgTp44Y1dp3wTXcn804QoTptLZT1vtvo=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.9.0/go.mod h1:pDetrLJeA3oMujJuvXc8RJoasr589B6A9fwzD3QMrqw=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
@@ -75,6 +79,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
|||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||||
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||||
@@ -85,10 +90,10 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
|||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
|
||||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
|
||||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
|
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
|
||||||
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
|
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
@@ -98,10 +103,11 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
|
|||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
||||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
@@ -132,31 +138,37 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uY
|
|||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
|
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
|
||||||
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
|
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
|
||||||
|
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
|
||||||
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
|
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
|
||||||
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
|
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
||||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
|
||||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
github.com/prometheus/client_golang v1.21.0 h1:DIsaGmiaBkSangBgMtWdNfxbMNdku5IK6iNhrEqWvdA=
|
||||||
|
github.com/prometheus/client_golang v1.21.0/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
|
||||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
|
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
|
||||||
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
|
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
github.com/redis/go-redis/v9 v9.7.1 h1:4LhKRCIduqXqtvCUlaq9c8bdHOkICjDMrr1+Zb3osAc=
|
||||||
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
github.com/redis/go-redis/v9 v9.7.1/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
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/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
@@ -168,8 +180,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||||
@@ -190,8 +203,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5
|
|||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
|
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
|
||||||
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
|
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
|
||||||
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
|
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
|
||||||
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
|
go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeHxQ=
|
||||||
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
|
go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
|
||||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
||||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
||||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
||||||
@@ -228,8 +241,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
|||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@@ -241,17 +254,17 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
|||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||||
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
|
||||||
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
|
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||||
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -263,20 +276,20 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
|
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
|
||||||
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
|
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||||
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||||
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4=
|
||||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
@@ -284,6 +297,7 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
|
|||||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -294,8 +308,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:
|
|||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ func (p *comboHealthManager) IsReady() bool {
|
|||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
defer p.mu.Unlock()
|
||||||
|
|
||||||
|
if len(p.probes) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for _, probe := range p.probes {
|
for _, probe := range p.probes {
|
||||||
if !probe.IsReady() {
|
if !probe.IsReady() {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestComboHealthManager(t *testing.T) {
|
|||||||
hm1 := NewHealthManager(probeName)
|
hm1 := NewHealthManager(probeName)
|
||||||
hm2 := NewHealthManager(probeName + "2")
|
hm2 := NewHealthManager(probeName + "2")
|
||||||
|
|
||||||
assert.True(t, chm.IsReady())
|
assert.False(t, chm.IsReady())
|
||||||
chm.addProbe(hm1)
|
chm.addProbe(hm1)
|
||||||
chm.addProbe(hm2)
|
chm.addProbe(hm2)
|
||||||
assert.False(t, chm.IsReady())
|
assert.False(t, chm.IsReady())
|
||||||
@@ -57,7 +57,7 @@ func TestComboHealthManager(t *testing.T) {
|
|||||||
chm := newComboHealthManager()
|
chm := newComboHealthManager()
|
||||||
hm := NewHealthManager(probeName)
|
hm := NewHealthManager(probeName)
|
||||||
|
|
||||||
assert.True(t, chm.IsReady())
|
assert.False(t, chm.IsReady())
|
||||||
chm.addProbe(hm)
|
chm.addProbe(hm)
|
||||||
assert.False(t, chm.IsReady())
|
assert.False(t, chm.IsReady())
|
||||||
hm.MarkReady()
|
hm.MarkReady()
|
||||||
@@ -127,7 +127,7 @@ func TestCreateHttpHandler(t *testing.T) {
|
|||||||
resp, err := http.Get(srv.URL)
|
resp, err := http.Get(srv.URL)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
|
||||||
|
|
||||||
hm := NewHealthManager(probeName)
|
hm := NewHealthManager(probeName)
|
||||||
defaultHealthManager.addProbe(hm)
|
defaultHealthManager.addProbe(hm)
|
||||||
|
|||||||
@@ -299,6 +299,9 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
|||||||
>100. 上海邑脉科技有限公司
|
>100. 上海邑脉科技有限公司
|
||||||
>101. 上海巨瓴科技有限公司
|
>101. 上海巨瓴科技有限公司
|
||||||
>102. 深圳市兴海物联科技有限公司
|
>102. 深圳市兴海物联科技有限公司
|
||||||
|
>103. 爱芯元智半导体股份有限公司
|
||||||
|
>104. 杭州升恒科技有限公司
|
||||||
|
>105. 昆仑万维科技股份有限公司
|
||||||
|
|
||||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/response"
|
"github.com/zeromicro/go-zero/rest/internal/response"
|
||||||
"github.com/zeromicro/go-zero/rest/token"
|
"github.com/zeromicro/go-zero/rest/token"
|
||||||
)
|
)
|
||||||
@@ -100,7 +100,7 @@ func WithUnauthorizedCallback(callback UnauthorizedCallback) AuthorizeOption {
|
|||||||
func detailAuthLog(r *http.Request, reason string) {
|
func detailAuthLog(r *http.Request, reason string) {
|
||||||
// discard dump error, only for debug purpose
|
// discard dump error, only for debug purpose
|
||||||
details, _ := httputil.DumpRequest(r, true)
|
details, _ := httputil.DumpRequest(r, true)
|
||||||
logx.Errorf("authorize failed: %s\n=> %+v", reason, string(details))
|
logc.Errorf(r.Context(), "authorize failed: %s\n=> %+v", reason, string(details))
|
||||||
}
|
}
|
||||||
|
|
||||||
func unauthorized(w http.ResponseWriter, r *http.Request, err error, callback UnauthorizedCallback) {
|
func unauthorized(w http.ResponseWriter, r *http.Request, err error, callback UnauthorizedCallback) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/breaker"
|
"github.com/zeromicro/go-zero/core/breaker"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/stat"
|
"github.com/zeromicro/go-zero/core/stat"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/response"
|
"github.com/zeromicro/go-zero/rest/internal/response"
|
||||||
@@ -22,7 +22,7 @@ func BreakerHandler(method, path string, metrics *stat.Metrics) func(http.Handle
|
|||||||
promise, err := brk.Allow()
|
promise, err := brk.Allow()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.AddDrop()
|
metrics.AddDrop()
|
||||||
logx.Errorf("[http] dropped, %s - %s - %s",
|
logc.Errorf(r.Context(), "[http] dropped, %s - %s - %s",
|
||||||
r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent())
|
r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent())
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/codec"
|
"github.com/zeromicro/go-zero/core/codec"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/security"
|
"github.com/zeromicro/go-zero/rest/internal/security"
|
||||||
)
|
)
|
||||||
@@ -34,11 +34,11 @@ func LimitContentSecurityHandler(limitBytes int64, decrypters map[string]codec.R
|
|||||||
case http.MethodDelete, http.MethodGet, http.MethodPost, http.MethodPut:
|
case http.MethodDelete, http.MethodGet, http.MethodPost, http.MethodPut:
|
||||||
header, err := security.ParseContentSecurity(decrypters, r)
|
header, err := security.ParseContentSecurity(decrypters, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("Signature parse failed, X-Content-Security: %s, error: %s",
|
logc.Errorf(r.Context(), "Signature parse failed, X-Content-Security: %s, error: %s",
|
||||||
r.Header.Get(contentSecurity), err.Error())
|
r.Header.Get(contentSecurity), err.Error())
|
||||||
executeCallbacks(w, r, next, strict, httpx.CodeSignatureInvalidHeader, callbacks)
|
executeCallbacks(w, r, next, strict, httpx.CodeSignatureInvalidHeader, callbacks)
|
||||||
} else if code := security.VerifySignature(r, header, tolerance); code != httpx.CodeSignaturePass {
|
} else if code := security.VerifySignature(r, header, tolerance); code != httpx.CodeSignaturePass {
|
||||||
logx.Errorf("Signature verification failed, X-Content-Security: %s",
|
logc.Errorf(r.Context(), "Signature verification failed, X-Content-Security: %s",
|
||||||
r.Header.Get(contentSecurity))
|
r.Header.Get(contentSecurity))
|
||||||
executeCallbacks(w, r, next, strict, code, callbacks)
|
executeCallbacks(w, r, next, strict, code, callbacks)
|
||||||
} else if r.ContentLength > 0 && header.Encrypted() {
|
} else if r.ContentLength > 0 && header.Encrypted() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@@ -10,7 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/codec"
|
"github.com/zeromicro/go-zero/core/codec"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxBytes = 1 << 20 // 1 MiB
|
const maxBytes = 1 << 20 // 1 MiB
|
||||||
@@ -27,7 +28,7 @@ func LimitCryptionHandler(limitBytes int64, key []byte) func(http.Handler) http.
|
|||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
cw := newCryptionResponseWriter(w)
|
cw := newCryptionResponseWriter(w)
|
||||||
defer cw.flush(key)
|
defer cw.flush(r.Context(), key)
|
||||||
|
|
||||||
if r.ContentLength <= 0 {
|
if r.ContentLength <= 0 {
|
||||||
next.ServeHTTP(cw, r)
|
next.ServeHTTP(cw, r)
|
||||||
@@ -118,7 +119,7 @@ func (w *cryptionResponseWriter) WriteHeader(statusCode int) {
|
|||||||
w.ResponseWriter.WriteHeader(statusCode)
|
w.ResponseWriter.WriteHeader(statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *cryptionResponseWriter) flush(key []byte) {
|
func (w *cryptionResponseWriter) flush(ctx context.Context, key []byte) {
|
||||||
if w.buf.Len() == 0 {
|
if w.buf.Len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -131,8 +132,8 @@ func (w *cryptionResponseWriter) flush(key []byte) {
|
|||||||
|
|
||||||
body := base64.StdEncoding.EncodeToString(content)
|
body := base64.StdEncoding.EncodeToString(content)
|
||||||
if n, err := io.WriteString(w.ResponseWriter, body); err != nil {
|
if n, err := io.WriteString(w.ResponseWriter, body); err != nil {
|
||||||
logx.Errorf("write response failed, error: %s", err)
|
logc.Errorf(ctx, "write response failed, error: %s", err)
|
||||||
} else if n < len(body) {
|
} else if n < len(body) {
|
||||||
logx.Errorf("actual bytes: %d, written bytes: %d", len(body), n)
|
logc.Errorf(ctx, "actual bytes: %d, written bytes: %d", len(body), n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
@@ -174,7 +175,7 @@ func TestCryptionResponseWriter_Flush(t *testing.T) {
|
|||||||
w := newCryptionResponseWriter(f)
|
w := newCryptionResponseWriter(f)
|
||||||
_, err := w.Write(body)
|
_, err := w.Write(body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
w.flush(aesKey)
|
w.flush(context.Background(), aesKey)
|
||||||
b, err := io.ReadAll(recorder.Body)
|
b, err := io.ReadAll(recorder.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expected, err := codec.EcbEncrypt(aesKey, body)
|
expected, err := codec.EcbEncrypt(aesKey, body)
|
||||||
@@ -191,7 +192,7 @@ func TestCryptionResponseWriter_Flush(t *testing.T) {
|
|||||||
w := newCryptionResponseWriter(f)
|
w := newCryptionResponseWriter(f)
|
||||||
_, err := w.Write(body)
|
_, err := w.Write(body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
w.flush(aesKey)
|
w.flush(context.Background(), aesKey)
|
||||||
b, err := io.ReadAll(recorder.Body)
|
b, err := io.ReadAll(recorder.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expected, err := codec.EcbEncrypt(aesKey, body)
|
expected, err := codec.EcbEncrypt(aesKey, body)
|
||||||
@@ -207,7 +208,7 @@ func TestCryptionResponseWriter_Flush(t *testing.T) {
|
|||||||
w := newCryptionResponseWriter(f)
|
w := newCryptionResponseWriter(f)
|
||||||
_, err := w.Write(body)
|
_, err := w.Write(body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
w.flush(aesKey)
|
w.flush(context.Background(), aesKey)
|
||||||
assert.True(t, strings.Contains(buf.Content(), io.ErrClosedPipe.Error()))
|
assert.True(t, strings.Contains(buf.Content(), io.ErrClosedPipe.Error()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,9 +158,9 @@ func logDetails(r *http.Request, response *detailLoggedResponseWriter, timer *ut
|
|||||||
logger := logx.WithContext(r.Context())
|
logger := logx.WithContext(r.Context())
|
||||||
buf.WriteString(fmt.Sprintf("[HTTP] %s - %d - %s - %s\n=> %s\n",
|
buf.WriteString(fmt.Sprintf("[HTTP] %s - %d - %s - %s\n=> %s\n",
|
||||||
r.Method, code, r.RemoteAddr, timex.ReprOfDuration(duration), dumpRequest(r)))
|
r.Method, code, r.RemoteAddr, timex.ReprOfDuration(duration), dumpRequest(r)))
|
||||||
if duration > defaultSlowThreshold {
|
if duration > slowThreshold.Load() {
|
||||||
logger.Slowf("[HTTP] %s - %d - %s - slowcall(%s)\n=> %s\n", r.Method, code, r.RemoteAddr,
|
logger.Slowf("[HTTP] %s - %d - %s - slowcall(%s)\n=> %s\n", r.Method, code, r.RemoteAddr,
|
||||||
fmt.Sprintf("slowcall(%s)", timex.ReprOfDuration(duration)), dumpRequest(r))
|
timex.ReprOfDuration(duration), dumpRequest(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
body := logs.Flush()
|
body := logs.Flush()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/load"
|
"github.com/zeromicro/go-zero/core/load"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/stat"
|
"github.com/zeromicro/go-zero/core/stat"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/response"
|
"github.com/zeromicro/go-zero/rest/internal/response"
|
||||||
@@ -35,7 +35,7 @@ func SheddingHandler(shedder load.Shedder, metrics *stat.Metrics) func(http.Hand
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.AddDrop()
|
metrics.AddDrop()
|
||||||
sheddingStat.IncrementDrop()
|
sheddingStat.IncrementDrop()
|
||||||
logx.Errorf("[http] dropped, %s - %s - %s",
|
logc.Errorf(r.Context(), "[http] dropped, %s - %s - %s",
|
||||||
r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent())
|
r.RequestURI, httpx.GetRemoteAddr(r), r.UserAgent())
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMetricsInterceptor(t *testing.T) {
|
func TestMetricsInterceptor(t *testing.T) {
|
||||||
c := gomock.NewController(t)
|
|
||||||
defer c.Finish()
|
|
||||||
|
|
||||||
logx.Disable()
|
logx.Disable()
|
||||||
|
|
||||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ func request(r *http.Request, cli client) (*http.Response, error) {
|
|||||||
for i := len(respHandlers) - 1; i >= 0; i-- {
|
for i := len(respHandlers) - 1; i >= 0; i-- {
|
||||||
respHandlers[i](resp, err)
|
respHandlers[i](resp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
span.SetStatus(codes.Error, err.Error())
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/mapping"
|
"github.com/zeromicro/go-zero/core/mapping"
|
||||||
"github.com/zeromicro/go-zero/core/validation"
|
"github.com/zeromicro/go-zero/core/validation"
|
||||||
@@ -33,7 +33,11 @@ var (
|
|||||||
pathKey,
|
pathKey,
|
||||||
mapping.WithStringValues(),
|
mapping.WithStringValues(),
|
||||||
mapping.WithOpaqueKeys())
|
mapping.WithOpaqueKeys())
|
||||||
validator atomic.Value
|
|
||||||
|
// panic: sync/atomic: store of inconsistently typed value into Value
|
||||||
|
// don't use atomic.Value to store the validator, different concrete types still panic
|
||||||
|
validator Validator
|
||||||
|
validatorLock sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validator defines the interface for validating the request.
|
// Validator defines the interface for validating the request.
|
||||||
@@ -65,8 +69,8 @@ func Parse(r *http.Request, v any) error {
|
|||||||
|
|
||||||
if valid, ok := v.(validation.Validator); ok {
|
if valid, ok := v.(validation.Validator); ok {
|
||||||
return valid.Validate()
|
return valid.Validate()
|
||||||
} else if val := validator.Load(); val != nil {
|
} else if val := getValidator(); val != nil {
|
||||||
return val.(Validator).Validate(r, v)
|
return val.Validate(r, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -135,7 +139,15 @@ func ParsePath(r *http.Request, v any) error {
|
|||||||
// The validator is used to validate the request, only called in Parse,
|
// The validator is used to validate the request, only called in Parse,
|
||||||
// not in ParseHeaders, ParseForm, ParseHeader, ParseJsonBody, ParsePath.
|
// not in ParseHeaders, ParseForm, ParseHeader, ParseJsonBody, ParsePath.
|
||||||
func SetValidator(val Validator) {
|
func SetValidator(val Validator) {
|
||||||
validator.Store(val)
|
validatorLock.Lock()
|
||||||
|
defer validatorLock.Unlock()
|
||||||
|
validator = val
|
||||||
|
}
|
||||||
|
|
||||||
|
func getValidator() Validator {
|
||||||
|
validatorLock.RLock()
|
||||||
|
defer validatorLock.RUnlock()
|
||||||
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
func withJsonBody(r *http.Request) bool {
|
func withJsonBody(r *http.Request) bool {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package httpx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -47,6 +48,21 @@ func TestParseForm(t *testing.T) {
|
|||||||
assert.Nil(t, Parse(r, &v))
|
assert.Nil(t, Parse(r, &v))
|
||||||
assert.Equal(t, 0, len(v.NoValue))
|
assert.Equal(t, 0, len(v.NoValue))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names string `form:"names"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?names=1,2,3",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.Equal(t, "1,2,3", v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseFormArray(t *testing.T) {
|
func TestParseFormArray(t *testing.T) {
|
||||||
@@ -88,6 +104,36 @@ func TestParseFormArray(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("slice with empty", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Name []string `form:"name,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{}, v.Name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with empty", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Name []string `form:"name,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?name=",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.Empty(t, v.Name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("slice with empty and non-empty", func(t *testing.T) {
|
t.Run("slice with empty and non-empty", func(t *testing.T) {
|
||||||
var v struct {
|
var v struct {
|
||||||
Name []string `form:"name"`
|
Name []string `form:"name"`
|
||||||
@@ -102,6 +148,154 @@ func TestParseFormArray(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, []string{"1"}, v.Name)
|
assert.ElementsMatch(t, []string{"1"}, v.Name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `form:"names"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?names=1,2,3",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{"1,2,3"}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on combined array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `form:"names"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?names=[1,2,3]&names=4",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{"[1,2,3]", "4"}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on integer array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Numbers []int `form:"numbers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?numbers=1,2,3",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Error(t, Parse(r, &v))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on array format brackets", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Names []string `form:"names"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?names[]=1&names[]=2&names[]=3",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{"1", "2", "3"}, v.Names)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one empty value on integer array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Numbers []int `form:"numbers,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?numbers=",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.Empty(t, v.Numbers)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on integer array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Numbers []int `form:"numbers,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?numbers=&numbers=2",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []int{2}, v.Numbers)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one empty value on float64 array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Numbers []float64 `form:"numbers,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?numbers=",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.Empty(t, v.Numbers)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value on float64 array format", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Numbers []float64 `form:"numbers,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?numbers=&numbers=2",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []float64{2}, v.Numbers)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with one value", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Codes []string `form:"codes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?codes=aaa,bbb,ccc",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{"aaa,bbb,ccc"}, v.Codes)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("slice with multiple values", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Codes []string `form:"codes,arrayComma=false"`
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := http.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/a?codes=aaa,bbb,ccc&codes=ccc,ddd,eee",
|
||||||
|
http.NoBody)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if assert.NoError(t, Parse(r, &v)) {
|
||||||
|
assert.ElementsMatch(t, []string{"aaa,bbb,ccc", "ccc,ddd,eee"}, v.Codes)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseForm_Error(t *testing.T) {
|
func TestParseForm_Error(t *testing.T) {
|
||||||
@@ -350,6 +544,26 @@ func TestParseJsonBody(t *testing.T) {
|
|||||||
assert.Equal(t, "apple", v[0].Name)
|
assert.Equal(t, "apple", v[0].Name)
|
||||||
assert.Equal(t, 18, v[0].Age)
|
assert.Equal(t, 18, v[0].Age)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("bytes field", func(t *testing.T) {
|
||||||
|
type v struct {
|
||||||
|
Signature []byte `json:"signature,optional"`
|
||||||
|
}
|
||||||
|
v1 := v{
|
||||||
|
Signature: []byte{0x01, 0xff, 0x00},
|
||||||
|
}
|
||||||
|
body, _ := json.Marshal(v1)
|
||||||
|
t.Logf("body:%s", string(body))
|
||||||
|
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(string(body)))
|
||||||
|
r.Header.Set(ContentType, header.JsonContentType)
|
||||||
|
var v2 v
|
||||||
|
err := ParseJsonBody(r, &v2)
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Greater(t, len(v2.Signature), 0)
|
||||||
|
}
|
||||||
|
t.Logf("%x", v2.Signature)
|
||||||
|
assert.EqualValues(t, v1.Signature, v2.Signature)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseRequired(t *testing.T) {
|
func TestParseRequired(t *testing.T) {
|
||||||
@@ -528,6 +742,42 @@ func TestCustomUnmarshalerStructRequest(t *testing.T) {
|
|||||||
assert.Equal(t, "hello", v.Foo.Name)
|
assert.Equal(t, "hello", v.Foo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseJsonStringRequest(t *testing.T) {
|
||||||
|
type GoodsInfo struct {
|
||||||
|
Sku int64 `json:"sku,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetReq struct {
|
||||||
|
GoodsList []*GoodsInfo `json:"goods_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
input := `{"goods_list":"[{\"sku\":11},{\"sku\":22}]"}`
|
||||||
|
r := httptest.NewRequest(http.MethodPost, "/a", strings.NewReader(input))
|
||||||
|
r.Header.Set(ContentType, JsonContentType)
|
||||||
|
var v GetReq
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
assert.NoError(t, Parse(r, &v))
|
||||||
|
assert.Equal(t, 2, len(v.GoodsList))
|
||||||
|
assert.ElementsMatch(t, []int64{11, 22}, []int64{v.GoodsList[0].Sku, v.GoodsList[1].Sku})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type valid1 struct{}
|
||||||
|
|
||||||
|
func (v valid1) Validate(*http.Request, any) error { return nil }
|
||||||
|
|
||||||
|
type valid2 struct{}
|
||||||
|
|
||||||
|
func (v valid2) Validate(*http.Request, any) error { return nil }
|
||||||
|
|
||||||
|
func TestSetValidatorTwice(t *testing.T) {
|
||||||
|
// panic: sync/atomic: store of inconsistently typed value into Value
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
SetValidator(valid1{})
|
||||||
|
SetValidator(valid2{})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkParseRaw(b *testing.B) {
|
func BenchmarkParseRaw(b *testing.B) {
|
||||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/errcode"
|
"github.com/zeromicro/go-zero/rest/internal/errcode"
|
||||||
"github.com/zeromicro/go-zero/rest/internal/header"
|
"github.com/zeromicro/go-zero/rest/internal/header"
|
||||||
@@ -119,7 +120,7 @@ func WriteJson(w http.ResponseWriter, code int, v any) {
|
|||||||
// WriteJsonCtx writes v as json string into w with code.
|
// WriteJsonCtx writes v as json string into w with code.
|
||||||
func WriteJsonCtx(ctx context.Context, w http.ResponseWriter, code int, v any) {
|
func WriteJsonCtx(ctx context.Context, w http.ResponseWriter, code int, v any) {
|
||||||
if err := doWriteJson(w, code, v); err != nil {
|
if err := doWriteJson(w, code, v); err != nil {
|
||||||
logx.WithContext(ctx).Error(err)
|
logc.Error(ctx, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,23 @@ package httpx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const xForwardedFor = "X-Forwarded-For"
|
const (
|
||||||
|
xForwardedFor = "X-Forwarded-For"
|
||||||
|
arraySuffix = "[]"
|
||||||
|
// most servers and clients have a limit of 8192 bytes (8 KB)
|
||||||
|
// one parameter at least take 4 chars, for example `?a=b&c=d`
|
||||||
|
maxFormParamCount = 2048
|
||||||
|
)
|
||||||
|
|
||||||
// GetFormValues returns the form values.
|
// GetFormValues returns the form values supporting three array notation formats:
|
||||||
|
// 1. Standard notation: /api?names=alice&names=bob
|
||||||
|
// 2. Comma notation: /api?names=alice,bob
|
||||||
|
// 3. Bracket notation: /api?names[]=alice&names[]=bob
|
||||||
func GetFormValues(r *http.Request) (map[string]any, error) {
|
func GetFormValues(r *http.Request) (map[string]any, error) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -19,16 +30,33 @@ func GetFormValues(r *http.Request) (map[string]any, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var n int
|
||||||
params := make(map[string]any, len(r.Form))
|
params := make(map[string]any, len(r.Form))
|
||||||
for name, values := range r.Form {
|
for name, values := range r.Form {
|
||||||
filtered := make([]string, 0, len(values))
|
filtered := make([]string, 0, len(values))
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
if len(v) > 0 {
|
// ignore empty values, especially for optional int parameters
|
||||||
|
// e.g. /api?ids=
|
||||||
|
// e.g. /api
|
||||||
|
// type Req struct {
|
||||||
|
// IDs []int `form:"ids,optional"`
|
||||||
|
// }
|
||||||
|
if len(v) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if n < maxFormParamCount {
|
||||||
filtered = append(filtered, v)
|
filtered = append(filtered, v)
|
||||||
|
n++
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("too many form values, error: %s", r.Form.Encode())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(filtered) > 0 {
|
if len(filtered) > 0 {
|
||||||
|
if strings.HasSuffix(name, arraySuffix) {
|
||||||
|
name = name[:len(name)-2]
|
||||||
|
}
|
||||||
params[name] = filtered
|
params[name] = filtered
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package httpx
|
package httpx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -23,3 +25,23 @@ func TestGetRemoteAddrNoHeader(t *testing.T) {
|
|||||||
|
|
||||||
assert.True(t, len(GetRemoteAddr(r)) == 0)
|
assert.True(t, len(GetRemoteAddr(r)) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFormValues_TooManyValues(t *testing.T) {
|
||||||
|
form := url.Values{}
|
||||||
|
|
||||||
|
// Add more values than the limit
|
||||||
|
for i := 0; i < maxFormParamCount+10; i++ {
|
||||||
|
form.Add("param", fmt.Sprintf("value%d", i))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new request with the form data
|
||||||
|
req, err := http.NewRequest("POST", "/test", strings.NewReader(form.Encode()))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// Set the content type for form data
|
||||||
|
req.Header.Set(ContentType, "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
_, err = GetFormValues(req)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "too many form values")
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/codec"
|
"github.com/zeromicro/go-zero/core/codec"
|
||||||
"github.com/zeromicro/go-zero/core/iox"
|
"github.com/zeromicro/go-zero/core/iox"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ func VerifySignature(r *http.Request, securityHeader *ContentSecurityHeader, tol
|
|||||||
return httpx.CodeSignaturePass
|
return httpx.CodeSignaturePass
|
||||||
}
|
}
|
||||||
|
|
||||||
logx.Infof("signature different, expect: %s, actual: %s",
|
logc.Infof(r.Context(), "signature different, expect: %s, actual: %s",
|
||||||
securityHeader.Signature, actualSignature)
|
securityHeader.Signature, actualSignature)
|
||||||
|
|
||||||
return httpx.CodeSignatureInvalidToken
|
return httpx.CodeSignatureInvalidToken
|
||||||
|
|||||||
@@ -516,28 +516,55 @@ func TestParsePtrInRequestEmpty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseQueryOptional(t *testing.T) {
|
func TestParseQueryOptional(t *testing.T) {
|
||||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
t.Run("optional with string", func(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
router := NewRouter()
|
router := NewRouter()
|
||||||
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
v := struct {
|
v := struct {
|
||||||
Nickname string `form:"nickname"`
|
Nickname string `form:"nickname"`
|
||||||
Zipcode int64 `form:"zipcode,optional"`
|
Zipcode string `form:"zipcode,optional"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
err = httpx.Parse(r, &v)
|
err = httpx.Parse(r, &v)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
_, err = io.WriteString(w, fmt.Sprintf("%s:%d", v.Nickname, v.Zipcode))
|
_, err = io.WriteString(w, fmt.Sprintf("%s:%s", v.Nickname, v.Zipcode))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}))
|
}))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
router.ServeHTTP(rr, r)
|
router.ServeHTTP(rr, r)
|
||||||
|
|
||||||
assert.Equal(t, "whatever:0", rr.Body.String())
|
assert.Equal(t, "whatever:", rr.Body.String())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("optional with int", func(t *testing.T) {
|
||||||
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
router := NewRouter()
|
||||||
|
err = router.Handle(http.MethodGet, "/:name/:year", http.HandlerFunc(
|
||||||
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
v := struct {
|
||||||
|
Nickname string `form:"nickname"`
|
||||||
|
Zipcode int `form:"zipcode,optional"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
err = httpx.Parse(r, &v)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
_, err = io.WriteString(w, fmt.Sprintf("%s:%d", v.Nickname, v.Zipcode))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
router.ServeHTTP(rr, r)
|
||||||
|
|
||||||
|
assert.Equal(t, "whatever:0", rr.Body.String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
|
|||||||
@@ -95,25 +95,6 @@ func (s *Server) Routes() []Route {
|
|||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeHTTP is for test purpose, allow developer to do a unit test with
|
|
||||||
// all defined router without starting an HTTP Server.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// server := MustNewServer(...)
|
|
||||||
// server.addRoute(...) // router a
|
|
||||||
// server.addRoute(...) // router b
|
|
||||||
// server.addRoute(...) // router c
|
|
||||||
//
|
|
||||||
// r, _ := http.NewRequest(...)
|
|
||||||
// w := httptest.NewRecorder(...)
|
|
||||||
// server.ServeHTTP(w, r)
|
|
||||||
// // verify the response
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
s.ngin.bindRoutes(s.router)
|
|
||||||
s.router.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts the Server.
|
// Start starts the Server.
|
||||||
// Graceful shutdown is enabled by default.
|
// Graceful shutdown is enabled by default.
|
||||||
// Use proc.SetTimeToForceQuit to customize the graceful shutdown period.
|
// Use proc.SetTimeToForceQuit to customize the graceful shutdown period.
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ func TestWithFileServerMiddleware(t *testing.T) {
|
|||||||
req := httptest.NewRequest(http.MethodGet, tt.requestPath, nil)
|
req := httptest.NewRequest(http.MethodGet, tt.requestPath, nil)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
server.ServeHTTP(rr, req)
|
serve(server, rr, req)
|
||||||
|
|
||||||
assert.Equal(t, tt.expectedStatus, rr.Code)
|
assert.Equal(t, tt.expectedStatus, rr.Code)
|
||||||
if len(tt.expectedContent) > 0 {
|
if len(tt.expectedContent) > 0 {
|
||||||
@@ -458,7 +458,7 @@ Port: 54321
|
|||||||
// we would need to verify the behavior here. Since we don't have
|
// we would need to verify the behavior here. Since we don't have
|
||||||
// direct access to headers, we'll mock newCorsRouter to capture it.
|
// direct access to headers, we'll mock newCorsRouter to capture it.
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
svr.ServeHTTP(w, httptest.NewRequest(http.MethodOptions, "/", nil))
|
serve(svr, w, httptest.NewRequest(http.MethodOptions, "/", nil))
|
||||||
|
|
||||||
vals := w.Header().Values("Access-Control-Allow-Headers")
|
vals := w.Header().Values("Access-Control-Allow-Headers")
|
||||||
respHeaders := make(map[string]struct{})
|
respHeaders := make(map[string]struct{})
|
||||||
@@ -748,7 +748,7 @@ Port: 54321
|
|||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
req, _ := http.NewRequest("GET", test.path, nil)
|
req, _ := http.NewRequest("GET", test.path, nil)
|
||||||
svr.ServeHTTP(w, req)
|
serve(svr, w, req)
|
||||||
assert.Equal(t, test.code, w.Code)
|
assert.Equal(t, test.code, w.Code)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -765,6 +765,25 @@ func TestServerEmbedFileSystem(t *testing.T) {
|
|||||||
req, err := http.NewRequest(http.MethodGet, "/assets/sample.txt", http.NoBody)
|
req, err := http.NewRequest(http.MethodGet, "/assets/sample.txt", http.NoBody)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
server.ServeHTTP(rr, req)
|
serve(server, rr, req)
|
||||||
assert.Equal(t, sampleContent, rr.Body.String())
|
assert.Equal(t, sampleContent, rr.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// serve is for test purpose, allow developer to do a unit test with
|
||||||
|
// all defined router without starting an HTTP Server.
|
||||||
|
//
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// server := MustNewServer(...)
|
||||||
|
// server.addRoute(...) // router a
|
||||||
|
// server.addRoute(...) // router b
|
||||||
|
// server.addRoute(...) // router c
|
||||||
|
//
|
||||||
|
// r, _ := http.NewRequest(...)
|
||||||
|
// w := httptest.NewRecorder(...)
|
||||||
|
// serve(server, w, r)
|
||||||
|
// // verify the response
|
||||||
|
func serve(s *Server, w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.ngin.bindRoutes(s.router)
|
||||||
|
s.router.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ FROM golang:alpine AS builder
|
|||||||
LABEL stage=gobuilder
|
LABEL stage=gobuilder
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ENV GOPROXY=https://goproxy.cn,direct
|
# if you are in China, you can use the following command to speed up the download
|
||||||
|
# ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ func init() {
|
|||||||
goCmdFlags.StringVar(&gogen.VarStringHome, "home")
|
goCmdFlags.StringVar(&gogen.VarStringHome, "home")
|
||||||
goCmdFlags.StringVar(&gogen.VarStringRemote, "remote")
|
goCmdFlags.StringVar(&gogen.VarStringRemote, "remote")
|
||||||
goCmdFlags.StringVar(&gogen.VarStringBranch, "branch")
|
goCmdFlags.StringVar(&gogen.VarStringBranch, "branch")
|
||||||
|
goCmdFlags.BoolVar(&gogen.VarBoolWithTest, "test")
|
||||||
goCmdFlags.StringVarWithDefaultValue(&gogen.VarStringStyle, "style", config.DefaultFormat)
|
goCmdFlags.StringVarWithDefaultValue(&gogen.VarStringStyle, "style", config.DefaultFormat)
|
||||||
|
|
||||||
javaCmdFlags.StringVar(&javagen.VarStringDir, "dir")
|
javaCmdFlags.StringVar(&javagen.VarStringDir, "dir")
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ const (
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../data/tokens.dart';
|
import '../data/tokens.dart';
|
||||||
|
|
||||||
/// 保存tokens到本地
|
/// store tokens to local
|
||||||
///
|
///
|
||||||
/// 传入null则删除本地tokens
|
/// pass null will clean local stored tokens
|
||||||
/// 返回:true:设置成功 false:设置失败
|
/// returns true if success, otherwise false
|
||||||
Future<bool> setTokens(Tokens tokens) async {
|
Future<bool> setTokens(Tokens tokens) async {
|
||||||
var sp = await SharedPreferences.getInstance();
|
var sp = await SharedPreferences.getInstance();
|
||||||
if (tokens == null) {
|
if (tokens == null) {
|
||||||
@@ -23,9 +23,9 @@ Future<bool> setTokens(Tokens tokens) async {
|
|||||||
return await sp.setString('tokens', jsonEncode(tokens.toJson()));
|
return await sp.setString('tokens', jsonEncode(tokens.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 获取本地存储的tokens
|
/// get local stored tokens
|
||||||
///
|
///
|
||||||
/// 如果没有,则返回null
|
/// if no, returns null
|
||||||
Future<Tokens> getTokens() async {
|
Future<Tokens> getTokens() async {
|
||||||
try {
|
try {
|
||||||
var sp = await SharedPreferences.getInstance();
|
var sp = await SharedPreferences.getInstance();
|
||||||
@@ -82,7 +82,8 @@ func genVars(dir string, isLegacy bool, scheme string, hostname string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !fileExists(dir + "vars.dart") {
|
if !fileExists(dir + "vars.dart") {
|
||||||
err = os.WriteFile(dir+"vars.dart", []byte(fmt.Sprintf(`const serverHost='%s://%s';`, scheme, hostname)), 0o644)
|
err = os.WriteFile(dir+"vars.dart", []byte(fmt.Sprintf(`const serverHost='%s://%s';`,
|
||||||
|
scheme, hostname)), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ var (
|
|||||||
// VarStringBranch describes the branch.
|
// VarStringBranch describes the branch.
|
||||||
VarStringBranch string
|
VarStringBranch string
|
||||||
// VarStringStyle describes the style of output files.
|
// VarStringStyle describes the style of output files.
|
||||||
VarStringStyle string
|
VarStringStyle string
|
||||||
|
VarBoolWithTest bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoCommand gen go project files from command line
|
// GoCommand gen go project files from command line
|
||||||
@@ -49,6 +50,7 @@ func GoCommand(_ *cobra.Command, _ []string) error {
|
|||||||
home := VarStringHome
|
home := VarStringHome
|
||||||
remote := VarStringRemote
|
remote := VarStringRemote
|
||||||
branch := VarStringBranch
|
branch := VarStringBranch
|
||||||
|
withTest := VarBoolWithTest
|
||||||
if len(remote) > 0 {
|
if len(remote) > 0 {
|
||||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||||
if len(repo) > 0 {
|
if len(repo) > 0 {
|
||||||
@@ -66,11 +68,11 @@ func GoCommand(_ *cobra.Command, _ []string) error {
|
|||||||
return errors.New("missing -dir")
|
return errors.New("missing -dir")
|
||||||
}
|
}
|
||||||
|
|
||||||
return DoGenProject(apiFile, dir, namingStyle)
|
return DoGenProject(apiFile, dir, namingStyle, withTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoGenProject gen go project files with api file
|
// DoGenProject gen go project files with api file
|
||||||
func DoGenProject(apiFile, dir, style string) error {
|
func DoGenProject(apiFile, dir, style string, withTest bool) error {
|
||||||
api, err := parser.Parse(apiFile)
|
api, err := parser.Parse(apiFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -100,6 +102,10 @@ func DoGenProject(apiFile, dir, style string) error {
|
|||||||
logx.Must(genHandlers(dir, rootPkg, cfg, api))
|
logx.Must(genHandlers(dir, rootPkg, cfg, api))
|
||||||
logx.Must(genLogic(dir, rootPkg, cfg, api))
|
logx.Must(genLogic(dir, rootPkg, cfg, api))
|
||||||
logx.Must(genMiddleware(dir, cfg, api))
|
logx.Must(genMiddleware(dir, cfg, api))
|
||||||
|
if withTest {
|
||||||
|
logx.Must(genHandlersTest(dir, rootPkg, cfg, api))
|
||||||
|
logx.Must(genLogicTest(dir, rootPkg, cfg, api))
|
||||||
|
}
|
||||||
|
|
||||||
if err := backupAndSweep(apiFile); err != nil {
|
if err := backupAndSweep(apiFile); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ func validateWithCamel(t *testing.T, api, camel string) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = initMod(dir)
|
err = initMod(dir)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = DoGenProject(api, dir, camel)
|
err = DoGenProject(api, dir, camel, true)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
if strings.HasSuffix(path, ".go") {
|
if strings.HasSuffix(path, ".go") {
|
||||||
|
|||||||
80
tools/goctl/api/gogen/genhandlerstest.go
Normal file
80
tools/goctl/api/gogen/genhandlerstest.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package gogen
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed handler_test.tpl
|
||||||
|
var handlerTestTemplate string
|
||||||
|
|
||||||
|
func genHandlerTest(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
|
||||||
|
handler := getHandlerName(route)
|
||||||
|
handlerPath := getHandlerFolderPath(group, route)
|
||||||
|
pkgName := handlerPath[strings.LastIndex(handlerPath, "/")+1:]
|
||||||
|
logicName := defaultLogicPackage
|
||||||
|
if handlerPath != handlerDir {
|
||||||
|
handler = strings.Title(handler)
|
||||||
|
logicName = pkgName
|
||||||
|
}
|
||||||
|
filename, err := format.FileNamingFormat(cfg.NamingFormat, handler)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return genFile(fileGenConfig{
|
||||||
|
dir: dir,
|
||||||
|
subdir: getHandlerFolderPath(group, route),
|
||||||
|
filename: filename + "_test.go",
|
||||||
|
templateName: "handlerTestTemplate",
|
||||||
|
category: category,
|
||||||
|
templateFile: handlerTestTemplateFile,
|
||||||
|
builtinTemplate: handlerTestTemplate,
|
||||||
|
data: map[string]any{
|
||||||
|
"PkgName": pkgName,
|
||||||
|
"ImportPackages": genHandlerTestImports(group, route, rootPkg),
|
||||||
|
"HandlerName": handler,
|
||||||
|
"RequestType": util.Title(route.RequestTypeName()),
|
||||||
|
"ResponseType": util.Title(route.ResponseTypeName()),
|
||||||
|
"LogicName": logicName,
|
||||||
|
"LogicType": strings.Title(getLogicName(route)),
|
||||||
|
"Call": strings.Title(strings.TrimSuffix(handler, "Handler")),
|
||||||
|
"HasResp": len(route.ResponseTypeName()) > 0,
|
||||||
|
"HasRequest": len(route.RequestTypeName()) > 0,
|
||||||
|
"HasDoc": len(route.JoinedDoc()) > 0,
|
||||||
|
"Doc": getDoc(route.JoinedDoc()),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func genHandlersTest(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||||
|
for _, group := range api.Service.Groups {
|
||||||
|
for _, route := range group.Routes {
|
||||||
|
if err := genHandlerTest(dir, rootPkg, cfg, group, route); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func genHandlerTestImports(group spec.Group, route spec.Route, parentPkg string) string {
|
||||||
|
imports := []string{
|
||||||
|
//fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, getLogicFolderPath(group, route))),
|
||||||
|
fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir)),
|
||||||
|
fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, configDir)),
|
||||||
|
}
|
||||||
|
if len(route.RequestTypeName()) > 0 {
|
||||||
|
imports = append(imports, fmt.Sprintf("\"%s\"\n", pathx.JoinPackages(parentPkg, typesDir)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(imports, "\n\t")
|
||||||
|
}
|
||||||
90
tools/goctl/api/gogen/genlogictest.go
Normal file
90
tools/goctl/api/gogen/genlogictest.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package gogen
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed logic_test.tpl
|
||||||
|
var logicTestTemplate string
|
||||||
|
|
||||||
|
func genLogicTest(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||||
|
for _, g := range api.Service.Groups {
|
||||||
|
for _, r := range g.Routes {
|
||||||
|
err := genLogicTestByRoute(dir, rootPkg, cfg, g, r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func genLogicTestByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
|
||||||
|
logic := getLogicName(route)
|
||||||
|
goFile, err := format.FileNamingFormat(cfg.NamingFormat, logic)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
imports := genLogicTestImports(route, rootPkg)
|
||||||
|
var responseString string
|
||||||
|
var returnString string
|
||||||
|
var requestString string
|
||||||
|
var requestType string
|
||||||
|
if len(route.ResponseTypeName()) > 0 {
|
||||||
|
resp := responseGoTypeName(route, typesPacket)
|
||||||
|
responseString = "(resp " + resp + ", err error)"
|
||||||
|
returnString = "return"
|
||||||
|
} else {
|
||||||
|
responseString = "error"
|
||||||
|
returnString = "return nil"
|
||||||
|
}
|
||||||
|
if len(route.RequestTypeName()) > 0 {
|
||||||
|
requestString = "req *" + requestGoTypeName(route, typesPacket)
|
||||||
|
requestType = requestGoTypeName(route, typesPacket)
|
||||||
|
}
|
||||||
|
|
||||||
|
subDir := getLogicFolderPath(group, route)
|
||||||
|
return genFile(fileGenConfig{
|
||||||
|
dir: dir,
|
||||||
|
subdir: subDir,
|
||||||
|
filename: goFile + "_test.go",
|
||||||
|
templateName: "logicTestTemplate",
|
||||||
|
category: category,
|
||||||
|
templateFile: logicTestTemplateFile,
|
||||||
|
builtinTemplate: logicTestTemplate,
|
||||||
|
data: map[string]any{
|
||||||
|
"pkgName": subDir[strings.LastIndex(subDir, "/")+1:],
|
||||||
|
"imports": imports,
|
||||||
|
"logic": strings.Title(logic),
|
||||||
|
"function": strings.Title(strings.TrimSuffix(logic, "Logic")),
|
||||||
|
"responseType": responseString,
|
||||||
|
"returnString": returnString,
|
||||||
|
"request": requestString,
|
||||||
|
"hasRequest": len(requestType) > 0,
|
||||||
|
"hasResponse": len(route.ResponseTypeName()) > 0,
|
||||||
|
"requestType": requestType,
|
||||||
|
"hasDoc": len(route.JoinedDoc()) > 0,
|
||||||
|
"doc": getDoc(route.JoinedDoc()),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func genLogicTestImports(route spec.Route, parentPkg string) string {
|
||||||
|
var imports []string
|
||||||
|
//imports = append(imports, `"context"`+"\n")
|
||||||
|
imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir)))
|
||||||
|
imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, configDir)))
|
||||||
|
if shallImportTypesPackage(route) {
|
||||||
|
imports = append(imports, fmt.Sprintf("\"%s\"\n", pathx.JoinPackages(parentPkg, typesDir)))
|
||||||
|
}
|
||||||
|
//imports = append(imports, fmt.Sprintf("\"%s/core/logx\"", vars.ProjectOpenSourceURL))
|
||||||
|
return strings.Join(imports, "\n\t")
|
||||||
|
}
|
||||||
@@ -139,12 +139,7 @@ rest.WithPrefix("%s"),`, g.prefix)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// why we check this, maybe some users set value 1, it's 1ns, not 1s.
|
timeout = fmt.Sprintf("\n rest.WithTimeout(%s),", formatDuration(duration))
|
||||||
if duration < timeoutThreshold {
|
|
||||||
return fmt.Errorf("timeout should not less than 1ms, now %v", duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout = fmt.Sprintf("\n rest.WithTimeout(%d * time.Millisecond),", duration.Milliseconds())
|
|
||||||
hasTimeout = true
|
hasTimeout = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +206,16 @@ rest.WithPrefix("%s"),`, g.prefix)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatDuration(duration time.Duration) string {
|
||||||
|
if duration < time.Microsecond {
|
||||||
|
return fmt.Sprintf("%d * time.Nanosecond", duration.Nanoseconds())
|
||||||
|
}
|
||||||
|
if duration < time.Millisecond {
|
||||||
|
return fmt.Sprintf("%d * time.Microsecond", duration.Microseconds())
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%d * time.Millisecond", duration.Milliseconds())
|
||||||
|
}
|
||||||
|
|
||||||
func genRouteImports(parentPkg string, api *spec.ApiSpec) string {
|
func genRouteImports(parentPkg string, api *spec.ApiSpec) string {
|
||||||
importSet := collection.NewSet()
|
importSet := collection.NewSet()
|
||||||
importSet.AddStr(fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir)))
|
importSet.AddStr(fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir)))
|
||||||
|
|||||||
27
tools/goctl/api/gogen/genroutes_test.go
Normal file
27
tools/goctl/api/gogen/genroutes_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package gogen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_formatDuration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
duration time.Duration
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{0, "0 * time.Nanosecond"},
|
||||||
|
{time.Nanosecond, "1 * time.Nanosecond"},
|
||||||
|
{100 * time.Nanosecond, "100 * time.Nanosecond"},
|
||||||
|
{500 * time.Microsecond, "500 * time.Microsecond"},
|
||||||
|
{2 * time.Millisecond, "2 * time.Millisecond"},
|
||||||
|
{time.Second, "1000 * time.Millisecond"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result := formatDuration(test.duration)
|
||||||
|
if result != test.expected {
|
||||||
|
t.Errorf("formatDuration(%v) = %v; want %v", test.duration, result, test.expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
tools/goctl/api/gogen/handler_test.tpl
Normal file
81
tools/goctl/api/gogen/handler_test.tpl
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package {{.PkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
{{if .HasRequest}}"encoding/json"{{end}}
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
{{.ImportPackages}}
|
||||||
|
)
|
||||||
|
|
||||||
|
{{if .HasDoc}}{{.Doc}}{{end}}
|
||||||
|
func Test{{.HandlerName}}(t *testing.T) {
|
||||||
|
// new service context
|
||||||
|
c := config.Config{}
|
||||||
|
svcCtx := svc.NewServiceContext(c)
|
||||||
|
// init mock service context here
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
reqBody interface{}
|
||||||
|
wantStatus int
|
||||||
|
wantResp string
|
||||||
|
setupMocks func()
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "invalid request body",
|
||||||
|
reqBody: "invalid",
|
||||||
|
wantStatus: http.StatusBadRequest,
|
||||||
|
wantResp: "unsupported type", // Adjust based on actual error response
|
||||||
|
setupMocks: func() {
|
||||||
|
// No setup needed for this test case
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handler error",
|
||||||
|
{{if .HasRequest}}reqBody: types.{{.RequestType}}{
|
||||||
|
//TODO: add fields here
|
||||||
|
},
|
||||||
|
{{end}}wantStatus: http.StatusBadRequest,
|
||||||
|
wantResp: "error", // Adjust based on actual error response
|
||||||
|
setupMocks: func() {
|
||||||
|
// Mock login logic to return an error
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handler successful",
|
||||||
|
{{if .HasRequest}}reqBody: types.{{.RequestType}}{
|
||||||
|
//TODO: add fields here
|
||||||
|
},
|
||||||
|
{{end}}wantStatus: http.StatusOK,
|
||||||
|
wantResp: `{"code":0,"msg":"success","data":{}}`, // Adjust based on actual success response
|
||||||
|
setupMocks: func() {
|
||||||
|
// Mock login logic to return success
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.setupMocks()
|
||||||
|
var reqBody []byte
|
||||||
|
{{if .HasRequest}}var err error
|
||||||
|
reqBody, err = json.Marshal(tt.reqBody)
|
||||||
|
require.NoError(t, err){{end}}
|
||||||
|
req, err := http.NewRequest("POST", "/ut", bytes.NewBuffer(reqBody))
|
||||||
|
require.NoError(t, err)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
handler := {{.HandlerName}}(svcCtx)
|
||||||
|
handler.ServeHTTP(rr, req)
|
||||||
|
t.Log(rr.Body.String())
|
||||||
|
assert.Equal(t, tt.wantStatus, rr.Code)
|
||||||
|
assert.Contains(t, rr.Body.String(), tt.wantResp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
69
tools/goctl/api/gogen/logic_test.tpl
Normal file
69
tools/goctl/api/gogen/logic_test.tpl
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package {{.pkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
{{.imports}}
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test{{.logic}}_{{.function}}(t *testing.T) {
|
||||||
|
c := config.Config{}
|
||||||
|
mockSvcCtx := svc.NewServiceContext(c)
|
||||||
|
// init mock service context here
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ctx context.Context
|
||||||
|
setupMocks func()
|
||||||
|
{{if .hasRequest}}req *{{.requestType}}{{end}}
|
||||||
|
wantErr bool
|
||||||
|
checkResp func{{if .hasResponse}}{{.responseType}}{{else}}(err error){{end}}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "response error",
|
||||||
|
ctx: context.Background(),
|
||||||
|
setupMocks: func() {
|
||||||
|
// mock data for this test case
|
||||||
|
},
|
||||||
|
{{if .hasRequest}}req: &{{.requestType}}{
|
||||||
|
// TODO: init your request here
|
||||||
|
},{{end}}
|
||||||
|
wantErr: true,
|
||||||
|
checkResp: func{{if .hasResponse}}{{.responseType}}{{else}}(err error){{end}} {
|
||||||
|
// TODO: Add your check logic here
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "successful",
|
||||||
|
ctx: context.Background(),
|
||||||
|
setupMocks: func() {
|
||||||
|
// Mock data for this test case
|
||||||
|
},
|
||||||
|
{{if .hasRequest}}req: &{{.requestType}}{
|
||||||
|
// TODO: init your request here
|
||||||
|
},{{end}}
|
||||||
|
wantErr: false,
|
||||||
|
checkResp: func{{if .hasResponse}}{{.responseType}}{{else}}(err error){{end}} {
|
||||||
|
// TODO: Add your check logic here
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.setupMocks()
|
||||||
|
l := New{{.logic}}(tt.ctx, mockSvcCtx)
|
||||||
|
{{if .hasResponse}}resp, {{end}}err := l.{{.function}}({{if .hasRequest}}tt.req{{end}})
|
||||||
|
if tt.wantErr {
|
||||||
|
assert.Error(t, err)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
{{if .hasResponse}}assert.NotNil(t, resp){{end}}
|
||||||
|
}
|
||||||
|
tt.checkResp({{if .hasResponse}}resp, {{end}}err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,9 @@ const (
|
|||||||
contextTemplateFile = "context.tpl"
|
contextTemplateFile = "context.tpl"
|
||||||
etcTemplateFile = "etc.tpl"
|
etcTemplateFile = "etc.tpl"
|
||||||
handlerTemplateFile = "handler.tpl"
|
handlerTemplateFile = "handler.tpl"
|
||||||
|
handlerTestTemplateFile = "handler_test.tpl"
|
||||||
logicTemplateFile = "logic.tpl"
|
logicTemplateFile = "logic.tpl"
|
||||||
|
logicTestTemplateFile = "logic_test.tpl"
|
||||||
mainTemplateFile = "main.tpl"
|
mainTemplateFile = "main.tpl"
|
||||||
middlewareImplementCodeFile = "middleware.tpl"
|
middlewareImplementCodeFile = "middleware.tpl"
|
||||||
routesTemplateFile = "routes.tpl"
|
routesTemplateFile = "routes.tpl"
|
||||||
@@ -25,7 +27,9 @@ var templates = map[string]string{
|
|||||||
contextTemplateFile: contextTemplate,
|
contextTemplateFile: contextTemplate,
|
||||||
etcTemplateFile: etcTemplate,
|
etcTemplateFile: etcTemplate,
|
||||||
handlerTemplateFile: handlerTemplate,
|
handlerTemplateFile: handlerTemplate,
|
||||||
|
handlerTestTemplateFile: handlerTestTemplate,
|
||||||
logicTemplateFile: logicTemplate,
|
logicTemplateFile: logicTemplate,
|
||||||
|
logicTestTemplateFile: logicTestTemplate,
|
||||||
mainTemplateFile: mainTemplate,
|
mainTemplateFile: mainTemplate,
|
||||||
middlewareImplementCodeFile: middlewareImplementCode,
|
middlewareImplementCodeFile: middlewareImplementCode,
|
||||||
routesTemplateFile: routesTemplate,
|
routesTemplateFile: routesTemplate,
|
||||||
|
|||||||
@@ -83,6 +83,6 @@ func CreateServiceCommand(_ *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gogen.DoGenProject(apiFilePath, abs, VarStringStyle)
|
err = gogen.DoGenProject(apiFilePath, abs, VarStringStyle, false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ type (
|
|||||||
// Member describes the field of a structure
|
// Member describes the field of a structure
|
||||||
Member struct {
|
Member struct {
|
||||||
Name string
|
Name string
|
||||||
// 数据类型字面值,如:string、map[int]string、[]int64、[]*User
|
// data type, for example, string、map[int]string、[]int64、[]*User
|
||||||
Type Type
|
Type Type
|
||||||
Tag string
|
Tag string
|
||||||
Comment string
|
Comment string
|
||||||
// 成员头顶注释说明
|
// document for the field
|
||||||
Docs Doc
|
Docs Doc
|
||||||
IsInline bool
|
IsInline bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Cmd describes a bug command.
|
// Cmd describes a bug command.
|
||||||
var Cmd = cobrax.NewCommand("bug", cobrax.WithRunE(cobra.NoArgs), cobrax.WithArgs(cobra.NoArgs))
|
var Cmd = cobrax.NewCommand("bug", cobrax.WithRunE(runE), cobrax.WithArgs(cobra.NoArgs))
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ if [ -d $WD ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
||||||
execute_command 'export GOPROXY="https://goproxy.cn,direct"'
|
|
||||||
execute_command "export GOBIN=$BIN"
|
execute_command "export GOBIN=$BIN"
|
||||||
|
|
||||||
echo "=======================install goctl============================="
|
echo "=======================install goctl============================="
|
||||||
|
|||||||
@@ -3,30 +3,33 @@ FROM golang:{{.Version}}alpine AS builder
|
|||||||
LABEL stage=gobuilder
|
LABEL stage=gobuilder
|
||||||
|
|
||||||
ENV CGO_ENABLED 0
|
ENV CGO_ENABLED 0
|
||||||
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct
|
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
{{if .HasTimezone}}
|
||||||
{{end}}{{if .HasTimezone}}
|
|
||||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||||
{{end}}
|
{{- end}}
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|
||||||
ADD go.mod .
|
ADD go.mod .
|
||||||
ADD go.sum .
|
ADD go.sum .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
{{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc
|
|
||||||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoMainFrom}}
|
RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoMainFrom}}
|
||||||
|
|
||||||
|
|
||||||
FROM {{.BaseImage}}
|
FROM {{.BaseImage}}
|
||||||
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
{{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}}
|
{{if .HasTimezone -}}
|
||||||
|
COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}}
|
||||||
ENV TZ {{.Timezone}}
|
ENV TZ {{.Timezone}}
|
||||||
{{end}}
|
{{end}}
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}}
|
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}
|
||||||
COPY --from=builder /app/etc /app/etc{{end}}
|
{{if .Argument -}}
|
||||||
|
COPY {{.GoRelPath}}/etc /app/etc
|
||||||
|
{{- end}}
|
||||||
{{if .HasPort}}
|
{{if .HasPort}}
|
||||||
EXPOSE {{.Port}}
|
EXPOSE {{.Port}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Tidy failed"
|
echo "Tidy failed"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Tidy failed"
|
echo "Tidy failed"
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
module github.com/zeromicro/go-zero/tools/goctl
|
module github.com/zeromicro/go-zero/tools/goctl
|
||||||
|
|
||||||
go 1.20
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||||
github.com/emicklei/proto v1.13.2
|
github.com/emicklei/proto v1.14.0
|
||||||
github.com/fatih/structtag v1.2.0
|
github.com/fatih/structtag v1.2.0
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.9.0
|
||||||
github.com/gookit/color v1.5.4
|
github.com/gookit/color v1.5.4
|
||||||
github.com/iancoleman/strcase v0.3.0
|
github.com/iancoleman/strcase v0.3.0
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.9.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.6
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
||||||
github.com/zeromicro/antlr v0.0.1
|
github.com/zeromicro/antlr v0.0.1
|
||||||
github.com/zeromicro/ddl-parser v1.0.5
|
github.com/zeromicro/ddl-parser v1.0.5
|
||||||
github.com/zeromicro/go-zero v1.7.3
|
github.com/zeromicro/go-zero v1.8.0
|
||||||
golang.org/x/text v0.19.0
|
golang.org/x/text v0.22.0
|
||||||
google.golang.org/grpc v1.65.0
|
google.golang.org/grpc v1.65.0
|
||||||
google.golang.org/protobuf v1.35.1
|
google.golang.org/protobuf v1.36.5
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
|
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0 // indirect
|
github.com/alicebob/miniredis/v2 v2.34.0 // indirect
|
||||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec // indirect
|
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
@@ -35,7 +35,7 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||||
github.com/fatih/color v1.17.0 // indirect
|
github.com/fatih/color v1.18.0 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||||
@@ -52,8 +52,8 @@ require (
|
|||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
github.com/jackc/pgx/v5 v5.7.2 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
@@ -93,13 +93,13 @@ require (
|
|||||||
go.uber.org/automaxprocs v1.6.0 // indirect
|
go.uber.org/automaxprocs v1.6.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
go.uber.org/zap v1.24.0 // indirect
|
go.uber.org/zap v1.24.0 // indirect
|
||||||
golang.org/x/crypto v0.28.0 // indirect
|
golang.org/x/crypto v0.32.0 // indirect
|
||||||
golang.org/x/net v0.30.0 // indirect
|
golang.org/x/net v0.34.0 // indirect
|
||||||
golang.org/x/oauth2 v0.21.0 // indirect
|
golang.org/x/oauth2 v0.21.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.11.0 // indirect
|
||||||
golang.org/x/sys v0.26.0 // indirect
|
golang.org/x/sys v0.29.0 // indirect
|
||||||
golang.org/x/term v0.25.0 // indirect
|
golang.org/x/term v0.28.0 // indirect
|
||||||
golang.org/x/time v0.7.0 // indirect
|
golang.org/x/time v0.9.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
|
|||||||
@@ -4,15 +4,18 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
|
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
|
||||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
|
github.com/alicebob/miniredis/v2 v2.34.0 h1:mBFWMaJSNL9RwdGRyEDoAAv8OQc5UlEhLDQggTglU/0=
|
||||||
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
|
github.com/alicebob/miniredis/v2 v2.34.0/go.mod h1:kWShP4b58T1CW0Y5dViCd5ztzrDqRWqM3nksiyXk5s8=
|
||||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
|
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
|
||||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
|
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
|
||||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
|
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -21,7 +24,7 @@ github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr
|
|||||||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
@@ -30,10 +33,10 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
|
|||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||||
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
|
github.com/emicklei/proto v1.14.0 h1:WYxC0OrBuuC+FUCTZvb8+fzEHdZMwLEF+OnVfZA3LXU=
|
||||||
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
github.com/emicklei/proto v1.14.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
||||||
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
||||||
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
@@ -49,9 +52,10 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
|
|||||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
||||||
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
github.com/go-sql-driver/mysql v1.9.0 h1:Y0zIbQXhQKmQgTp44Y1dp3wTXcn804QoTptLZT1vtvo=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.9.0/go.mod h1:pDetrLJeA3oMujJuvXc8RJoasr589B6A9fwzD3QMrqw=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
@@ -68,6 +72,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
|||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||||
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
|
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
|
||||||
@@ -75,6 +80,7 @@ github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/Q
|
|||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
||||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||||
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||||
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||||
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
@@ -83,10 +89,10 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
|||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
|
||||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
|
||||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
@@ -98,11 +104,13 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
|
|||||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
@@ -120,15 +128,19 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
|
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
|
||||||
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
|
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
|
||||||
|
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
|
||||||
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
|
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
|
||||||
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
|
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
||||||
|
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
|
||||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
@@ -140,13 +152,14 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG
|
|||||||
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
||||||
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
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/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
@@ -158,8 +171,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1 h1:+dBg5k7nuTE38VVdoroRsT0Z88fmvdYrI2EjzJst35I=
|
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1 h1:+dBg5k7nuTE38VVdoroRsT0Z88fmvdYrI2EjzJst35I=
|
||||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1/go.mod h1:nmuySobZb4kFgFy6BptpXp/BBw+xFSyvVPP6auoJB4k=
|
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1/go.mod h1:nmuySobZb4kFgFy6BptpXp/BBw+xFSyvVPP6auoJB4k=
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||||
@@ -173,8 +187,8 @@ github.com/zeromicro/antlr v0.0.1 h1:CQpIn/dc0pUjgGQ81y98s/NGOm2Hfru2NNio2I9mQgk
|
|||||||
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
||||||
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
||||||
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||||
github.com/zeromicro/go-zero v1.7.3 h1:yDUQF2DXDhUHc77/NZF6mzsoRPMBfldjPmG2O/ZSzss=
|
github.com/zeromicro/go-zero v1.8.0 h1:4g/8VW+fOyM51HZYPeI3mXIZdEX+Fl6SsdYX2H5PYw4=
|
||||||
github.com/zeromicro/go-zero v1.7.3/go.mod h1:9JIW3gHBGuc9LzvjZnNwINIq9QdiKu3AigajLtkJamQ=
|
github.com/zeromicro/go-zero v1.8.0/go.mod h1:xDBF+/iDzj30zPvu6HNUIbpz1J6+/g3Sx9D/DytJfss=
|
||||||
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
||||||
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
||||||
@@ -208,6 +222,7 @@ go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0
|
|||||||
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
|
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
|
||||||
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
|
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
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.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||||
@@ -215,8 +230,8 @@ go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
|||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@@ -225,16 +240,16 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||||
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
||||||
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -243,23 +258,24 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||||
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
|
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
|
||||||
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -270,12 +286,13 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:
|
|||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||||
|
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
"home": "{{.global.home}}",
|
"home": "{{.global.home}}",
|
||||||
"remote": "{{.global.remote}}",
|
"remote": "{{.global.remote}}",
|
||||||
"branch": "{{.global.branch}}",
|
"branch": "{{.global.branch}}",
|
||||||
"style": "{{.global.style}}"
|
"style": "{{.global.style}}",
|
||||||
|
"test": "Generate test files"
|
||||||
},
|
},
|
||||||
"new": {
|
"new": {
|
||||||
"short": "Fast create api service",
|
"short": "Fast create api service",
|
||||||
@@ -150,6 +151,7 @@
|
|||||||
"short": "Generate mysql model",
|
"short": "Generate mysql model",
|
||||||
"strict": "Generate model in strict mode",
|
"strict": "Generate model in strict mode",
|
||||||
"ignore-columns": "Ignore columns while creating or updating rows",
|
"ignore-columns": "Ignore columns while creating or updating rows",
|
||||||
|
"prefix": "The cache prefix, effective when --cache is true",
|
||||||
"datasource": {
|
"datasource": {
|
||||||
"short": "Generate model from datasource",
|
"short": "Generate model from datasource",
|
||||||
"url": "The data source of database,like \"root:password@tcp(127.0.0.1:3306)/database",
|
"url": "The data source of database,like \"root:password@tcp(127.0.0.1:3306)/database",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildVersion is the version of goctl.
|
// BuildVersion is the version of goctl.
|
||||||
const BuildVersion = "1.7.3"
|
const BuildVersion = "1.7.7"
|
||||||
|
|
||||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
|
|
||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package migrate
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
defaultProxy = "https://goproxy.cn"
|
|
||||||
defaultProxies = []string{defaultProxy}
|
|
||||||
)
|
|
||||||
|
|
||||||
func goProxy() []string {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return defaultProxies
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy, err := execx.Run("go env GOPROXY", wd)
|
|
||||||
if err != nil {
|
|
||||||
return defaultProxies
|
|
||||||
}
|
|
||||||
list := strings.FieldsFunc(proxy, func(r rune) bool {
|
|
||||||
return r == '|' || r == ','
|
|
||||||
})
|
|
||||||
var ret []string
|
|
||||||
for _, item := range list {
|
|
||||||
if len(item) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err = url.Parse(item)
|
|
||||||
if err == nil && !stringx.Contains(ret, item) {
|
|
||||||
ret = append(ret, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !stringx.Contains(ret, defaultProxy) {
|
|
||||||
ret = append(ret, defaultProxy)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
@@ -15,33 +15,29 @@ var client = http.Client{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLatest(repo string, verbose bool) ([]string, error) {
|
func getLatest(repo string, verbose bool) ([]string, error) {
|
||||||
proxies := goProxy()
|
log := func(err error) {
|
||||||
for _, proxy := range proxies {
|
console.Warning("get latest versions failed, error: %+v", err)
|
||||||
if verbose {
|
|
||||||
console.Info("use go proxy %q", proxy)
|
|
||||||
}
|
|
||||||
log := func(err error) {
|
|
||||||
console.Warning("get latest versions failed from proxy %q, error: %+v", proxy, err)
|
|
||||||
}
|
|
||||||
resp, err := client.Get(fmt.Sprintf("%s/%s/@v/list", proxy, repo))
|
|
||||||
if err != nil {
|
|
||||||
log(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
log(fmt.Errorf("%s", resp.Status))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
data, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
versionStr := string(data)
|
|
||||||
versions := strings.Fields(versionStr)
|
|
||||||
return versions, nil
|
|
||||||
}
|
}
|
||||||
return []string{}, nil
|
resp, err := client.Get(fmt.Sprintf("%s/@v/list", repo))
|
||||||
|
if err != nil {
|
||||||
|
log(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
err = fmt.Errorf("%s", resp.Status)
|
||||||
|
log(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
versionStr := string(data)
|
||||||
|
versions := strings.Fields(versionStr)
|
||||||
|
return versions, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ func init() {
|
|||||||
mysqlCmd.PersistentFlags().BoolVar(&command.VarBoolStrict, "strict")
|
mysqlCmd.PersistentFlags().BoolVar(&command.VarBoolStrict, "strict")
|
||||||
mysqlCmd.PersistentFlags().StringSliceVarPWithDefaultValue(&command.VarStringSliceIgnoreColumns,
|
mysqlCmd.PersistentFlags().StringSliceVarPWithDefaultValue(&command.VarStringSliceIgnoreColumns,
|
||||||
"ignore-columns", "i", []string{"create_at", "created_at", "create_time", "update_at", "updated_at", "update_time"})
|
"ignore-columns", "i", []string{"create_at", "created_at", "create_time", "update_at", "updated_at", "update_time"})
|
||||||
|
mysqlCmd.PersistentFlags().StringVarPWithDefaultValue(&command.VarStringCachePrefix, "prefix", "p", "cache")
|
||||||
|
|
||||||
mysqlCmd.AddCommand(datasourceCmd, ddlCmd)
|
mysqlCmd.AddCommand(datasourceCmd, ddlCmd)
|
||||||
pgCmd.AddCommand(pgDatasourceCmd)
|
pgCmd.AddCommand(pgDatasourceCmd)
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ var (
|
|||||||
VarBoolStrict bool
|
VarBoolStrict bool
|
||||||
// VarStringSliceIgnoreColumns represents the columns which are ignored.
|
// VarStringSliceIgnoreColumns represents the columns which are ignored.
|
||||||
VarStringSliceIgnoreColumns []string
|
VarStringSliceIgnoreColumns []string
|
||||||
|
// VarStringCachePrefix describes the prefix of cache.
|
||||||
|
VarStringCachePrefix string
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNotMatched = errors.New("sql not matched")
|
var errNotMatched = errors.New("sql not matched")
|
||||||
@@ -57,6 +59,9 @@ var errNotMatched = errors.New("sql not matched")
|
|||||||
// MysqlDDL generates model code from ddl
|
// MysqlDDL generates model code from ddl
|
||||||
func MysqlDDL(_ *cobra.Command, _ []string) error {
|
func MysqlDDL(_ *cobra.Command, _ []string) error {
|
||||||
migrationnotes.BeforeCommands(VarStringDir, VarStringStyle)
|
migrationnotes.BeforeCommands(VarStringDir, VarStringStyle)
|
||||||
|
if VarBoolCache && len(VarStringCachePrefix) == 0 {
|
||||||
|
return errors.New("cache prefix is empty")
|
||||||
|
}
|
||||||
src := VarStringSrc
|
src := VarStringSrc
|
||||||
dir := VarStringDir
|
dir := VarStringDir
|
||||||
cache := VarBoolCache
|
cache := VarBoolCache
|
||||||
@@ -89,6 +94,7 @@ func MysqlDDL(_ *cobra.Command, _ []string) error {
|
|||||||
database: database,
|
database: database,
|
||||||
strict: VarBoolStrict,
|
strict: VarBoolStrict,
|
||||||
ignoreColumns: mergeColumns(VarStringSliceIgnoreColumns),
|
ignoreColumns: mergeColumns(VarStringSliceIgnoreColumns),
|
||||||
|
prefix: VarStringCachePrefix,
|
||||||
}
|
}
|
||||||
return fromDDL(arg)
|
return fromDDL(arg)
|
||||||
}
|
}
|
||||||
@@ -96,6 +102,9 @@ func MysqlDDL(_ *cobra.Command, _ []string) error {
|
|||||||
// MySqlDataSource generates model code from datasource
|
// MySqlDataSource generates model code from datasource
|
||||||
func MySqlDataSource(_ *cobra.Command, _ []string) error {
|
func MySqlDataSource(_ *cobra.Command, _ []string) error {
|
||||||
migrationnotes.BeforeCommands(VarStringDir, VarStringStyle)
|
migrationnotes.BeforeCommands(VarStringDir, VarStringStyle)
|
||||||
|
if VarBoolCache && len(VarStringCachePrefix) == 0 {
|
||||||
|
return errors.New("cache prefix is empty")
|
||||||
|
}
|
||||||
url := strings.TrimSpace(VarStringURL)
|
url := strings.TrimSpace(VarStringURL)
|
||||||
dir := strings.TrimSpace(VarStringDir)
|
dir := strings.TrimSpace(VarStringDir)
|
||||||
cache := VarBoolCache
|
cache := VarBoolCache
|
||||||
@@ -130,6 +139,7 @@ func MySqlDataSource(_ *cobra.Command, _ []string) error {
|
|||||||
idea: idea,
|
idea: idea,
|
||||||
strict: VarBoolStrict,
|
strict: VarBoolStrict,
|
||||||
ignoreColumns: mergeColumns(VarStringSliceIgnoreColumns),
|
ignoreColumns: mergeColumns(VarStringSliceIgnoreColumns),
|
||||||
|
prefix: VarStringCachePrefix,
|
||||||
}
|
}
|
||||||
return fromMysqlDataSource(arg)
|
return fromMysqlDataSource(arg)
|
||||||
}
|
}
|
||||||
@@ -225,6 +235,7 @@ type ddlArg struct {
|
|||||||
database string
|
database string
|
||||||
strict bool
|
strict bool
|
||||||
ignoreColumns []string
|
ignoreColumns []string
|
||||||
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromDDL(arg ddlArg) error {
|
func fromDDL(arg ddlArg) error {
|
||||||
@@ -243,7 +254,7 @@ func fromDDL(arg ddlArg) error {
|
|||||||
return errNotMatched
|
return errNotMatched
|
||||||
}
|
}
|
||||||
|
|
||||||
generator, err := gen.NewDefaultGenerator(arg.dir, arg.cfg,
|
generator, err := gen.NewDefaultGenerator(arg.prefix, arg.dir, arg.cfg,
|
||||||
gen.WithConsoleOption(log), gen.WithIgnoreColumns(arg.ignoreColumns))
|
gen.WithConsoleOption(log), gen.WithIgnoreColumns(arg.ignoreColumns))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -266,6 +277,7 @@ type dataSourceArg struct {
|
|||||||
cache, idea bool
|
cache, idea bool
|
||||||
strict bool
|
strict bool
|
||||||
ignoreColumns []string
|
ignoreColumns []string
|
||||||
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromMysqlDataSource(arg dataSourceArg) error {
|
func fromMysqlDataSource(arg dataSourceArg) error {
|
||||||
@@ -318,7 +330,7 @@ func fromMysqlDataSource(arg dataSourceArg) error {
|
|||||||
return errors.New("no tables matched")
|
return errors.New("no tables matched")
|
||||||
}
|
}
|
||||||
|
|
||||||
generator, err := gen.NewDefaultGenerator(arg.dir, arg.cfg,
|
generator, err := gen.NewDefaultGenerator(arg.prefix, arg.dir, arg.cfg,
|
||||||
gen.WithConsoleOption(log), gen.WithIgnoreColumns(arg.ignoreColumns))
|
gen.WithConsoleOption(log), gen.WithIgnoreColumns(arg.ignoreColumns))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -369,7 +381,7 @@ func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, c
|
|||||||
return errors.New("no tables matched")
|
return errors.New("no tables matched")
|
||||||
}
|
}
|
||||||
|
|
||||||
generator, err := gen.NewDefaultGenerator(dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns))
|
generator, err := gen.NewDefaultGenerator("", dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user