mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 16:59:59 +08:00
Compare commits
64 Commits
tools/goct
...
v1.7.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cad243905f | ||
|
|
7c8f41d577 | ||
|
|
cbd118d55f | ||
|
|
9d2a1b8b0a | ||
|
|
f6ada979aa | ||
|
|
53a74759a5 | ||
|
|
1940f7bd58 | ||
|
|
18cb3141ba | ||
|
|
f822c9a94f | ||
|
|
1a3dc75874 | ||
|
|
796dd5b6e2 | ||
|
|
94e476ade7 | ||
|
|
2a74996e1b | ||
|
|
f52af1ebf9 | ||
|
|
24450f18bb | ||
|
|
f1a45d8a23 | ||
|
|
9aebba1566 | ||
|
|
4998479f9a | ||
|
|
873d1351ee | ||
|
|
afcbca8f24 | ||
|
|
5b8126c2cf | ||
|
|
4dfaf35151 | ||
|
|
00cd77c92b | ||
|
|
2145a7a93c | ||
|
|
d5302f2dbe | ||
|
|
6181594bc8 | ||
|
|
11c10e51ff | ||
|
|
3f03126d27 | ||
|
|
d43adc2823 | ||
|
|
656222b572 | ||
|
|
077b6072fa | ||
|
|
0cafb1164b | ||
|
|
90afa08367 | ||
|
|
c92f788292 | ||
|
|
e94be9b302 | ||
|
|
e713d9013d | ||
|
|
24d6150073 | ||
|
|
44cddec5c3 | ||
|
|
47d13e5ef8 | ||
|
|
896e1a2abb | ||
|
|
075817a8dd | ||
|
|
29400f6814 | ||
|
|
34f536264f | ||
|
|
9d9c7e0fe0 | ||
|
|
e220d3a4cb | ||
|
|
193dcf90bc | ||
|
|
03756c9166 | ||
|
|
c1f12c5784 | ||
|
|
2883111af5 | ||
|
|
2758c4e842 | ||
|
|
4196ddb3e3 | ||
|
|
e24d797226 | ||
|
|
d4349fa958 | ||
|
|
da2c14d45f | ||
|
|
64e3aeda55 | ||
|
|
dedba17219 | ||
|
|
c6348b9855 | ||
|
|
8689a6247e | ||
|
|
ff6ee25d23 | ||
|
|
5213243bbb | ||
|
|
2588a36555 | ||
|
|
c2421beb25 | ||
|
|
dfe8a81c76 | ||
|
|
ee643a945e |
8
.github/workflows/go.yml
vendored
8
.github/workflows/go.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version-file: go.mod
|
||||
check-latest: true
|
||||
cache: true
|
||||
id: go
|
||||
@@ -40,7 +40,7 @@ jobs:
|
||||
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
|
||||
- name: Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
|
||||
test-win:
|
||||
name: Windows
|
||||
@@ -52,8 +52,8 @@ jobs:
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
# use 1.20 to guarantee Go 1.20 compatibility
|
||||
go-version: '1.20'
|
||||
# make sure Go version compatible with go-zero
|
||||
go-version-file: go.mod
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
goversion: "https://dl.google.com/go/go1.19.13.linux-amd64.tar.gz"
|
||||
goversion: "https://dl.google.com/go/go1.20.14.linux-amd64.tar.gz"
|
||||
project_path: "tools/goctl"
|
||||
binary_name: "goctl"
|
||||
extra_files: tools/goctl/readme.md tools/goctl/readme-cn.md
|
||||
@@ -189,7 +189,7 @@ func buildFieldsInfo(tp reflect.Type, fullName string) (*fieldInfo, error) {
|
||||
switch tp.Kind() {
|
||||
case reflect.Struct:
|
||||
return buildStructFieldsInfo(tp, fullName)
|
||||
case reflect.Array, reflect.Slice:
|
||||
case reflect.Array, reflect.Slice, reflect.Map:
|
||||
return buildFieldsInfo(mapping.Deref(tp.Elem()), fullName)
|
||||
case reflect.Chan, reflect.Func:
|
||||
return nil, fmt.Errorf("unsupported type: %s", tp.Kind())
|
||||
@@ -332,6 +332,8 @@ func toLowerCaseKeyMap(m map[string]any, info *fieldInfo) map[string]any {
|
||||
res[lk] = toLowerCaseInterface(v, ti)
|
||||
} else if info.mapField != nil {
|
||||
res[k] = toLowerCaseInterface(v, info.mapField)
|
||||
} else if vv, ok := v.(map[string]any); ok {
|
||||
res[k] = toLowerCaseKeyMap(vv, info)
|
||||
} else {
|
||||
res[k] = v
|
||||
}
|
||||
|
||||
@@ -1192,6 +1192,29 @@ Email = "bar"`)
|
||||
assert.Len(t, c.Value, 2)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multi layer map", func(t *testing.T) {
|
||||
type Value struct {
|
||||
User struct {
|
||||
Name string
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Value map[string]map[string]Value
|
||||
}
|
||||
|
||||
var input = []byte(`
|
||||
[Value.first.User1.User]
|
||||
Name = "foo"
|
||||
[Value.second.User2.User]
|
||||
Name = "bar"
|
||||
`)
|
||||
var c Config
|
||||
if assert.NoError(t, LoadFromTomlBytes(input, &c)) {
|
||||
assert.Len(t, c.Value, 2)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_getFullName(t *testing.T) {
|
||||
|
||||
200
core/configcenter/configurator.go
Normal file
200
core/configcenter/configurator.go
Normal file
@@ -0,0 +1,200 @@
|
||||
package configurator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/configcenter/subscriber"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/mapping"
|
||||
"github.com/zeromicro/go-zero/core/threading"
|
||||
)
|
||||
|
||||
var (
|
||||
errEmptyConfig = errors.New("empty config value")
|
||||
errMissingUnmarshalerType = errors.New("missing unmarshaler type")
|
||||
)
|
||||
|
||||
// Configurator is the interface for configuration center.
|
||||
type Configurator[T any] interface {
|
||||
// GetConfig returns the subscription value.
|
||||
GetConfig() (T, error)
|
||||
// AddListener adds a listener to the subscriber.
|
||||
AddListener(listener func())
|
||||
}
|
||||
|
||||
type (
|
||||
// Config is the configuration for Configurator.
|
||||
Config struct {
|
||||
// Type is the value type, yaml, json or toml.
|
||||
Type string `json:",default=yaml,options=[yaml,json,toml]"`
|
||||
// Log is the flag to control logging.
|
||||
Log bool `json:",default=true"`
|
||||
}
|
||||
|
||||
configCenter[T any] struct {
|
||||
conf Config
|
||||
unmarshaler LoaderFn
|
||||
subscriber subscriber.Subscriber
|
||||
listeners []func()
|
||||
lock sync.Mutex
|
||||
snapshot atomic.Value
|
||||
}
|
||||
|
||||
value[T any] struct {
|
||||
data string
|
||||
marshalData T
|
||||
err error
|
||||
}
|
||||
)
|
||||
|
||||
// Configurator is the interface for configuration center.
|
||||
var _ Configurator[any] = (*configCenter[any])(nil)
|
||||
|
||||
// MustNewConfigCenter returns a Configurator, exits on errors.
|
||||
func MustNewConfigCenter[T any](c Config, subscriber subscriber.Subscriber) Configurator[T] {
|
||||
cc, err := NewConfigCenter[T](c, subscriber)
|
||||
logx.Must(err)
|
||||
return cc
|
||||
}
|
||||
|
||||
// NewConfigCenter returns a Configurator.
|
||||
func NewConfigCenter[T any](c Config, subscriber subscriber.Subscriber) (Configurator[T], error) {
|
||||
unmarshaler, ok := Unmarshaler(strings.ToLower(c.Type))
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown format: %s", c.Type)
|
||||
}
|
||||
|
||||
cc := &configCenter[T]{
|
||||
conf: c,
|
||||
unmarshaler: unmarshaler,
|
||||
subscriber: subscriber,
|
||||
}
|
||||
|
||||
if err := cc.loadConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := cc.subscriber.AddListener(cc.onChange); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := cc.GetConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
// AddListener adds listener to s.
|
||||
func (c *configCenter[T]) AddListener(listener func()) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.listeners = append(c.listeners, listener)
|
||||
}
|
||||
|
||||
// GetConfig return structured config.
|
||||
func (c *configCenter[T]) GetConfig() (T, error) {
|
||||
v := c.value()
|
||||
if v == nil || len(v.data) == 0 {
|
||||
var empty T
|
||||
return empty, errEmptyConfig
|
||||
}
|
||||
|
||||
return v.marshalData, v.err
|
||||
}
|
||||
|
||||
// Value returns the subscription value.
|
||||
func (c *configCenter[T]) Value() string {
|
||||
v := c.value()
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
return v.data
|
||||
}
|
||||
|
||||
func (c *configCenter[T]) loadConfig() error {
|
||||
v, err := c.subscriber.Value()
|
||||
if err != nil {
|
||||
if c.conf.Log {
|
||||
logx.Errorf("ConfigCenter loads changed configuration, error: %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if c.conf.Log {
|
||||
logx.Infof("ConfigCenter loads changed configuration, content [%s]", v)
|
||||
}
|
||||
|
||||
c.snapshot.Store(c.genValue(v))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *configCenter[T]) onChange() {
|
||||
if err := c.loadConfig(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.lock.Lock()
|
||||
listeners := make([]func(), len(c.listeners))
|
||||
copy(listeners, c.listeners)
|
||||
c.lock.Unlock()
|
||||
|
||||
for _, l := range listeners {
|
||||
threading.GoSafe(l)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configCenter[T]) value() *value[T] {
|
||||
content := c.snapshot.Load()
|
||||
if content == nil {
|
||||
return nil
|
||||
}
|
||||
return content.(*value[T])
|
||||
}
|
||||
|
||||
func (c *configCenter[T]) genValue(data string) *value[T] {
|
||||
v := &value[T]{
|
||||
data: data,
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
t := reflect.TypeOf(v.marshalData)
|
||||
// if the type is nil, it means that the user has not set the type of the configuration.
|
||||
if t == nil {
|
||||
v.err = errMissingUnmarshalerType
|
||||
return v
|
||||
}
|
||||
|
||||
t = mapping.Deref(t)
|
||||
switch t.Kind() {
|
||||
case reflect.Struct, reflect.Array, reflect.Slice:
|
||||
if err := c.unmarshaler([]byte(data), &v.marshalData); err != nil {
|
||||
v.err = err
|
||||
if c.conf.Log {
|
||||
logx.Errorf("ConfigCenter unmarshal configuration failed, err: %+v, content [%s]",
|
||||
err.Error(), data)
|
||||
}
|
||||
}
|
||||
case reflect.String:
|
||||
if str, ok := any(data).(T); ok {
|
||||
v.marshalData = str
|
||||
} else {
|
||||
v.err = errMissingUnmarshalerType
|
||||
}
|
||||
default:
|
||||
if c.conf.Log {
|
||||
logx.Errorf("ConfigCenter unmarshal configuration missing unmarshaler for type: %s, content [%s]",
|
||||
t.Kind(), data)
|
||||
}
|
||||
v.err = errMissingUnmarshalerType
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
233
core/configcenter/configurator_test.go
Normal file
233
core/configcenter/configurator_test.go
Normal file
@@ -0,0 +1,233 @@
|
||||
package configurator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewConfigCenter(t *testing.T) {
|
||||
_, err := NewConfigCenter[any](Config{
|
||||
Log: true,
|
||||
}, &mockSubscriber{})
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = NewConfigCenter[any](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, &mockSubscriber{})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestConfigCenter_GetConfig(t *testing.T) {
|
||||
mock := &mockSubscriber{}
|
||||
type Data struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
mock.v = `{"name": "go-zero"}`
|
||||
c1, err := NewConfigCenter[Data](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, err := c1.GetConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "go-zero", data.Name)
|
||||
|
||||
mock.v = `{"name": "111"}`
|
||||
c2, err := NewConfigCenter[Data](Config{Type: "json"}, mock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
mock.v = `{}`
|
||||
c3, err := NewConfigCenter[string](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.NoError(t, err)
|
||||
_, err = c3.GetConfig()
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, err = c2.GetConfig()
|
||||
assert.NoError(t, err)
|
||||
|
||||
mock.lisErr = errors.New("mock error")
|
||||
_, err = NewConfigCenter[Data](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestConfigCenter_onChange(t *testing.T) {
|
||||
mock := &mockSubscriber{}
|
||||
type Data struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
mock.v = `{"name": "go-zero"}`
|
||||
c1, err := NewConfigCenter[Data](Config{Type: "json", Log: true}, mock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, err := c1.GetConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "go-zero", data.Name)
|
||||
|
||||
mock.v = `{"name": "go-zero2"}`
|
||||
mock.change()
|
||||
|
||||
data, err = c1.GetConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "go-zero2", data.Name)
|
||||
|
||||
mock.valErr = errors.New("mock error")
|
||||
_, err = NewConfigCenter[Data](Config{Type: "json", Log: false}, mock)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestConfigCenter_Value(t *testing.T) {
|
||||
mock := &mockSubscriber{}
|
||||
mock.v = "1234"
|
||||
|
||||
c, err := NewConfigCenter[string](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
cc := c.(*configCenter[string])
|
||||
|
||||
assert.Equal(t, cc.Value(), "1234")
|
||||
|
||||
mock.valErr = errors.New("mock error")
|
||||
|
||||
_, err = NewConfigCenter[any](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestConfigCenter_AddListener(t *testing.T) {
|
||||
mock := &mockSubscriber{}
|
||||
mock.v = "1234"
|
||||
c, err := NewConfigCenter[string](Config{
|
||||
Type: "json",
|
||||
Log: true,
|
||||
}, mock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
cc := c.(*configCenter[string])
|
||||
var a, b int
|
||||
var mutex sync.Mutex
|
||||
cc.AddListener(func() {
|
||||
mutex.Lock()
|
||||
a = 1
|
||||
mutex.Unlock()
|
||||
})
|
||||
cc.AddListener(func() {
|
||||
mutex.Lock()
|
||||
b = 2
|
||||
mutex.Unlock()
|
||||
})
|
||||
|
||||
assert.Equal(t, 2, len(cc.listeners))
|
||||
|
||||
mock.change()
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
mutex.Lock()
|
||||
assert.Equal(t, 1, a)
|
||||
assert.Equal(t, 2, b)
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
func TestConfigCenter_genValue(t *testing.T) {
|
||||
t.Run("data is empty", func(t *testing.T) {
|
||||
c := &configCenter[string]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue("")
|
||||
assert.Equal(t, "", v.data)
|
||||
})
|
||||
|
||||
t.Run("invalid template type", func(t *testing.T) {
|
||||
c := &configCenter[any]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue("xxxx")
|
||||
assert.Equal(t, errMissingUnmarshalerType, v.err)
|
||||
})
|
||||
|
||||
t.Run("unsupported template type", func(t *testing.T) {
|
||||
c := &configCenter[int]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue("1")
|
||||
assert.Equal(t, errMissingUnmarshalerType, v.err)
|
||||
})
|
||||
|
||||
t.Run("supported template string type", func(t *testing.T) {
|
||||
c := &configCenter[string]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue("12345")
|
||||
assert.NoError(t, v.err)
|
||||
assert.Equal(t, "12345", v.data)
|
||||
})
|
||||
|
||||
t.Run("unmarshal fail", func(t *testing.T) {
|
||||
c := &configCenter[struct {
|
||||
Name string `json:"name"`
|
||||
}]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue(`{"name":"new name}`)
|
||||
assert.Equal(t, `{"name":"new name}`, v.data)
|
||||
assert.Error(t, v.err)
|
||||
})
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
c := &configCenter[struct {
|
||||
Name string `json:"name"`
|
||||
}]{
|
||||
unmarshaler: registry.unmarshalers["json"],
|
||||
conf: Config{Log: true},
|
||||
}
|
||||
v := c.genValue(`{"name":"new name"}`)
|
||||
assert.Equal(t, `{"name":"new name"}`, v.data)
|
||||
assert.Equal(t, "new name", v.marshalData.Name)
|
||||
assert.NoError(t, v.err)
|
||||
})
|
||||
}
|
||||
|
||||
type mockSubscriber struct {
|
||||
v string
|
||||
lisErr, valErr error
|
||||
listener func()
|
||||
}
|
||||
|
||||
func (m *mockSubscriber) AddListener(listener func()) error {
|
||||
m.listener = listener
|
||||
return m.lisErr
|
||||
}
|
||||
|
||||
func (m *mockSubscriber) Value() (string, error) {
|
||||
return m.v, m.valErr
|
||||
}
|
||||
|
||||
func (m *mockSubscriber) change() {
|
||||
if m.listener != nil {
|
||||
m.listener()
|
||||
}
|
||||
}
|
||||
67
core/configcenter/subscriber/etcd.go
Normal file
67
core/configcenter/subscriber/etcd.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package subscriber
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/discov"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type (
|
||||
// etcdSubscriber is a subscriber that subscribes to etcd.
|
||||
etcdSubscriber struct {
|
||||
*discov.Subscriber
|
||||
}
|
||||
|
||||
// EtcdConf is the configuration for etcd.
|
||||
EtcdConf = discov.EtcdConf
|
||||
)
|
||||
|
||||
// MustNewEtcdSubscriber returns an etcd Subscriber, exits on errors.
|
||||
func MustNewEtcdSubscriber(conf EtcdConf) Subscriber {
|
||||
s, err := NewEtcdSubscriber(conf)
|
||||
logx.Must(err)
|
||||
return s
|
||||
}
|
||||
|
||||
// NewEtcdSubscriber returns an etcd Subscriber.
|
||||
func NewEtcdSubscriber(conf EtcdConf) (Subscriber, error) {
|
||||
opts := buildSubOptions(conf)
|
||||
s, err := discov.NewSubscriber(conf.Hosts, conf.Key, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &etcdSubscriber{Subscriber: s}, nil
|
||||
}
|
||||
|
||||
// buildSubOptions constructs the options for creating a new etcd subscriber.
|
||||
func buildSubOptions(conf EtcdConf) []discov.SubOption {
|
||||
opts := []discov.SubOption{
|
||||
discov.WithExactMatch(),
|
||||
}
|
||||
|
||||
if len(conf.User) > 0 {
|
||||
opts = append(opts, discov.WithSubEtcdAccount(conf.User, conf.Pass))
|
||||
}
|
||||
if len(conf.CertFile) > 0 || len(conf.CertKeyFile) > 0 || len(conf.CACertFile) > 0 {
|
||||
opts = append(opts, discov.WithSubEtcdTLS(conf.CertFile, conf.CertKeyFile,
|
||||
conf.CACertFile, conf.InsecureSkipVerify))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// AddListener adds a listener to the subscriber.
|
||||
func (s *etcdSubscriber) AddListener(listener func()) error {
|
||||
s.Subscriber.AddListener(listener)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the value of the subscriber.
|
||||
func (s *etcdSubscriber) Value() (string, error) {
|
||||
vs := s.Subscriber.Values()
|
||||
if len(vs) > 0 {
|
||||
return vs[len(vs)-1], nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
9
core/configcenter/subscriber/subscriber.go
Normal file
9
core/configcenter/subscriber/subscriber.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package subscriber
|
||||
|
||||
// Subscriber is the interface for configcenter subscribers.
|
||||
type Subscriber interface {
|
||||
// AddListener adds a listener to the subscriber.
|
||||
AddListener(listener func()) error
|
||||
// Value returns the value of the subscriber.
|
||||
Value() (string, error)
|
||||
}
|
||||
41
core/configcenter/unmarshaler.go
Normal file
41
core/configcenter/unmarshaler.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package configurator
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
)
|
||||
|
||||
var registry = &unmarshalerRegistry{
|
||||
unmarshalers: map[string]LoaderFn{
|
||||
"json": conf.LoadFromJsonBytes,
|
||||
"toml": conf.LoadFromTomlBytes,
|
||||
"yaml": conf.LoadFromYamlBytes,
|
||||
},
|
||||
}
|
||||
|
||||
type (
|
||||
// LoaderFn is the function type for loading configuration.
|
||||
LoaderFn func([]byte, any) error
|
||||
|
||||
// unmarshalerRegistry is the registry for unmarshalers.
|
||||
unmarshalerRegistry struct {
|
||||
unmarshalers map[string]LoaderFn
|
||||
mu sync.RWMutex
|
||||
}
|
||||
)
|
||||
|
||||
// RegisterUnmarshaler registers an unmarshaler.
|
||||
func RegisterUnmarshaler(name string, fn LoaderFn) {
|
||||
registry.mu.Lock()
|
||||
defer registry.mu.Unlock()
|
||||
registry.unmarshalers[name] = fn
|
||||
}
|
||||
|
||||
// Unmarshaler returns the unmarshaler by name.
|
||||
func Unmarshaler(name string) (LoaderFn, bool) {
|
||||
registry.mu.RLock()
|
||||
defer registry.mu.RUnlock()
|
||||
fn, ok := registry.unmarshalers[name]
|
||||
return fn, ok
|
||||
}
|
||||
28
core/configcenter/unmarshaler_test.go
Normal file
28
core/configcenter/unmarshaler_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package configurator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRegisterUnmarshaler(t *testing.T) {
|
||||
RegisterUnmarshaler("test", func(data []byte, v interface{}) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
_, ok := Unmarshaler("test")
|
||||
assert.True(t, ok)
|
||||
|
||||
_, ok = Unmarshaler("test2")
|
||||
assert.False(t, ok)
|
||||
|
||||
_, ok = Unmarshaler("json")
|
||||
assert.True(t, ok)
|
||||
|
||||
_, ok = Unmarshaler("toml")
|
||||
assert.True(t, ok)
|
||||
|
||||
_, ok = Unmarshaler("yaml")
|
||||
assert.True(t, ok)
|
||||
}
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
"sync"
|
||||
"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/logx"
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
"github.com/zeromicro/go-zero/core/threading"
|
||||
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -45,7 +46,7 @@ func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
||||
}
|
||||
|
||||
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
||||
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
||||
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener, exactMatch bool) error {
|
||||
c, exists := r.getCluster(endpoints)
|
||||
// if exists, the existing values should be updated to the listener.
|
||||
if exists {
|
||||
@@ -55,7 +56,7 @@ func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) err
|
||||
}
|
||||
}
|
||||
|
||||
return c.monitor(key, l)
|
||||
return c.monitor(key, l, exactMatch)
|
||||
}
|
||||
|
||||
func (r *Registry) getCluster(endpoints []string) (c *cluster, exists bool) {
|
||||
@@ -86,6 +87,7 @@ type cluster struct {
|
||||
watchGroup *threading.RoutineGroup
|
||||
done chan lang.PlaceholderType
|
||||
lock sync.RWMutex
|
||||
exactMatch bool
|
||||
}
|
||||
|
||||
func newCluster(endpoints []string) *cluster {
|
||||
@@ -224,7 +226,12 @@ func (c *cluster) load(cli EtcdClient, key string) int64 {
|
||||
for {
|
||||
var err error
|
||||
ctx, cancel := context.WithTimeout(c.context(cli), RequestTimeout)
|
||||
resp, err = cli.Get(ctx, makeKeyPrefix(key), clientv3.WithPrefix())
|
||||
if c.exactMatch {
|
||||
resp, err = cli.Get(ctx, key)
|
||||
} else {
|
||||
resp, err = cli.Get(ctx, makeKeyPrefix(key), clientv3.WithPrefix())
|
||||
}
|
||||
|
||||
cancel()
|
||||
if err == nil {
|
||||
break
|
||||
@@ -247,9 +254,10 @@ func (c *cluster) load(cli EtcdClient, key string) int64 {
|
||||
return resp.Header.Revision
|
||||
}
|
||||
|
||||
func (c *cluster) monitor(key string, l UpdateListener) error {
|
||||
func (c *cluster) monitor(key string, l UpdateListener, exactMatch bool) error {
|
||||
c.lock.Lock()
|
||||
c.listeners[key] = append(c.listeners[key], l)
|
||||
c.exactMatch = exactMatch
|
||||
c.lock.Unlock()
|
||||
|
||||
cli, err := c.getClient()
|
||||
@@ -315,14 +323,20 @@ func (c *cluster) watch(cli EtcdClient, key string, rev int64) {
|
||||
}
|
||||
|
||||
func (c *cluster) watchStream(cli EtcdClient, key string, rev int64) error {
|
||||
var rch clientv3.WatchChan
|
||||
if rev != 0 {
|
||||
rch = cli.Watch(clientv3.WithRequireLeader(c.context(cli)), makeKeyPrefix(key),
|
||||
clientv3.WithPrefix(), clientv3.WithRev(rev+1))
|
||||
} else {
|
||||
rch = cli.Watch(clientv3.WithRequireLeader(c.context(cli)), makeKeyPrefix(key),
|
||||
clientv3.WithPrefix())
|
||||
var (
|
||||
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 {
|
||||
select {
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestRegistry_Monitor(t *testing.T) {
|
||||
},
|
||||
}
|
||||
GetRegistry().lock.Unlock()
|
||||
assert.Error(t, GetRegistry().Monitor(endpoints, "foo", new(mockListener)))
|
||||
assert.Error(t, GetRegistry().Monitor(endpoints, "foo", new(mockListener), false))
|
||||
}
|
||||
|
||||
type mockListener struct {
|
||||
|
||||
@@ -15,9 +15,10 @@ type (
|
||||
|
||||
// A Subscriber is used to subscribe the given key on an etcd cluster.
|
||||
Subscriber struct {
|
||||
endpoints []string
|
||||
exclusive bool
|
||||
items *container
|
||||
endpoints []string
|
||||
exclusive bool
|
||||
exactMatch bool
|
||||
items *container
|
||||
}
|
||||
)
|
||||
|
||||
@@ -34,7 +35,7 @@ func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscrib
|
||||
}
|
||||
sub.items = newContainer(sub.exclusive)
|
||||
|
||||
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items); err != nil {
|
||||
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items, sub.exactMatch); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -59,6 +60,13 @@ func Exclusive() SubOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithExactMatch turn off querying using key prefixes.
|
||||
func WithExactMatch() SubOption {
|
||||
return func(sub *Subscriber) {
|
||||
sub.exactMatch = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithSubEtcdAccount provides the etcd username/password.
|
||||
func WithSubEtcdAccount(user, pass string) SubOption {
|
||||
return func(sub *Subscriber) {
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package errorx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type (
|
||||
// A BatchError is an error that can hold multiple errors.
|
||||
BatchError struct {
|
||||
errs errorArray
|
||||
lock sync.Mutex
|
||||
}
|
||||
// BatchError is an error that can hold multiple errors.
|
||||
type BatchError struct {
|
||||
errs []error
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
errorArray []error
|
||||
)
|
||||
|
||||
// Add adds errs to be, nil errors are ignored.
|
||||
// Add adds one or more non-nil errors to the BatchError instance.
|
||||
func (be *BatchError) Add(errs ...error) {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
@@ -27,39 +23,20 @@ func (be *BatchError) Add(errs ...error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Err returns an error that represents all errors.
|
||||
// Err returns an error that represents all accumulated errors.
|
||||
// It returns nil if there are no errors.
|
||||
func (be *BatchError) Err() error {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
be.lock.RLock()
|
||||
defer be.lock.RUnlock()
|
||||
|
||||
switch len(be.errs) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return be.errs[0]
|
||||
default:
|
||||
return be.errs
|
||||
}
|
||||
// If there are no non-nil errors, errors.Join(...) returns nil.
|
||||
return errors.Join(be.errs...)
|
||||
}
|
||||
|
||||
// NotNil checks if any error inside.
|
||||
// NotNil checks if there is at least one error inside the BatchError.
|
||||
func (be *BatchError) NotNil() bool {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
be.lock.RLock()
|
||||
defer be.lock.RUnlock()
|
||||
|
||||
return len(be.errs) > 0
|
||||
}
|
||||
|
||||
// Error returns a string that represents inside errors.
|
||||
func (ea errorArray) Error() string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
for i := range ea {
|
||||
if i > 0 {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
buf.WriteString(ea[i].Error())
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
@@ -66,3 +66,82 @@ func TestBatchErrorConcurrentAdd(t *testing.T) {
|
||||
assert.Equal(t, count, len(batch.errs))
|
||||
assert.True(t, batch.NotNil())
|
||||
}
|
||||
|
||||
func TestBatchError_Unwrap(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var be BatchError
|
||||
assert.Nil(t, be.Err())
|
||||
assert.True(t, errors.Is(be.Err(), nil))
|
||||
})
|
||||
|
||||
t.Run("one error", func(t *testing.T) {
|
||||
var errFoo = errors.New("foo")
|
||||
var errBar = errors.New("bar")
|
||||
var be BatchError
|
||||
be.Add(errFoo)
|
||||
assert.True(t, errors.Is(be.Err(), errFoo))
|
||||
assert.False(t, errors.Is(be.Err(), errBar))
|
||||
})
|
||||
|
||||
t.Run("two errors", func(t *testing.T) {
|
||||
var errFoo = errors.New("foo")
|
||||
var errBar = errors.New("bar")
|
||||
var errBaz = errors.New("baz")
|
||||
var be BatchError
|
||||
be.Add(errFoo)
|
||||
be.Add(errBar)
|
||||
assert.True(t, errors.Is(be.Err(), errFoo))
|
||||
assert.True(t, errors.Is(be.Err(), errBar))
|
||||
assert.False(t, errors.Is(be.Err(), errBaz))
|
||||
})
|
||||
}
|
||||
|
||||
func TestBatchError_Add(t *testing.T) {
|
||||
var be BatchError
|
||||
|
||||
// Test adding nil errors
|
||||
be.Add(nil, nil)
|
||||
assert.False(t, be.NotNil(), "Expected BatchError to be empty after adding nil errors")
|
||||
|
||||
// Test adding non-nil errors
|
||||
err1 := errors.New("error 1")
|
||||
err2 := errors.New("error 2")
|
||||
be.Add(err1, err2)
|
||||
assert.True(t, be.NotNil(), "Expected BatchError to be non-empty after adding errors")
|
||||
|
||||
// Test adding a mix of nil and non-nil errors
|
||||
err3 := errors.New("error 3")
|
||||
be.Add(nil, err3, nil)
|
||||
assert.True(t, be.NotNil(), "Expected BatchError to be non-empty after adding a mix of nil and non-nil errors")
|
||||
}
|
||||
|
||||
func TestBatchError_Err(t *testing.T) {
|
||||
var be BatchError
|
||||
|
||||
// Test Err() on empty BatchError
|
||||
assert.Nil(t, be.Err(), "Expected nil error for empty BatchError")
|
||||
|
||||
// Test Err() with multiple errors
|
||||
err1 := errors.New("error 1")
|
||||
err2 := errors.New("error 2")
|
||||
be.Add(err1, err2)
|
||||
|
||||
combinedErr := be.Err()
|
||||
assert.NotNil(t, combinedErr, "Expected nil error for BatchError with multiple errors")
|
||||
|
||||
// Check if the combined error contains both error messages
|
||||
errString := combinedErr.Error()
|
||||
assert.Truef(t, errors.Is(combinedErr, err1), "Combined error doesn't contain first error: %s", errString)
|
||||
assert.Truef(t, errors.Is(combinedErr, err2), "Combined error doesn't contain second error: %s", errString)
|
||||
}
|
||||
|
||||
func TestBatchError_NotNil(t *testing.T) {
|
||||
var be BatchError
|
||||
|
||||
// Test NotNil() on empty BatchError
|
||||
assert.Nil(t, be.Err(), "Expected nil error for empty BatchError")
|
||||
|
||||
// Test NotNil() after adding an error
|
||||
be.Add(errors.New("test error"))
|
||||
assert.NotNil(t, be.Err(), "Expected non-nil error after adding an error")
|
||||
}
|
||||
|
||||
@@ -42,4 +42,6 @@ type LogConf struct {
|
||||
// daily: daily rotation.
|
||||
// size: size limited rotation.
|
||||
Rotation string `json:",default=daily,options=[daily,size]"`
|
||||
// FileTimeFormat represents the time format for file name, default is `2006-01-02T15:04:05.000Z07:00`.
|
||||
FileTimeFormat string `json:",optional"`
|
||||
}
|
||||
|
||||
@@ -294,6 +294,10 @@ func SetUp(c LogConf) (err error) {
|
||||
timeFormat = c.TimeFormat
|
||||
}
|
||||
|
||||
if len(c.FileTimeFormat) > 0 {
|
||||
fileTimeFormat = c.FileTimeFormat
|
||||
}
|
||||
|
||||
atomic.StoreUint32(&maxContentLength, c.MaxContentLength)
|
||||
|
||||
switch c.Encoding {
|
||||
|
||||
@@ -850,12 +850,13 @@ func doTestStructedLogConsole(t *testing.T, w *mockWriter, write func(...any)) {
|
||||
func testSetLevelTwiceWithMode(t *testing.T, mode string, w *mockWriter) {
|
||||
writer.Store(nil)
|
||||
SetUp(LogConf{
|
||||
Mode: mode,
|
||||
Level: "debug",
|
||||
Path: "/dev/null",
|
||||
Encoding: plainEncoding,
|
||||
Stat: false,
|
||||
TimeFormat: time.RFC3339,
|
||||
Mode: mode,
|
||||
Level: "debug",
|
||||
Path: "/dev/null",
|
||||
Encoding: plainEncoding,
|
||||
Stat: false,
|
||||
TimeFormat: time.RFC3339,
|
||||
FileTimeFormat: time.DateTime,
|
||||
})
|
||||
SetUp(LogConf{
|
||||
Mode: mode,
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
const (
|
||||
dateFormat = "2006-01-02"
|
||||
fileTimeFormat = time.RFC3339
|
||||
hoursPerDay = 24
|
||||
bufferSize = 100
|
||||
defaultDirMode = 0o755
|
||||
@@ -28,8 +27,12 @@ const (
|
||||
megaBytes = 1 << 20
|
||||
)
|
||||
|
||||
// ErrLogFileClosed is an error that indicates the log file is already closed.
|
||||
var ErrLogFileClosed = errors.New("error: log file closed")
|
||||
var (
|
||||
// ErrLogFileClosed is an error that indicates the log file is already closed.
|
||||
ErrLogFileClosed = errors.New("error: log file closed")
|
||||
|
||||
fileTimeFormat = time.RFC3339
|
||||
)
|
||||
|
||||
type (
|
||||
// A RotateRule interface is used to define the log rotating rules.
|
||||
|
||||
@@ -50,6 +50,7 @@ type (
|
||||
|
||||
unmarshalOptions struct {
|
||||
fillDefault bool
|
||||
fromArray bool
|
||||
fromString bool
|
||||
opaqueKeys bool
|
||||
canonicalKey func(key string) string
|
||||
@@ -811,6 +812,19 @@ func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect
|
||||
return u.processNamedFieldWithoutValue(field.Type, value, opts, fullName)
|
||||
}
|
||||
|
||||
if u.opts.fromArray {
|
||||
fieldKind := field.Type.Kind()
|
||||
if fieldKind != reflect.Slice && fieldKind != reflect.Array {
|
||||
valueKind := reflect.TypeOf(mapValue).Kind()
|
||||
if valueKind == reflect.Slice || valueKind == reflect.Array {
|
||||
val := reflect.ValueOf(mapValue)
|
||||
if val.Len() > 0 {
|
||||
mapValue = val.Index(0).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return u.processNamedFieldWithValue(field.Type, value, valueWithParent{
|
||||
value: mapValue,
|
||||
parent: valuer,
|
||||
@@ -990,6 +1004,16 @@ func WithDefault() UnmarshalOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithFromArray customizes an Unmarshaler with converting array values to non-array types.
|
||||
// For example, if the field type is []string, and the value is [hello],
|
||||
// the field type can be `string`, instead of `[]string`.
|
||||
// Typically, this option is used for unmarshaling from form values.
|
||||
func WithFromArray() UnmarshalOption {
|
||||
return func(opt *unmarshalOptions) {
|
||||
opt.fromArray = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithOpaqueKeys customizes an Unmarshaler with opaque keys.
|
||||
// Opaque keys are keys that are not processed by the unmarshaler.
|
||||
func WithOpaqueKeys() UnmarshalOption {
|
||||
|
||||
@@ -5639,6 +5639,62 @@ func TestUnmarshalFromStringSliceForTypeMismatch(t *testing.T) {
|
||||
}, &v))
|
||||
}
|
||||
|
||||
func TestUnmarshalWithFromArray(t *testing.T) {
|
||||
t.Run("array", func(t *testing.T) {
|
||||
var v struct {
|
||||
Value []string `key:"value"`
|
||||
}
|
||||
unmarshaler := NewUnmarshaler("key", WithFromArray())
|
||||
if assert.NoError(t, unmarshaler.Unmarshal(map[string]any{
|
||||
"value": []string{"foo", "bar"},
|
||||
}, &v)) {
|
||||
assert.ElementsMatch(t, []string{"foo", "bar"}, v.Value)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not array", func(t *testing.T) {
|
||||
var v struct {
|
||||
Value string `key:"value"`
|
||||
}
|
||||
unmarshaler := NewUnmarshaler("key", WithFromArray())
|
||||
if assert.NoError(t, unmarshaler.Unmarshal(map[string]any{
|
||||
"value": []string{"foo"},
|
||||
}, &v)) {
|
||||
assert.Equal(t, "foo", v.Value)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not array and empty", func(t *testing.T) {
|
||||
var v struct {
|
||||
Value string `key:"value"`
|
||||
}
|
||||
unmarshaler := NewUnmarshaler("key", WithFromArray())
|
||||
if assert.NoError(t, unmarshaler.Unmarshal(map[string]any{
|
||||
"value": []string{""},
|
||||
}, &v)) {
|
||||
assert.Empty(t, v.Value)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not array and no value", func(t *testing.T) {
|
||||
var v struct {
|
||||
Value string `key:"value"`
|
||||
}
|
||||
unmarshaler := NewUnmarshaler("key", WithFromArray())
|
||||
assert.Error(t, unmarshaler.Unmarshal(map[string]any{}, &v))
|
||||
})
|
||||
|
||||
t.Run("not array and no value and optional", func(t *testing.T) {
|
||||
var v struct {
|
||||
Value string `key:"value,optional"`
|
||||
}
|
||||
unmarshaler := NewUnmarshaler("key", WithFromArray())
|
||||
if assert.NoError(t, unmarshaler.Unmarshal(map[string]any{}, &v)) {
|
||||
assert.Empty(t, v.Value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalWithOpaqueKeys(t *testing.T) {
|
||||
var v struct {
|
||||
Opaque string `key:"opaque.key"`
|
||||
|
||||
@@ -1197,6 +1197,18 @@ func (s *Redis) PipelinedCtx(ctx context.Context, fn func(Pipeliner) error) erro
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Redis) Publish(channel string, message interface{}) (int64, error) {
|
||||
return s.PublishCtx(context.Background(), channel, message)
|
||||
}
|
||||
|
||||
func (s *Redis) PublishCtx(ctx context.Context, channel string, message interface{}) (int64, error) {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return conn.Publish(ctx, channel, message).Result()
|
||||
}
|
||||
|
||||
// Rpop is the implementation of redis rpop command.
|
||||
func (s *Redis) Rpop(key string) (string, error) {
|
||||
return s.RpopCtx(context.Background(), key)
|
||||
@@ -1247,6 +1259,18 @@ func (s *Redis) RpushCtx(ctx context.Context, key string, values ...any) (int, e
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
func (s *Redis) RPopLPush(source string, destination string) (string, error) {
|
||||
return s.RPopLPushCtx(context.Background(), source, destination)
|
||||
}
|
||||
|
||||
func (s *Redis) RPopLPushCtx(ctx context.Context, source string, destination string) (string, error) {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return conn.RPopLPush(ctx, source, destination).Result()
|
||||
}
|
||||
|
||||
// Sadd is the implementation of redis sadd command.
|
||||
func (s *Redis) Sadd(key string, values ...any) (int, error) {
|
||||
return s.SaddCtx(context.Background(), key, values...)
|
||||
@@ -1645,6 +1669,26 @@ func (s *Redis) TtlCtx(ctx context.Context, key string) (int, error) {
|
||||
return int(duration), nil
|
||||
}
|
||||
|
||||
func (s *Redis) TxPipeline() (pipe Pipeliner, err error) {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn.TxPipeline(), nil
|
||||
}
|
||||
|
||||
func (s *Redis) Unlink(keys ...string) (int64, error) {
|
||||
return s.UnlinkCtx(context.Background(), keys...)
|
||||
}
|
||||
|
||||
func (s *Redis) UnlinkCtx(ctx context.Context, keys ...string) (int64, error) {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return conn.Unlink(ctx, keys...).Result()
|
||||
}
|
||||
|
||||
// Zadd is the implementation of redis zadd command.
|
||||
func (s *Redis) Zadd(key string, score int64, value string) (bool, error) {
|
||||
return s.ZaddCtx(context.Background(), key, score, value)
|
||||
|
||||
@@ -2080,3 +2080,70 @@ func (n mockedNode) BLPop(_ context.Context, _ time.Duration, _ ...string) *red.
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func TestRedisPublish(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
_, err := newRedis(client.Addr, badType()).Publish("Test", "message")
|
||||
assert.NotNil(t, err)
|
||||
_, err = client.Publish("Test", "message")
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRedisRPopLPush(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
_, err := newRedis(client.Addr, badType()).RPopLPush("Source", "Destination")
|
||||
assert.NotNil(t, err)
|
||||
_, err = client.Rpush("Source", "Destination")
|
||||
assert.Nil(t, err)
|
||||
_, err = client.RPopLPush("Source", "Destination")
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRedisUnlink(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
_, err := newRedis(client.Addr, badType()).Unlink("Key1", "Key2")
|
||||
assert.NotNil(t, err)
|
||||
err = client.Set("Key1", "Key2")
|
||||
assert.Nil(t, err)
|
||||
get, err := client.Get("Key1")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "Key2", get)
|
||||
res, err := client.Unlink("Key1")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), res)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRedisTxPipeline(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
ctx := context.Background()
|
||||
pipe, err := newRedis(client.Addr, badType()).TxPipeline()
|
||||
assert.NotNil(t, err)
|
||||
pipe, err = client.TxPipeline()
|
||||
assert.Nil(t, err)
|
||||
key := "key"
|
||||
hashKey := "field"
|
||||
hashValue := "value"
|
||||
|
||||
// setting value
|
||||
pipe.HSet(ctx, key, hashKey, hashValue)
|
||||
|
||||
existsCmd := pipe.Exists(ctx, key)
|
||||
getCmd := pipe.HGet(ctx, key, hashKey)
|
||||
|
||||
// execution
|
||||
_, err = pipe.Exec(ctx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// verification results
|
||||
exists, err := existsCmd.Result()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), exists)
|
||||
|
||||
value, err := getCmd.Result()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, hashValue, value)
|
||||
})
|
||||
}
|
||||
|
||||
45
go.mod
45
go.mod
@@ -5,24 +5,24 @@ go 1.20
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/alicebob/miniredis/v2 v2.33.0
|
||||
github.com/fatih/color v1.17.0
|
||||
github.com/fatih/color v1.18.0
|
||||
github.com/fullstorydev/grpcurl v1.9.1
|
||||
github.com/go-sql-driver/mysql v1.8.1
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/golang/protobuf v1.5.4
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jackc/pgx/v5 v5.6.0
|
||||
github.com/jhump/protoreflect v1.16.0
|
||||
github.com/jhump/protoreflect v1.17.0
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pelletier/go-toml/v2 v2.2.2
|
||||
github.com/prometheus/client_golang v1.19.1
|
||||
github.com/redis/go-redis/v9 v9.6.1
|
||||
github.com/prometheus/client_golang v1.20.5
|
||||
github.com/redis/go-redis/v9 v9.7.0
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
go.etcd.io/etcd/api/v3 v3.5.15
|
||||
go.etcd.io/etcd/client/v3 v3.5.15
|
||||
go.mongodb.org/mongo-driver v1.16.0
|
||||
go.mongodb.org/mongo-driver v1.17.1
|
||||
go.opentelemetry.io/otel v1.24.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
||||
@@ -31,14 +31,14 @@ require (
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.24.0
|
||||
go.opentelemetry.io/otel/sdk v1.24.0
|
||||
go.opentelemetry.io/otel/trace v1.24.0
|
||||
go.uber.org/automaxprocs v1.5.3
|
||||
go.uber.org/automaxprocs v1.6.0
|
||||
go.uber.org/goleak v1.3.0
|
||||
golang.org/x/net v0.27.0
|
||||
golang.org/x/sys v0.22.0
|
||||
golang.org/x/time v0.5.0
|
||||
golang.org/x/net v0.31.0
|
||||
golang.org/x/sys v0.27.0
|
||||
golang.org/x/time v0.8.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
google.golang.org/protobuf v1.35.2
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
@@ -52,7 +52,7 @@ require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bufbuild/protocompile v0.10.0 // indirect
|
||||
github.com/bufbuild/protocompile v0.14.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
|
||||
@@ -80,7 +80,8 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.8 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
@@ -91,15 +92,15 @@ require (
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.48.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.55.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
github.com/yuin/gopher-lua v1.1.1 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
|
||||
@@ -108,11 +109,11 @@ require (
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.25.0 // indirect
|
||||
golang.org/x/oauth2 v0.20.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/term v0.22.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
golang.org/x/crypto v0.29.0 // indirect
|
||||
golang.org/x/oauth2 v0.21.0 // indirect
|
||||
golang.org/x/sync v0.9.0 // indirect
|
||||
golang.org/x/term v0.26.0 // indirect
|
||||
golang.org/x/text v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
91
go.sum
91
go.sum
@@ -11,8 +11,8 @@ 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/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bufbuild/protocompile v0.10.0 h1:+jW/wnLMLxaCEG8AX9lD0bQ5v9h1RUiMKOBOT5ll9dM=
|
||||
github.com/bufbuild/protocompile v0.10.0/go.mod h1:G9qQIQo0xZ6Uyj6CMNz0saGmx2so+KONo8/KrELABiY=
|
||||
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/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/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -35,8 +35,8 @@ github.com/envoyproxy/go-control-plane v0.12.0 h1:4X+VP1GHd1Mhj6IB5mMeGbLCleqxjl
|
||||
github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0=
|
||||
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
|
||||
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
|
||||
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
|
||||
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
|
||||
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/fullstorydev/grpcurl v1.9.1 h1:YxX1aCcCc4SDBQfj9uoWcTLe8t4NWrZe1y+mk83BQgo=
|
||||
github.com/fullstorydev/grpcurl v1.9.1/go.mod h1:i8gKLIC6s93WdU3LSmkE5vtsCxyRmihUj5FK1cNW5EM=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
@@ -58,8 +58,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
|
||||
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/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
@@ -89,8 +89,8 @@ github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg=
|
||||
github.com/jhump/protoreflect v1.16.0/go.mod h1:oYPd7nPvcBw/5wlDfm/AVmU9zH9BgqGCI469pGxfj/8=
|
||||
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/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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
@@ -98,14 +98,16 @@ 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/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/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
|
||||
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
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.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
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.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
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/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
@@ -139,16 +141,16 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
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/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
||||
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
|
||||
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
||||
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
||||
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
||||
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
|
||||
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
|
||||
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_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
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.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
|
||||
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/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/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
@@ -174,8 +176,8 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
@@ -188,8 +190,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/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
|
||||
go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4=
|
||||
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
||||
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
|
||||
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
|
||||
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/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
||||
@@ -214,8 +216,8 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
|
||||
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
|
||||
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/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=
|
||||
@@ -224,11 +226,10 @@ go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||
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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/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.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||
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.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
@@ -240,17 +241,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-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.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
|
||||
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||
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/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-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-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
|
||||
golang.org/x/sync v0.9.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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -262,20 +263,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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.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-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
|
||||
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
|
||||
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
|
||||
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
|
||||
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.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
@@ -293,8 +294,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/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||
google.golang.org/protobuf v1.35.2/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 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
||||
@@ -77,10 +77,12 @@ func (s *Server) StartAsync(c Config) {
|
||||
|
||||
// StartAgent start inner http server by config.
|
||||
func StartAgent(c Config) {
|
||||
if !c.Enabled {
|
||||
return
|
||||
}
|
||||
|
||||
once.Do(func() {
|
||||
if c.Enabled {
|
||||
s := NewServer(c)
|
||||
s.StartAsync(c)
|
||||
}
|
||||
s := NewServer(c)
|
||||
s.StartAsync(c)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>99. 新华三技术有限公司
|
||||
>100. 上海邑脉科技有限公司
|
||||
>101. 上海巨瓴科技有限公司
|
||||
>102. 深圳市兴海物联科技有限公司
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ go-zero contains simple API description syntax and code generation tool called `
|
||||
|
||||
## Backgrounds of go-zero
|
||||
|
||||
At the beginning of 2018, we decided to re-design our system, from monolithic architecture with Java+MongoDB to microservice architecture. After research and comparison, we chose to:
|
||||
In early 2018, we embarked on a transformative journey to redesign our system, transitioning from a monolithic architecture built with Java and MongoDB to a microservices architecture. After careful research and comparison, we made a deliberate choice to:
|
||||
|
||||
* Go Beyond with Golang
|
||||
@@ -251,7 +250,7 @@ go-zero enlisted in the [CNCF Cloud Native Landscape](https://landscape.cncf.io/
|
||||
|
||||
## Give a Star! ⭐
|
||||
|
||||
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
|
||||
If you like this project or are using it to learn or start your own solution, give it a star to get updates on new releases. Your support matters!
|
||||
|
||||
## Buy me a coffee
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package httpx
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
@@ -23,9 +24,16 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
formUnmarshaler = mapping.NewUnmarshaler(formKey, mapping.WithStringValues(), mapping.WithOpaqueKeys())
|
||||
pathUnmarshaler = mapping.NewUnmarshaler(pathKey, mapping.WithStringValues(), mapping.WithOpaqueKeys())
|
||||
validator atomic.Value
|
||||
formUnmarshaler = mapping.NewUnmarshaler(
|
||||
formKey,
|
||||
mapping.WithStringValues(),
|
||||
mapping.WithOpaqueKeys(),
|
||||
mapping.WithFromArray())
|
||||
pathUnmarshaler = mapping.NewUnmarshaler(
|
||||
pathKey,
|
||||
mapping.WithStringValues(),
|
||||
mapping.WithOpaqueKeys())
|
||||
validator atomic.Value
|
||||
)
|
||||
|
||||
// Validator defines the interface for validating the request.
|
||||
@@ -36,16 +44,19 @@ type Validator interface {
|
||||
|
||||
// Parse parses the request.
|
||||
func Parse(r *http.Request, v any) error {
|
||||
if err := ParsePath(r, v); err != nil {
|
||||
return err
|
||||
}
|
||||
kind := mapping.Deref(reflect.TypeOf(v)).Kind()
|
||||
if kind != reflect.Array && kind != reflect.Slice {
|
||||
if err := ParsePath(r, v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ParseForm(r, v); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ParseForm(r, v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ParseHeaders(r, v); err != nil {
|
||||
return err
|
||||
if err := ParseHeaders(r, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := ParseJsonBody(r, v); err != nil {
|
||||
|
||||
@@ -49,6 +49,61 @@ func TestParseForm(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseFormArray(t *testing.T) {
|
||||
t.Run("slice", func(t *testing.T) {
|
||||
var v struct {
|
||||
Name []string `form:"name"`
|
||||
Age []int `form:"age"`
|
||||
Percent []float64 `form:"percent,optional"`
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(
|
||||
http.MethodGet,
|
||||
"/a?name=hello&name=world&age=18&age=19&percent=3.4&percent=4.5",
|
||||
http.NoBody)
|
||||
assert.NoError(t, err)
|
||||
if assert.NoError(t, Parse(r, &v)) {
|
||||
assert.ElementsMatch(t, []string{"hello", "world"}, v.Name)
|
||||
assert.ElementsMatch(t, []int{18, 19}, v.Age)
|
||||
assert.ElementsMatch(t, []float64{3.4, 4.5}, v.Percent)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("slice with single value", func(t *testing.T) {
|
||||
var v struct {
|
||||
Name []string `form:"name"`
|
||||
Age []int `form:"age"`
|
||||
Percent []float64 `form:"percent,optional"`
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(
|
||||
http.MethodGet,
|
||||
"/a?name=hello&age=18&percent=3.4",
|
||||
http.NoBody)
|
||||
assert.NoError(t, err)
|
||||
if assert.NoError(t, Parse(r, &v)) {
|
||||
assert.ElementsMatch(t, []string{"hello"}, v.Name)
|
||||
assert.ElementsMatch(t, []int{18}, v.Age)
|
||||
assert.ElementsMatch(t, []float64{3.4}, v.Percent)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("slice with empty and non-empty", func(t *testing.T) {
|
||||
var v struct {
|
||||
Name []string `form:"name"`
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(
|
||||
http.MethodGet,
|
||||
"/a?name=&name=1",
|
||||
http.NoBody)
|
||||
assert.NoError(t, err)
|
||||
if assert.NoError(t, Parse(r, &v)) {
|
||||
assert.ElementsMatch(t, []string{"1"}, v.Name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseForm_Error(t *testing.T) {
|
||||
var v struct {
|
||||
Name string `form:"name"`
|
||||
@@ -270,11 +325,31 @@ func TestParseJsonBody(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, header.JsonContentType)
|
||||
|
||||
assert.NoError(t, ParseJsonBody(r, &v))
|
||||
assert.NoError(t, Parse(r, &v))
|
||||
assert.Equal(t, 1, len(v))
|
||||
assert.Equal(t, "kevin", v[0].Name)
|
||||
assert.Equal(t, 18, v[0].Age)
|
||||
})
|
||||
|
||||
t.Run("form and array body", func(t *testing.T) {
|
||||
var v []struct {
|
||||
// we can only ignore the form tag,
|
||||
// because if the value is a slice, it should be in the body,
|
||||
// but it's hard to detect when we treat it as a json body.
|
||||
Product string `form:"product"`
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
body := `[{"name":"apple", "age": 18}]`
|
||||
r := httptest.NewRequest(http.MethodPost, "/a?product=tree", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, header.JsonContentType)
|
||||
|
||||
assert.NoError(t, Parse(r, &v))
|
||||
assert.Equal(t, 1, len(v))
|
||||
assert.Equal(t, "apple", v[0].Name)
|
||||
assert.Equal(t, 18, v[0].Age)
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseRequired(t *testing.T) {
|
||||
|
||||
@@ -20,10 +20,16 @@ func GetFormValues(r *http.Request) (map[string]any, error) {
|
||||
}
|
||||
|
||||
params := make(map[string]any, len(r.Form))
|
||||
for name := range r.Form {
|
||||
formValue := r.Form.Get(name)
|
||||
if len(formValue) > 0 {
|
||||
params[name] = formValue
|
||||
for name, values := range r.Form {
|
||||
filtered := make([]string, 0, len(values))
|
||||
for _, v := range values {
|
||||
if len(v) > 0 {
|
||||
filtered = append(filtered, v)
|
||||
}
|
||||
}
|
||||
|
||||
if len(filtered) > 0 {
|
||||
params[name] = filtered
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ const (
|
||||
originHeader = "Origin"
|
||||
)
|
||||
|
||||
// AddAllowHeaders sets the allowed headers.
|
||||
func AddAllowHeaders(header http.Header, headers ...string) {
|
||||
header.Add(allowHeaders, strings.Join(headers, ", "))
|
||||
}
|
||||
|
||||
// NotAllowedHandler handles cross domain not allowed requests.
|
||||
// At most one origin can be specified, other origins are ignored if given, default to be *.
|
||||
func NotAllowedHandler(fn func(w http.ResponseWriter), origins ...string) http.Handler {
|
||||
|
||||
@@ -3,11 +3,80 @@ package cors
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAddAllowHeaders(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
initial string
|
||||
headers []string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "single header",
|
||||
initial: "",
|
||||
headers: []string{"Content-Type"},
|
||||
expected: "Content-Type",
|
||||
},
|
||||
{
|
||||
name: "multiple headers",
|
||||
initial: "",
|
||||
headers: []string{"Content-Type", "Authorization", "X-Requested-With"},
|
||||
expected: "Content-Type, Authorization, X-Requested-With",
|
||||
},
|
||||
{
|
||||
name: "add to existing headers",
|
||||
initial: "Origin, Accept",
|
||||
headers: []string{"Content-Type"},
|
||||
expected: "Origin, Accept, Content-Type",
|
||||
},
|
||||
{
|
||||
name: "no headers",
|
||||
initial: "",
|
||||
headers: []string{},
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
header := http.Header{}
|
||||
headers := make(map[string]struct{})
|
||||
if tt.initial != "" {
|
||||
header.Set(allowHeaders, tt.initial)
|
||||
vals := strings.Split(tt.initial, ", ")
|
||||
for _, v := range vals {
|
||||
headers[v] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, h := range tt.headers {
|
||||
headers[h] = struct{}{}
|
||||
}
|
||||
AddAllowHeaders(header, tt.headers...)
|
||||
var actual []string
|
||||
vals := header.Values(allowHeaders)
|
||||
for _, v := range vals {
|
||||
bunch := strings.Split(v, ", ")
|
||||
for _, b := range bunch {
|
||||
if len(b) > 0 {
|
||||
actual = append(actual, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var expect []string
|
||||
for k := range headers {
|
||||
expect = append(expect, k)
|
||||
}
|
||||
assert.ElementsMatch(t, expect, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorsHandlerWithOrigins(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -137,7 +137,7 @@ func TestPatRouter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseSlice(t *testing.T) {
|
||||
body := `names=%5B%22first%22%2C%22second%22%5D`
|
||||
body := `names=first&names=second`
|
||||
reader := strings.NewReader(body)
|
||||
r, err := http.NewRequest(http.MethodPost, "http://hello.com/", reader)
|
||||
assert.Nil(t, err)
|
||||
@@ -388,7 +388,7 @@ func TestParseQueryRequired(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseOptional(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever&zipcode=", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/kevin/2017?nickname=whatever", nil)
|
||||
assert.Nil(t, err)
|
||||
|
||||
router := NewRouter()
|
||||
|
||||
@@ -161,6 +161,18 @@ func WithCors(origin ...string) RunOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithCorsHeaders returns a RunOption to enable CORS with given headers.
|
||||
func WithCorsHeaders(headers ...string) RunOption {
|
||||
const allDomains = "*"
|
||||
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(nil, allDomains))
|
||||
server.router = newCorsRouter(server.router, func(header http.Header) {
|
||||
cors.AddAllowHeaders(header, headers...)
|
||||
}, allDomains)
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustomCors returns a func to enable CORS for given origin, or default to all origins (*),
|
||||
// fn lets caller customizing the response.
|
||||
func WithCustomCors(middlewareFn func(header http.Header), notAllowedFn func(http.ResponseWriter),
|
||||
|
||||
@@ -420,6 +420,64 @@ Port: 54321
|
||||
opt(svr)
|
||||
}
|
||||
|
||||
func TestWithCorsHeaders(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
headers []string
|
||||
}{
|
||||
{
|
||||
name: "single header",
|
||||
headers: []string{"UserHeader"},
|
||||
},
|
||||
{
|
||||
name: "multiple headers",
|
||||
headers: []string{"UserHeader", "X-Requested-With"},
|
||||
},
|
||||
{
|
||||
name: "no headers",
|
||||
headers: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
const configYaml = `
|
||||
Name: foo
|
||||
Port: 54321
|
||||
`
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
|
||||
rt := router.NewRouter()
|
||||
svr, err := NewServer(cnf, WithRouter(rt))
|
||||
assert.Nil(t, err)
|
||||
defer svr.Stop()
|
||||
option := WithCorsHeaders(tt.headers...)
|
||||
option(svr)
|
||||
|
||||
// Assuming newCorsRouter sets headers correctly,
|
||||
// we would need to verify the behavior here. Since we don't have
|
||||
// direct access to headers, we'll mock newCorsRouter to capture it.
|
||||
w := httptest.NewRecorder()
|
||||
svr.ServeHTTP(w, httptest.NewRequest(http.MethodOptions, "/", nil))
|
||||
|
||||
vals := w.Header().Values("Access-Control-Allow-Headers")
|
||||
respHeaders := make(map[string]struct{})
|
||||
for _, header := range vals {
|
||||
headers := strings.Split(header, ", ")
|
||||
for _, h := range headers {
|
||||
if len(h) > 0 {
|
||||
respHeaders[h] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, h := range tt.headers {
|
||||
_, ok := respHeaders[h]
|
||||
assert.Truef(t, ok, "expected header %s not found", h)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_PrintRoutes(t *testing.T) {
|
||||
const (
|
||||
configYaml = `
|
||||
|
||||
@@ -2,8 +2,8 @@ FROM golang:alpine AS builder
|
||||
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
ENV CGO_ENABLED=0
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
@@ -24,7 +24,7 @@ RUN apk update --no-cache && apk add --no-cache protoc
|
||||
COPY --from=builder /etc/passwd /etc/group /etc/
|
||||
COPY --from=builder /usr/share/zoneinfo/ /usr/share/zoneinfo/
|
||||
COPY --from=builder --chown=1000:1000 /go/bin/protoc-gen-go* /app/goctl /usr/local/bin/
|
||||
ENV TZ Asia/Shanghai
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
USER app
|
||||
|
||||
@@ -157,8 +157,8 @@ func convertDataType(api *spec.ApiSpec, isLegacy bool) (error, *DartSpec) {
|
||||
defineStruct, ok := ty.(spec.DefineStruct)
|
||||
if ok {
|
||||
for index, member := range defineStruct.Members {
|
||||
structMember, ok := member.Type.(spec.DefineStruct)
|
||||
if ok && structMember.IsNestedStruct() {
|
||||
structMember, ok := member.Type.(spec.NestedStruct)
|
||||
if ok {
|
||||
defineStruct.Members[index].Type = spec.PrimitiveType{RawName: member.Name}
|
||||
t := template.New("dataTemplate")
|
||||
t = t.Funcs(funcMap)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/collection"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||
@@ -22,6 +23,8 @@ const (
|
||||
jwtTransKey = "jwtTransition"
|
||||
routesFilename = "routes"
|
||||
routesTemplate = `// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
@@ -203,6 +206,7 @@ rest.WithPrefix("%s"),`, g.prefix)
|
||||
"hasTimeout": hasTimeout,
|
||||
"importPackages": genRouteImports(rootPkg, api),
|
||||
"routesAdditions": strings.TrimSpace(builder.String()),
|
||||
"version": version.BuildVersion,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||
)
|
||||
@@ -64,6 +65,7 @@ func genTypes(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
data: map[string]any{
|
||||
"types": val,
|
||||
"containsTime": false,
|
||||
"version": version.BuildVersion,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
package types{{if .containsTime}}
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -63,8 +63,8 @@ func writeProperty(writer io.Writer, name, tag, comment string, tp spec.Type, in
|
||||
err error
|
||||
isNestedStruct bool
|
||||
)
|
||||
structType, ok := tp.(spec.DefineStruct)
|
||||
if ok && structType.IsNestedStruct() {
|
||||
structType, ok := tp.(spec.NestedStruct)
|
||||
if ok {
|
||||
isNestedStruct = true
|
||||
}
|
||||
if len(comment) > 0 {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
package com.xhb.logic.http.packet.{{.packet}}.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
@@ -131,6 +132,7 @@ func (c *componentsContext) createComponent(dir, packetName string, ty spec.Type
|
||||
"className": util.Title(defineStruct.Name()),
|
||||
"superClassName": superClassName,
|
||||
"HasProperty": len(strings.TrimSpace(propertiesString)) > 0,
|
||||
"version": version.BuildVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -30,9 +30,19 @@ func (t DefineStruct) Documents() []string {
|
||||
return t.Docs
|
||||
}
|
||||
|
||||
// IsNestedStruct returns whether the structure is nested.
|
||||
func (t DefineStruct) IsNestedStruct() bool {
|
||||
return len(t.Members) > 0
|
||||
// Name returns a structure string, such as User
|
||||
func (t NestedStruct) Name() string {
|
||||
return t.RawName
|
||||
}
|
||||
|
||||
// Comments returns the comments of struct
|
||||
func (t NestedStruct) Comments() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Documents returns the documents of struct
|
||||
func (t NestedStruct) Documents() []string {
|
||||
return t.Docs
|
||||
}
|
||||
|
||||
// Name returns a map string, such as map[string]int
|
||||
|
||||
@@ -105,6 +105,13 @@ type (
|
||||
Docs Doc
|
||||
}
|
||||
|
||||
// NestedStruct describes a structure nested in structure.
|
||||
NestedStruct struct {
|
||||
RawName string
|
||||
Members []Member
|
||||
Docs Doc
|
||||
}
|
||||
|
||||
// PrimitiveType describes the basic golang type, such as bool,int32,int64, ...
|
||||
PrimitiveType struct {
|
||||
RawName string
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
{{.componentTypes}}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
@@ -61,5 +62,6 @@ func genComponents(dir string, api *spec.ApiSpec) error {
|
||||
t := template.Must(template.New("componentsTemplate").Parse(componentsTemplate))
|
||||
return t.Execute(fp, map[string]string{
|
||||
"componentTypes": val,
|
||||
"version": version.BuildVersion,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export function parseParams(url: string): Array<string> {
|
||||
* @param url
|
||||
* @param params
|
||||
*/
|
||||
export function genUrl(url: string, params: unknown) {
|
||||
export function genUrl(url: string, params: any) {
|
||||
if (!params) {
|
||||
return url;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export const webapi = {
|
||||
return api<T>('delete', url, req, config);
|
||||
},
|
||||
put<T>(url: string, req: unknown, config?: unknown): Promise<T> {
|
||||
return api<T>('get', url, req, config);
|
||||
return api<T>('put', url, req, config);
|
||||
},
|
||||
post<T>(url: string, req: unknown, config?: unknown): Promise<T> {
|
||||
return api<T>('post', url, req, config);
|
||||
|
||||
@@ -54,8 +54,8 @@ func writeIndent(writer io.Writer, indent int) {
|
||||
}
|
||||
|
||||
func genTsType(m spec.Member, indent int) (ty string, err error) {
|
||||
v, ok := m.Type.(spec.DefineStruct)
|
||||
if ok && v.IsNestedStruct() {
|
||||
v, ok := m.Type.(spec.NestedStruct)
|
||||
if ok {
|
||||
writer := bytes.NewBuffer(nil)
|
||||
_, err := fmt.Fprintf(writer, "{\n")
|
||||
if err != nil {
|
||||
|
||||
1
tools/goctl/compare/.gitignore
vendored
Normal file
1
tools/goctl/compare/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build
|
||||
151
tools/goctl/compare/api/test.api
Normal file
151
tools/goctl/compare/api/test.api
Normal file
@@ -0,0 +1,151 @@
|
||||
syntax = "v1"
|
||||
|
||||
@server (
|
||||
group: base
|
||||
)
|
||||
service test {
|
||||
@handler root
|
||||
get /
|
||||
|
||||
@handler ping
|
||||
get /ping
|
||||
|
||||
@handler postRoot
|
||||
post /
|
||||
|
||||
@handler postPing
|
||||
post /ping
|
||||
}
|
||||
|
||||
type (
|
||||
Subject {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
Grade {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
Class {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
GradeId int64 `json:"gradeId"`
|
||||
Teachers []*Teacher `json:"teachers"`
|
||||
Master {
|
||||
UserId int64 `json:"userId"`
|
||||
Temp bool `json:"temp"`
|
||||
} `json:"master"`
|
||||
}
|
||||
User {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Gender int `json:"gender"`
|
||||
Active bool `json:"active"`
|
||||
Hobby []string `json:"hobby"`
|
||||
}
|
||||
Teacher {
|
||||
UserId int64 `json:"userId"`
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SubjectId int64 `json:"subjectId"`
|
||||
Class map[int64]*Class `json:"class"`
|
||||
}
|
||||
Student {
|
||||
UserId int64 `json:"userId"`
|
||||
StudentId int64 `json:"studentId"`
|
||||
Number string `json:"number"`
|
||||
ClassId int64 `json:"classId"`
|
||||
SubjectId []int64 `json:"subjectId"`
|
||||
SubjectTop3 [3]int64 `json:"subjectTop3"`
|
||||
Extra map[string]interface{} `json:"extra"`
|
||||
}
|
||||
Base {
|
||||
Code int64 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
LoginReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
LoginResp {
|
||||
Base
|
||||
Data *User `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: user
|
||||
prefix: /user
|
||||
)
|
||||
service test {
|
||||
@handler login
|
||||
post /login (LoginReq) returns (LoginReq)
|
||||
}
|
||||
|
||||
type (
|
||||
UserInfoReq {
|
||||
Id int64 `path:"id"`
|
||||
}
|
||||
UserInfoResp {
|
||||
Base
|
||||
Data *User `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: user
|
||||
prefix: /user
|
||||
jwt: JWT
|
||||
middleware: Auth
|
||||
)
|
||||
service test {
|
||||
@handler userInfo
|
||||
post /info/:id (UserInfoReq) returns (UserInfoResp)
|
||||
}
|
||||
|
||||
type (
|
||||
StudentClassNameListReq {
|
||||
Id int64 `string:"id"`
|
||||
}
|
||||
StudentInfoReq {
|
||||
Id int64 `path:"id"`
|
||||
}
|
||||
SutdentInfoResp {
|
||||
Base
|
||||
Data *Student `json:"data"`
|
||||
}
|
||||
UpdateStudentInfoReq {
|
||||
UserId int64 `form:"userId"`
|
||||
StudentId int64 `form:"studentId"`
|
||||
Number string `form:"number"`
|
||||
ClassId int64 `form:"classId"`
|
||||
SubjectId []int64 `form:"subjectId"`
|
||||
SubjectTop3 [3]int64 `form:"subjectTop3"`
|
||||
Extra map[string]interface{} `form:"extra"`
|
||||
}
|
||||
UpdateSutdentInfoResp {
|
||||
Base
|
||||
Data *Student `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
group: student
|
||||
prefix: /student
|
||||
jwt: JWT
|
||||
middleware: Auth
|
||||
)
|
||||
service test {
|
||||
@handler studentInfo
|
||||
get /info/:id (StudentInfoReq) returns (SutdentInfoResp)
|
||||
|
||||
@handler updateStudentInfo
|
||||
post /info/update (UpdateStudentInfoReq) returns (UpdateSutdentInfoResp)
|
||||
|
||||
@handler studentClassNameList
|
||||
post /class/name/list (StudentClassNameListReq) returns ([]string)
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/compare/testdata"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/console"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "compare",
|
||||
Short: "Compare the goctl commands generated results between urfave and cobra",
|
||||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dir := args[0]
|
||||
testdata.MustRun(dir)
|
||||
},
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
console.Error("%+v", err)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/compare/cmd"
|
||||
|
||||
// EXPERIMENTAL: compare goctl generated code results between old and new, it will be removed in the feature.
|
||||
// TODO: BEFORE RUNNING: export DSN=$datasource, the database must be gozero, and there has no limit for tables.
|
||||
// TODO: AFTER RUNNING: diff --recursive old_fs new_fs
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
||||
97
tools/goctl/compare/compare.sh
Normal file
97
tools/goctl/compare/compare.sh
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
# local compare test
|
||||
# compare goctl between latest and newest version if exists different.
|
||||
|
||||
execute_command() {
|
||||
local command="$1"
|
||||
|
||||
echo "=> $command"
|
||||
eval "$command"
|
||||
}
|
||||
|
||||
has_diff (){
|
||||
local command="$1"
|
||||
if $command &> /dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=======================env init============================="
|
||||
WD=$(readlink -f $(dirname $0))/build
|
||||
BIN=$WD/bin
|
||||
PROJECT_DIR=$WD/project
|
||||
OLD_CODE=$PROJECT_DIR/old
|
||||
NEW_CODE=$PROJECT_DIR/new
|
||||
|
||||
if [ -d $WD ]; then
|
||||
execute_command "rm -rf $WD"
|
||||
fi
|
||||
|
||||
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
||||
execute_command 'export GOPROXY="https://goproxy.cn,direct"'
|
||||
execute_command "export GOBIN=$BIN"
|
||||
|
||||
echo "=======================install goctl============================="
|
||||
# install latest goctl
|
||||
execute_command "go install github.com/zeromicro/go-zero/tools/goctl@master"
|
||||
execute_command "mv $BIN/goctl $BIN/goctl.old"
|
||||
execute_command "$BIN/goctl.old env"
|
||||
execute_command "$BIN/goctl.old env -w GOCTL_EXPERIMENTAL=on"
|
||||
|
||||
# install newest goctl
|
||||
execute_command "cd .."
|
||||
execute_command "go build -o goctl.new ."
|
||||
execute_command "mv goctl.new $BIN/goctl.new"
|
||||
execute_command "cd -"
|
||||
execute_command "$BIN/goctl.new env"
|
||||
execute_command "$BIN/goctl.new env -w GOCTL_EXPERIMENTAL=on"
|
||||
|
||||
echo "=======================go mod tidy============================="
|
||||
# go mod init
|
||||
execute_command "cd $OLD_CODE"
|
||||
execute_command "go mod init demo"
|
||||
execute_command "cd -"
|
||||
|
||||
execute_command "cd $NEW_CODE"
|
||||
execute_command "go mod init demo"
|
||||
execute_command "cd -"
|
||||
|
||||
echo "=======================generate api============================="
|
||||
execute_command "cd api"
|
||||
# generate api by goctl.old
|
||||
execute_command "$BIN/goctl.old api go --api test.api --dir $OLD_CODE/api"
|
||||
# generate api by goctl.new
|
||||
execute_command "$BIN/goctl.new api go --api test.api --dir $NEW_CODE/api"
|
||||
execute_command "cd -"
|
||||
|
||||
echo "=======================generate rpc============================="
|
||||
execute_command "cd rpc"
|
||||
# generate rpc by goctl.old
|
||||
execute_command "$BIN/goctl.old rpc protoc test.proto --go_out=$OLD_CODE/rpc --go-grpc_out=$OLD_CODE/rpc --zrpc_out=$OLD_CODE/rpc"
|
||||
# generate rpc by goctl.new
|
||||
execute_command "$BIN/goctl.new rpc protoc test.proto --go_out=$NEW_CODE/rpc --go-grpc_out=$NEW_CODE/rpc --zrpc_out=$NEW_CODE/rpc"
|
||||
execute_command "cd -"
|
||||
|
||||
echo "=======================generate model============================="
|
||||
execute_command "cd model"
|
||||
# generate model by goctl.old
|
||||
execute_command "$BIN/goctl.old model mysql ddl --src user.sql --dir $OLD_CODE/cache -c"
|
||||
execute_command "$BIN/goctl.old model mysql ddl --src user.sql --dir $OLD_CODE/nocache"
|
||||
# generate model by goctl.new
|
||||
execute_command "$BIN/goctl.new model mysql ddl --src user.sql --dir $NEW_CODE/cache -c"
|
||||
execute_command "$BIN/goctl.new model mysql ddl --src user.sql --dir $NEW_CODE/nocache"
|
||||
execute_command "cd -"
|
||||
|
||||
echo "=======================diff compare============================="
|
||||
# compare and diff
|
||||
if has_diff "diff -rq $OLD_CODE $NEW_CODE"; then
|
||||
echo "no diff"
|
||||
exit 0
|
||||
else
|
||||
echo "a diff found"
|
||||
execute_command "diff -r $OLD_CODE $NEW_CODE"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
wd=`dirname $0`
|
||||
GOBIN="$GOPATH/bin"
|
||||
EXE=goctl-compare
|
||||
go build -o $EXE $wd
|
||||
mv $EXE $GOBIN
|
||||
@@ -4,11 +4,12 @@ CREATE TABLE `user`
|
||||
`id` bigint(10) NOT NULL AUTO_INCREMENT,
|
||||
`user` varchar(50) NOT NULL DEFAULT '' COMMENT '用户',
|
||||
`name` varchar(255) COLLATE utf8mb4_general_ci NULL COMMENT '用户\t名称',
|
||||
`age` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '年龄',
|
||||
`password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户\n密码',
|
||||
`mobile` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '手机号',
|
||||
`gender` char(5) COLLATE utf8mb4_general_ci NOT NULL COMMENT '男|女|未公\r开',
|
||||
`nickname` varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '用户昵称',
|
||||
`type` tinyint(1) COLLATE utf8mb4_general_ci DEFAULT 0 COMMENT '用户类型',
|
||||
`type` tinyint(1) COLLATE utf8mb4_general_ci DEFAULT 0 COMMENT '用户类型',
|
||||
`create_time` timestamp NULL,
|
||||
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
@@ -21,14 +22,15 @@ CREATE TABLE `user`
|
||||
|
||||
CREATE TABLE `student`
|
||||
(
|
||||
`type` bigint NOT NULL,
|
||||
`class` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
|
||||
`name` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
|
||||
`age` tinyint DEFAULT NULL,
|
||||
`type` bigint NOT NULL,
|
||||
`class` varchar(255) NOT NULL DEFAULT '',
|
||||
`name` varchar(255) NOT NULL DEFAULT '',
|
||||
`age` tinyint DEFAULT NULL,
|
||||
`score` float(10, 0
|
||||
) DEFAULT NULL,
|
||||
`amount` decimal DEFAULT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`type`) USING BTREE,
|
||||
UNIQUE KEY `class_name_index` (`class`,`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
`delete_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`type`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
8
tools/goctl/compare/rpc/base/common.proto
Normal file
8
tools/goctl/compare/rpc/base/common.proto
Normal file
@@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package common;
|
||||
option go_package="./common";
|
||||
|
||||
message User {
|
||||
string name = 1;
|
||||
}
|
||||
65
tools/goctl/compare/rpc/test.proto
Normal file
65
tools/goctl/compare/rpc/test.proto
Normal file
@@ -0,0 +1,65 @@
|
||||
// test proto
|
||||
syntax = "proto3";
|
||||
|
||||
package test;
|
||||
|
||||
import "base/common.proto";
|
||||
option go_package = "github.com/test";
|
||||
|
||||
message Req {
|
||||
string in = 1;
|
||||
common.User user = 2;
|
||||
}
|
||||
|
||||
message Reply {
|
||||
string out = 1;
|
||||
}
|
||||
|
||||
message snake_req {}
|
||||
|
||||
message snake_reply {}
|
||||
|
||||
message CamelReq{}
|
||||
|
||||
message CamelReply{}
|
||||
|
||||
message EnumMessage {
|
||||
enum Enum {
|
||||
unknown = 0;
|
||||
male = 1;
|
||||
female = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message CommonReply{}
|
||||
|
||||
message MapReq{
|
||||
map<string, string> m = 1;
|
||||
}
|
||||
|
||||
message RepeatedReq{
|
||||
repeated string id = 1;
|
||||
}
|
||||
|
||||
service Test_Service {
|
||||
// service
|
||||
rpc Service (Req) returns (Reply);
|
||||
// greet service
|
||||
rpc GreetService (Req) returns (Reply);
|
||||
// case snake
|
||||
rpc snake_service (snake_req) returns (snake_reply);
|
||||
// case camel
|
||||
rpc CamelService (CamelReq) returns (CamelReply);
|
||||
// case enum
|
||||
rpc EnumService (EnumMessage) returns (CommonReply);
|
||||
// case map
|
||||
rpc MapService (MapReq) returns (CommonReply);
|
||||
// case repeated
|
||||
rpc RepeatedService (RepeatedReq) returns (CommonReply);
|
||||
// server stream
|
||||
rpc ServerStream (Req) returns (stream Reply);
|
||||
// client stream
|
||||
rpc ClientStream (stream Req) returns (Reply);
|
||||
// stream
|
||||
rpc Stream(stream Req) returns (stream Reply);
|
||||
}
|
||||
17
tools/goctl/compare/testdata/kotlin.api
vendored
17
tools/goctl/compare/testdata/kotlin.api
vendored
@@ -1,17 +0,0 @@
|
||||
syntax = "v1"
|
||||
|
||||
info(
|
||||
title: "type title here"
|
||||
desc: "type desc here"
|
||||
author: "type author here"
|
||||
email: "type email here"
|
||||
version: "type version here"
|
||||
)
|
||||
|
||||
type req{}
|
||||
type reply{}
|
||||
|
||||
service kotlin-api{
|
||||
@handler ping
|
||||
post /ping
|
||||
}
|
||||
470
tools/goctl/compare/testdata/testcase.go
vendored
470
tools/goctl/compare/testdata/testcase.go
vendored
@@ -1,470 +0,0 @@
|
||||
package testdata
|
||||
|
||||
import _ "embed"
|
||||
|
||||
var (
|
||||
//go:embed unformat.api
|
||||
unformatApi string
|
||||
//go:embed kotlin.api
|
||||
kotlinApi string
|
||||
//go:embed user.sql
|
||||
userSql string
|
||||
|
||||
list = Files{
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "version",
|
||||
Cmd: "goctl --version",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/local",
|
||||
Cmd: "goctl api --o sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/local/assign",
|
||||
Cmd: "goctl api --o=sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/local/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/remote",
|
||||
Cmd: "goctl api --o sample.api --remote https://github.com/zeromicro/go-zero-template --branch main",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/remote/shorthand",
|
||||
Cmd: "goctl api -o sample.api -remote https://github.com/zeromicro/go-zero-template -branch main",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/remote/assign",
|
||||
Cmd: "goctl api --o=sample.api --remote https://github.com/zeromicro/go-zero-template --branch=main",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/sample_file/remote/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api -remote https://github.com/zeromicro/go-zero-template -branch=main",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/true",
|
||||
Cmd: "goctl api --o sample.api && goctl api dart --api sample.api --dir . --hostname 127.0.0.1 --legacy true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/true/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api dart -api sample.api -dir . -hostname 127.0.0.1 -legacy true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/true/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api dart --api=sample.api --dir=. --hostname=127.0.0.1 --legacy=true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/true/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api && goctl api dart -api=sample.api -dir=. -hostname=127.0.0.1 -legacy=true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/false",
|
||||
Cmd: "goctl api --o sample.api && goctl api dart --api sample.api --dir . --hostname 127.0.0.1 --legacy true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/false/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api dart -api sample.api -dir . -hostname 127.0.0.1 -legacy true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/false/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api dart --api=sample.api --dir=. --hostname=127.0.0.1 --legacy=true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/dart/legacy/false/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api && goctl api dart -api=sample.api -dir=. -hostname=127.0.0.1 -legacy=true",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/doc",
|
||||
Cmd: "goctl api --o sample.api && goctl api doc --dir . --o .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/doc/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api doc -dir . -o .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/doc/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api doc --dir=. --o=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/doc/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api && goctl api doc -dir=. -o=.",
|
||||
},
|
||||
{
|
||||
Path: "api/format/unformat.api",
|
||||
Content: unformatApi,
|
||||
Cmd: "goctl api format --dir . --iu",
|
||||
},
|
||||
{
|
||||
Path: "api/format/shorthand/unformat.api",
|
||||
Content: unformatApi,
|
||||
Cmd: "goctl api format -dir . -iu",
|
||||
},
|
||||
{
|
||||
Path: "api/format/assign/unformat.api",
|
||||
Content: unformatApi,
|
||||
Cmd: "goctl api format --dir=. --iu",
|
||||
},
|
||||
{
|
||||
Path: "api/format/assign/shorthand/unformat.api",
|
||||
Content: unformatApi,
|
||||
Cmd: "goctl api format -dir=. -iu",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/default",
|
||||
Cmd: "goctl api --o sample.api && goctl api go --api sample.api --dir .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/default/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api go -api sample.api -dir .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/assign/default",
|
||||
Cmd: "goctl api --o=sample.api && goctl api go --api=sample.api --dir=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/assign/default/shorthand",
|
||||
Cmd: "goctl api -o=sample.api && goctl api go -api=sample.api -dir=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/goZero",
|
||||
Cmd: "goctl api --o sample.api && goctl api go --api sample.api --dir . --style goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/goZero/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api go -api sample.api -dir . -style goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/goZero/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api go --api=sample.api --dir=. --style=goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/go/style/goZero/assign/shorthand",
|
||||
Cmd: "goctl api -o=sample.api && goctl api go -api=sample.api -dir=. -style=goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/java",
|
||||
Cmd: "goctl api --o sample.api && goctl api java --api sample.api --dir .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/java/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api java -api sample.api -dir .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/java/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api java --api=sample.api --dir=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/java/shorthand/assign",
|
||||
Cmd: "goctl api -o=sample.api && goctl api java -api=sample.api -dir=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/new/style/default",
|
||||
Cmd: "goctl api new greet",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/new/style/goZero",
|
||||
Cmd: "goctl api new greet --style goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/new/style/goZero/assign",
|
||||
Cmd: "goctl api new greet --style=goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/new/style/goZero/shorthand",
|
||||
Cmd: "goctl api new greet -style goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/new/style/goZero/shorthand/assign",
|
||||
Cmd: "goctl api new greet -style=goZero",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/ts",
|
||||
Cmd: "goctl api --o sample.api && goctl api ts --api sample.api --dir . --unwrap --webapi .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/ts/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api ts -api sample.api -dir . -unwrap -webapi .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/ts/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api ts --api=sample.api --dir=. --unwrap --webapi=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/ts/shorthand/assign",
|
||||
Cmd: "goctl api -o=sample.api && goctl api ts -api=sample.api -dir=. -unwrap -webapi=.",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/validate",
|
||||
Cmd: "goctl api --o sample.api && goctl api validate --api sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/validate/shorthand",
|
||||
Cmd: "goctl api -o sample.api && goctl api validate -api sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/validate/assign",
|
||||
Cmd: "goctl api --o=sample.api && goctl api validate --api=sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "api/validate/shorthand/assign",
|
||||
Cmd: "goctl api -o=sample.api && goctl api validate -api=sample.api",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "env/show",
|
||||
Cmd: "goctl env > env.txt",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "env/check",
|
||||
Cmd: "goctl env check -f -v",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "env/install",
|
||||
Cmd: "goctl env install -v",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "kube",
|
||||
Cmd: "goctl kube deploy --image alpine --name foo --namespace foo --o foo.yaml --port 8888",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "kube/shorthand",
|
||||
Cmd: "goctl kube deploy -image alpine -name foo -namespace foo -o foo.yaml -port 8888",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "kube/assign",
|
||||
Cmd: "goctl kube deploy --image=alpine --name=foo --namespace=foo --o=foo.yaml --port=8888",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "kube/shorthand/assign",
|
||||
Cmd: "goctl kube deploy -image=alpine -name=foo -namespace=foo -o=foo.yaml -port=8888",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/cache",
|
||||
Cmd: "goctl model mongo --dir . --type user --style goZero -c",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/cache/shorthand",
|
||||
Cmd: "goctl model mongo -dir . -type user -style goZero -c",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/cache/assign",
|
||||
Cmd: "goctl model mongo --dir=. --type=user --style=goZero -c",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/cache/shorthand/assign",
|
||||
Cmd: "goctl model mongo -dir=. -type=user -style=goZero -c",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/nocache",
|
||||
Cmd: "goctl model mongo --dir . --type user",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/nocache/shorthand",
|
||||
Cmd: "goctl model mongo -dir . -type user",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/nocache/assign",
|
||||
Cmd: "goctl model mongo --dir=. --type=user",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mongo/nocache/shorthand/assign",
|
||||
Cmd: "goctl model mongo -dir=. -type=user",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/user.sql",
|
||||
Cmd: "goctl model mysql ddl --database user --dir cache --src user.sql -c",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/shorthand/user.sql",
|
||||
Cmd: "goctl model mysql ddl -database user -dir cache -src user.sql -c",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/assign/user.sql",
|
||||
Cmd: "goctl model mysql ddl --database=user --dir=cache --src=user.sql -c",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/shorthand/assign/user.sql",
|
||||
Cmd: "goctl model mysql ddl -database=user -dir=cache -src=user.sql -c",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/user.sql",
|
||||
Cmd: "goctl model mysql ddl --database user --dir nocache --src user.sql",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/shorthand/user.sql",
|
||||
Cmd: "goctl model mysql ddl -database user -dir nocache -src user.sql",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/assign/user.sql",
|
||||
Cmd: "goctl model mysql ddl --database=user --dir=nocache --src=user.sql",
|
||||
},
|
||||
{
|
||||
Content: userSql,
|
||||
Path: "model/mysql/ddl/shorthand/assign/user.sql",
|
||||
Cmd: "goctl model mysql ddl -database=user -dir=nocache -src=user.sql",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource",
|
||||
Cmd: `goctl model mysql datasource --url $DSN --dir cache --table "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand",
|
||||
Cmd: `goctl model mysql datasource -url $DSN -dir cache -table "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand2",
|
||||
Cmd: `goctl model mysql datasource -url $DSN -dir cache -t "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/assign",
|
||||
Cmd: `goctl model mysql datasource --url=$DSN --dir=cache --table="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand/assign",
|
||||
Cmd: `goctl model mysql datasource -url=$DSN -dir=cache -table="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand2/assign",
|
||||
Cmd: `goctl model mysql datasource -url=$DSN -dir=cache -t="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource",
|
||||
Cmd: `goctl model mysql datasource --url $DSN --dir nocache --table "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand",
|
||||
Cmd: `goctl model mysql datasource -url $DSN -dir nocache -table "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand2",
|
||||
Cmd: `goctl model mysql datasource -url $DSN -dir nocache -t "*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/assign",
|
||||
Cmd: `goctl model mysql datasource --url=$DSN --dir=nocache --table="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand/assign",
|
||||
Cmd: `goctl model mysql datasource -url=$DSN -dir=nocache -table="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "model/mysql/datasource/shorthand2/assign",
|
||||
Cmd: `goctl model mysql datasource -url=$DSN -dir=nocache -t="*" -c`,
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/new",
|
||||
Cmd: "goctl rpc new greet",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/template",
|
||||
Cmd: "goctl rpc template --o greet.proto",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/template/shorthand",
|
||||
Cmd: "goctl rpc template -o greet.proto",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/template/assign",
|
||||
Cmd: "goctl rpc template --o=greet.proto",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/template/shorthand/assign",
|
||||
Cmd: "goctl rpc template -o=greet.proto",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/protoc",
|
||||
Cmd: "goctl rpc template --o greet.proto && goctl rpc protoc greet.proto --go_out . --go-grpc_out . --zrpc_out .",
|
||||
},
|
||||
{
|
||||
IsDir: true,
|
||||
Path: "rpc/protoc/assign",
|
||||
Cmd: "goctl rpc template --o=greet.proto && goctl rpc protoc greet.proto --go_out=. --go-grpc_out=. --zrpc_out=.",
|
||||
},
|
||||
}
|
||||
)
|
||||
119
tools/goctl/compare/testdata/testdata.go
vendored
119
tools/goctl/compare/testdata/testdata.go
vendored
@@ -1,119 +0,0 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
type (
|
||||
File struct {
|
||||
IsDir bool
|
||||
Path string
|
||||
AbsolutePath string
|
||||
Content string
|
||||
Cmd string
|
||||
}
|
||||
|
||||
Files []File
|
||||
)
|
||||
|
||||
func (f File) execute(goctl string) error {
|
||||
printDir := f.Path
|
||||
dir := f.AbsolutePath
|
||||
if !f.IsDir {
|
||||
printDir = filepath.Dir(printDir)
|
||||
dir = filepath.Dir(dir)
|
||||
}
|
||||
printCommand := strings.ReplaceAll(fmt.Sprintf("cd %s && %s", printDir, f.Cmd), "goctl", filepath.Base(goctl))
|
||||
command := strings.ReplaceAll(fmt.Sprintf("cd %s && %s", dir, f.Cmd), "goctl", goctl)
|
||||
fmt.Println(color.LightGreen.Render(printCommand))
|
||||
cmd := exec.Command("sh", "-c", command)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (fs Files) execute(goctl string) error {
|
||||
for _, f := range fs {
|
||||
err := f.execute(goctl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mustGetTestData(baseDir string) (Files, Files) {
|
||||
if len(baseDir) == 0 {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
baseDir = dir
|
||||
}
|
||||
baseDir, err := filepath.Abs(baseDir)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
createFile := func(baseDir string, data File) (File, error) {
|
||||
fp := filepath.Join(baseDir, data.Path)
|
||||
dir := filepath.Dir(fp)
|
||||
if data.IsDir {
|
||||
dir = fp
|
||||
}
|
||||
if err := pathx.MkdirIfNotExist(dir); err != nil {
|
||||
return data, err
|
||||
}
|
||||
data.AbsolutePath = fp
|
||||
if data.IsDir {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
return data, os.WriteFile(fp, []byte(data.Content), os.ModePerm)
|
||||
}
|
||||
oldDir := filepath.Join(baseDir, "old_fs")
|
||||
newDir := filepath.Join(baseDir, "new_fs")
|
||||
os.RemoveAll(oldDir)
|
||||
os.RemoveAll(newDir)
|
||||
var oldFiles, newFiles []File
|
||||
for _, data := range list {
|
||||
od, err := createFile(oldDir, data)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
oldFiles = append(oldFiles, od)
|
||||
nd, err := createFile(newDir, data)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
newFiles = append(newFiles, nd)
|
||||
}
|
||||
return oldFiles, newFiles
|
||||
}
|
||||
|
||||
func MustRun(baseDir string) {
|
||||
oldFiles, newFiles := mustGetTestData(baseDir)
|
||||
goctlOld, err := exec.LookPath("goctl.old")
|
||||
must(err)
|
||||
goctlNew, err := exec.LookPath("goctl")
|
||||
must(err)
|
||||
fmt.Println(color.LightBlue.Render("========================goctl.old======================="))
|
||||
must(oldFiles.execute(goctlOld))
|
||||
fmt.Println()
|
||||
fmt.Println(color.LightBlue.Render("========================goctl.new======================="))
|
||||
must(newFiles.execute(goctlNew))
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
3
tools/goctl/compare/testdata/unformat.api
vendored
3
tools/goctl/compare/testdata/unformat.api
vendored
@@ -1,3 +0,0 @@
|
||||
syntax = "v1"
|
||||
|
||||
type Foo struct{}
|
||||
@@ -15,10 +15,10 @@ require (
|
||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
||||
github.com/zeromicro/antlr v0.0.1
|
||||
github.com/zeromicro/ddl-parser v1.0.5
|
||||
github.com/zeromicro/go-zero v1.7.0
|
||||
golang.org/x/text v0.16.0
|
||||
github.com/zeromicro/go-zero v1.7.3
|
||||
golang.org/x/text v0.19.0
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
google.golang.org/protobuf v1.35.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
@@ -56,6 +56,7 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
@@ -66,11 +67,11 @@ require (
|
||||
github.com/openzipkin/zipkin-go v0.4.3 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.19.1 // indirect
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.48.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/redis/go-redis/v9 v9.6.1 // indirect
|
||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.55.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.7.0 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
github.com/yuin/gopher-lua v1.1.1 // indirect
|
||||
@@ -89,16 +90,16 @@ require (
|
||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/automaxprocs v1.5.3 // indirect
|
||||
go.uber.org/automaxprocs v1.6.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.25.0 // indirect
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/oauth2 v0.20.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
golang.org/x/term v0.22.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/oauth2 v0.21.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/term v0.25.0 // indirect
|
||||
golang.org/x/time v0.7.0 // 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
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
|
||||
@@ -94,12 +94,15 @@ 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/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/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
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.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
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.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
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/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
@@ -126,16 +129,16 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
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/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
|
||||
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
|
||||
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
||||
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
||||
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
||||
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
|
||||
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
|
||||
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_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
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.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
|
||||
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/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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
@@ -170,8 +173,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/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
||||
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/go-zero v1.7.0 h1:B+y7tUVlo3qVQ6F0I0R9bi+Dq4I1QdO9ZB+dz1r0p1s=
|
||||
github.com/zeromicro/go-zero v1.7.0/go.mod h1:ypW4PzQI+jUrMcNJDDQ+7YW+pE+tMua9Xj/pmtmS1Dc=
|
||||
github.com/zeromicro/go-zero v1.7.3 h1:yDUQF2DXDhUHc77/NZF6mzsoRPMBfldjPmG2O/ZSzss=
|
||||
github.com/zeromicro/go-zero v1.7.3/go.mod h1:9JIW3gHBGuc9LzvjZnNwINIq9QdiKu3AigajLtkJamQ=
|
||||
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/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
||||
@@ -202,8 +205,8 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
|
||||
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
|
||||
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/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
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=
|
||||
@@ -212,8 +215,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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
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.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
@@ -222,16 +225,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-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.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
|
||||
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
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/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-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.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -240,17 +243,17 @@ 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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.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.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
|
||||
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
|
||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
||||
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.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
|
||||
golang.org/x/time v0.7.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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
@@ -267,8 +270,8 @@ 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/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/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 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildVersion is the version of goctl.
|
||||
const BuildVersion = "1.7.0"
|
||||
const BuildVersion = "1.7.3"
|
||||
|
||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ spec:
|
||||
|
||||
---
|
||||
|
||||
apiVersion: autoscaling/v2beta2
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: {{.Name}}-hpa-c
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/model/mongo/template"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
||||
@@ -59,6 +60,7 @@ func generateModel(ctx *Context) error {
|
||||
"Type": stringx.From(t).Title(),
|
||||
"lowerType": stringx.From(t).Untitle(),
|
||||
"Cache": ctx.Cache,
|
||||
"version": version.BuildVersion,
|
||||
}, output, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
@@ -44,6 +45,8 @@ var ModelCustom string
|
||||
|
||||
// ModelGen defines a template for model
|
||||
var ModelGen = fmt.Sprintf(`%s
|
||||
// versions:
|
||||
// goctl version: %s
|
||||
|
||||
package {{.pkg}}
|
||||
{{.imports}}
|
||||
@@ -57,7 +60,7 @@ package {{.pkg}}
|
||||
{{.extraMethod}}
|
||||
{{.tableName}}
|
||||
{{.customized}}
|
||||
`, util.DoNotEditHead)
|
||||
`, util.DoNotEditHead, version.BuildVersion)
|
||||
|
||||
// Insert defines a template for insert code in model
|
||||
//
|
||||
|
||||
@@ -54,7 +54,7 @@ func (a *Analyzer) astTypeToSpec(in ast.DataType) (spec.Type, error) {
|
||||
return nil, ast.SyntaxError(v.Pos(), "unsupported empty struct")
|
||||
}
|
||||
|
||||
return spec.DefineStruct{
|
||||
return spec.NestedStruct{
|
||||
RawName: v.RawText(),
|
||||
Members: members,
|
||||
}, nil
|
||||
@@ -78,7 +78,7 @@ func (a *Analyzer) astTypeToSpec(in ast.DataType) (spec.Type, error) {
|
||||
|
||||
return spec.MapType{
|
||||
RawName: v.RawText(),
|
||||
Key: v.RawText(),
|
||||
Key: v.Key.RawText(),
|
||||
Value: value,
|
||||
}, nil
|
||||
case *ast.PointerDataType:
|
||||
@@ -347,14 +347,12 @@ func (a *Analyzer) fillTypes() error {
|
||||
for _, member := range v.Members {
|
||||
switch v := member.Type.(type) {
|
||||
case spec.DefineStruct:
|
||||
if !v.IsNestedStruct() {
|
||||
tp, err := a.findDefinedType(v.RawName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
member.Type = tp
|
||||
tp, err := a.findDefinedType(v.RawName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
member.Type = tp
|
||||
}
|
||||
members = append(members, member)
|
||||
}
|
||||
|
||||
@@ -56,12 +56,8 @@ func initProject() {
|
||||
}
|
||||
|
||||
log.Must(pathx.MkdirIfNotExist(projectDir))
|
||||
if hasGoMod, _ := ctx.IsGoMod(projectDir); hasGoMod {
|
||||
return
|
||||
}
|
||||
if exitCode := execCommand(projectDir, "go mod init "+baseDir); exitCode != 0 {
|
||||
log.Fatalln("Init process exit")
|
||||
}
|
||||
_, err = ctx.Prepare(projectDir)
|
||||
logx.Must(err)
|
||||
}
|
||||
|
||||
func run(_ *cobra.Command, _ []string) error {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
// GenPb generates the pb.go file, which is a layer of packaging for protoc to generate gprc,
|
||||
@@ -88,7 +89,7 @@ func findPbFile(current string, src string, grpc bool) (string, error) {
|
||||
return nil
|
||||
})
|
||||
if errors.Is(err, os.ErrExist) {
|
||||
return filepath.Dir(filepath.Join(current, ret)), nil
|
||||
return pathx.ReadLink(filepath.Dir(filepath.Join(current, ret)))
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -62,4 +62,4 @@ service Test_Service {
|
||||
rpc ClientStream (stream Req) returns (Reply);
|
||||
// stream
|
||||
rpc Stream(stream Req) returns (stream Reply);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ func Test_getRealModule(t *testing.T) {
|
||||
"Path":"foo",
|
||||
"Dir":"/home/foo",
|
||||
"GoMod":"/home/foo/go.mod",
|
||||
"GoVersion":"go1.19"
|
||||
"GoVersion":"go1.20"
|
||||
}
|
||||
{
|
||||
"Path":"bar",
|
||||
"Dir":"/home/bar",
|
||||
"GoMod":"/home/bar/go.mod",
|
||||
"GoVersion":"go1.19"
|
||||
"GoVersion":"go1.20"
|
||||
}`, nil
|
||||
},
|
||||
},
|
||||
@@ -95,7 +95,7 @@ func Test_getRealModule(t *testing.T) {
|
||||
Path: "bar",
|
||||
Dir: "/home/bar",
|
||||
GoMod: "/home/bar/go.mod",
|
||||
GoVersion: "go1.19",
|
||||
GoVersion: "go1.20",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -143,26 +143,26 @@ func TestDecodePackages(t *testing.T) {
|
||||
"Path":"foo",
|
||||
"Dir":"/home/foo",
|
||||
"GoMod":"/home/foo/go.mod",
|
||||
"GoVersion":"go1.19"
|
||||
"GoVersion":"go1.20"
|
||||
}
|
||||
{
|
||||
"Path":"bar",
|
||||
"Dir":"/home/bar",
|
||||
"GoMod":"/home/bar/go.mod",
|
||||
"GoVersion":"go1.19"
|
||||
"GoVersion":"go1.20"
|
||||
}`),
|
||||
want: []Module{
|
||||
{
|
||||
Path: "foo",
|
||||
Dir: "/home/foo",
|
||||
GoMod: "/home/foo/go.mod",
|
||||
GoVersion: "go1.19",
|
||||
GoVersion: "go1.20",
|
||||
},
|
||||
{
|
||||
Path: "bar",
|
||||
Dir: "/home/bar",
|
||||
GoMod: "/home/bar/go.mod",
|
||||
GoVersion: "go1.19",
|
||||
GoVersion: "go1.20",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -173,14 +173,14 @@ func TestDecodePackages(t *testing.T) {
|
||||
"Path":"foo",
|
||||
"Dir":"/home/foo",
|
||||
"GoMod":"/home/foo/go.mod",
|
||||
"GoVersion":"go1.19"
|
||||
"GoVersion":"go1.20"
|
||||
}`),
|
||||
want: []Module{
|
||||
{
|
||||
Path: "foo",
|
||||
Dir: "/home/foo",
|
||||
GoMod: "/home/foo/go.mod",
|
||||
GoVersion: "go1.19",
|
||||
GoVersion: "go1.20",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
package util
|
||||
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
|
||||
const (
|
||||
// DoNotEditHead added to the beginning of a file to prompt the user not to edit
|
||||
DoNotEditHead = "// Code generated by goctl. DO NOT EDIT."
|
||||
|
||||
headTemplate = DoNotEditHead + `
|
||||
// goctl {{.version}}
|
||||
// Source: {{.source}}`
|
||||
)
|
||||
|
||||
// GetHead returns a code head string with source filename
|
||||
func GetHead(source string) string {
|
||||
buffer, _ := With("head").Parse(headTemplate).Execute(map[string]any{
|
||||
"source": source,
|
||||
"source": source,
|
||||
"version": version.BuildVersion,
|
||||
})
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ const (
|
||||
)
|
||||
|
||||
// NewRpcPubServer returns a Server.
|
||||
func NewRpcPubServer(etcd discov.EtcdConf, listenOn string, middlewares ServerMiddlewaresConf,
|
||||
func NewRpcPubServer(etcd discov.EtcdConf, listenOn string,
|
||||
opts ...ServerOption) (Server, error) {
|
||||
registerEtcd := func() error {
|
||||
pubListenOn := figureOutListenOn(listenOn)
|
||||
@@ -34,7 +34,7 @@ func NewRpcPubServer(etcd discov.EtcdConf, listenOn string, middlewares ServerMi
|
||||
}
|
||||
server := keepAliveServer{
|
||||
registerEtcd: registerEtcd,
|
||||
Server: NewRpcServer(listenOn, middlewares, opts...),
|
||||
Server: NewRpcServer(listenOn, opts...),
|
||||
}
|
||||
|
||||
return server, nil
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestNewRpcPubServer(t *testing.T) {
|
||||
User: "user",
|
||||
Pass: "pass",
|
||||
ID: 10,
|
||||
}, "", ServerMiddlewaresConf{})
|
||||
}, "")
|
||||
assert.NoError(t, err)
|
||||
assert.NotPanics(t, func() {
|
||||
s.Start(nil)
|
||||
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/proc"
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"github.com/zeromicro/go-zero/internal/health"
|
||||
"github.com/zeromicro/go-zero/zrpc/internal/serverinterceptors"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
@@ -19,38 +17,31 @@ type (
|
||||
ServerOption func(options *rpcServerOptions)
|
||||
|
||||
rpcServerOptions struct {
|
||||
metrics *stat.Metrics
|
||||
health bool
|
||||
health bool
|
||||
}
|
||||
|
||||
rpcServer struct {
|
||||
*baseRpcServer
|
||||
name string
|
||||
middlewares ServerMiddlewaresConf
|
||||
healthManager health.Probe
|
||||
}
|
||||
)
|
||||
|
||||
// NewRpcServer returns a Server.
|
||||
func NewRpcServer(addr string, middlewares ServerMiddlewaresConf, opts ...ServerOption) Server {
|
||||
func NewRpcServer(addr string, opts ...ServerOption) Server {
|
||||
var options rpcServerOptions
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
if options.metrics == nil {
|
||||
options.metrics = stat.NewMetrics(addr)
|
||||
}
|
||||
|
||||
return &rpcServer{
|
||||
baseRpcServer: newBaseRpcServer(addr, &options),
|
||||
middlewares: middlewares,
|
||||
healthManager: health.NewHealthManager(fmt.Sprintf("%s-%s", probeNamePrefix, addr)),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *rpcServer) SetName(name string) {
|
||||
s.name = name
|
||||
s.baseRpcServer.SetName(name)
|
||||
}
|
||||
|
||||
func (s *rpcServer) Start(register RegisterFn) error {
|
||||
@@ -59,8 +50,8 @@ func (s *rpcServer) Start(register RegisterFn) error {
|
||||
return err
|
||||
}
|
||||
|
||||
unaryInterceptorOption := grpc.ChainUnaryInterceptor(s.buildUnaryInterceptors()...)
|
||||
streamInterceptorOption := grpc.ChainStreamInterceptor(s.buildStreamInterceptors()...)
|
||||
unaryInterceptorOption := grpc.ChainUnaryInterceptor(s.unaryInterceptors...)
|
||||
streamInterceptorOption := grpc.ChainStreamInterceptor(s.streamInterceptors...)
|
||||
|
||||
options := append(s.options, unaryInterceptorOption, streamInterceptorOption)
|
||||
server := grpc.NewServer(options...)
|
||||
@@ -87,52 +78,6 @@ func (s *rpcServer) Start(register RegisterFn) error {
|
||||
return server.Serve(lis)
|
||||
}
|
||||
|
||||
func (s *rpcServer) buildStreamInterceptors() []grpc.StreamServerInterceptor {
|
||||
var interceptors []grpc.StreamServerInterceptor
|
||||
|
||||
if s.middlewares.Trace {
|
||||
interceptors = append(interceptors, serverinterceptors.StreamTracingInterceptor)
|
||||
}
|
||||
if s.middlewares.Recover {
|
||||
interceptors = append(interceptors, serverinterceptors.StreamRecoverInterceptor)
|
||||
}
|
||||
if s.middlewares.Breaker {
|
||||
interceptors = append(interceptors, serverinterceptors.StreamBreakerInterceptor)
|
||||
}
|
||||
|
||||
return append(interceptors, s.streamInterceptors...)
|
||||
}
|
||||
|
||||
func (s *rpcServer) buildUnaryInterceptors() []grpc.UnaryServerInterceptor {
|
||||
var interceptors []grpc.UnaryServerInterceptor
|
||||
|
||||
if s.middlewares.Trace {
|
||||
interceptors = append(interceptors, serverinterceptors.UnaryTracingInterceptor)
|
||||
}
|
||||
if s.middlewares.Recover {
|
||||
interceptors = append(interceptors, serverinterceptors.UnaryRecoverInterceptor)
|
||||
}
|
||||
if s.middlewares.Stat {
|
||||
interceptors = append(interceptors,
|
||||
serverinterceptors.UnaryStatInterceptor(s.metrics, s.middlewares.StatConf))
|
||||
}
|
||||
if s.middlewares.Prometheus {
|
||||
interceptors = append(interceptors, serverinterceptors.UnaryPrometheusInterceptor)
|
||||
}
|
||||
if s.middlewares.Breaker {
|
||||
interceptors = append(interceptors, serverinterceptors.UnaryBreakerInterceptor)
|
||||
}
|
||||
|
||||
return append(interceptors, s.unaryInterceptors...)
|
||||
}
|
||||
|
||||
// WithMetrics returns a func that sets metrics to a Server.
|
||||
func WithMetrics(metrics *stat.Metrics) ServerOption {
|
||||
return func(options *rpcServerOptions) {
|
||||
options.metrics = metrics
|
||||
}
|
||||
}
|
||||
|
||||
// WithRpcHealth returns a func that sets rpc health switch to a Server.
|
||||
func WithRpcHealth(health bool) ServerOption {
|
||||
return func(options *rpcServerOptions) {
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/proc"
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"github.com/zeromicro/go-zero/internal/mock"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TestRpcServer(t *testing.T) {
|
||||
metrics := stat.NewMetrics("foo")
|
||||
server := NewRpcServer("localhost:54321", ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
}, WithMetrics(metrics), WithRpcHealth(true))
|
||||
server := NewRpcServer("localhost:54321", WithRpcHealth(true))
|
||||
server.SetName("mock")
|
||||
var wg, wgDone sync.WaitGroup
|
||||
var grpcServer *grpc.Server
|
||||
@@ -52,13 +43,7 @@ func TestRpcServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRpcServer_WithBadAddress(t *testing.T) {
|
||||
server := NewRpcServer("localhost:111111", ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
}, WithRpcHealth(true))
|
||||
server := NewRpcServer("localhost:111111", WithRpcHealth(true))
|
||||
server.SetName("mock")
|
||||
err := server.Start(func(server *grpc.Server) {
|
||||
mock.RegisterDepositServiceServer(server, new(mock.DepositServer))
|
||||
@@ -67,115 +52,3 @@ func TestRpcServer_WithBadAddress(t *testing.T) {
|
||||
|
||||
proc.WrapUp()
|
||||
}
|
||||
|
||||
func TestRpcServer_buildUnaryInterceptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *rpcServer
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{},
|
||||
},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
unaryInterceptors: []grpc.UnaryServerInterceptor{
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
unaryInterceptors: []grpc.UnaryServerInterceptor{
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 6,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.len, len(test.r.buildUnaryInterceptors()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRpcServer_buildStreamInterceptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *rpcServer
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{},
|
||||
},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
streamInterceptors: []grpc.StreamServerInterceptor{
|
||||
func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
streamInterceptors: []grpc.StreamServerInterceptor{
|
||||
func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 4,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.len, len(test.r.buildStreamInterceptors()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package internal
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/health"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
@@ -27,7 +26,6 @@ type (
|
||||
baseRpcServer struct {
|
||||
address string
|
||||
health *health.Server
|
||||
metrics *stat.Metrics
|
||||
options []grpc.ServerOption
|
||||
streamInterceptors []grpc.StreamServerInterceptor
|
||||
unaryInterceptors []grpc.UnaryServerInterceptor
|
||||
@@ -42,7 +40,6 @@ func newBaseRpcServer(address string, rpcServerOpts *rpcServerOptions) *baseRpcS
|
||||
return &baseRpcServer{
|
||||
address: address,
|
||||
health: h,
|
||||
metrics: rpcServerOpts.metrics,
|
||||
options: []grpc.ServerOption{grpc.KeepaliveParams(keepalive.ServerParameters{
|
||||
MaxConnectionIdle: defaultConnectionIdleDuration,
|
||||
})},
|
||||
@@ -60,7 +57,3 @@ func (s *baseRpcServer) AddStreamInterceptors(interceptors ...grpc.StreamServerI
|
||||
func (s *baseRpcServer) AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) {
|
||||
s.unaryInterceptors = append(s.unaryInterceptors, interceptors...)
|
||||
}
|
||||
|
||||
func (s *baseRpcServer) SetName(name string) {
|
||||
s.metrics.SetName(name)
|
||||
}
|
||||
|
||||
@@ -5,23 +5,18 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TestBaseRpcServer_AddOptions(t *testing.T) {
|
||||
metrics := stat.NewMetrics("foo")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{metrics: metrics})
|
||||
server.SetName("bar")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{})
|
||||
var opt grpc.EmptyServerOption
|
||||
server.AddOptions(opt)
|
||||
assert.Contains(t, server.options, opt)
|
||||
}
|
||||
|
||||
func TestBaseRpcServer_AddStreamInterceptors(t *testing.T) {
|
||||
metrics := stat.NewMetrics("foo")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{metrics: metrics})
|
||||
server.SetName("bar")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{})
|
||||
var vals []int
|
||||
f := func(_ any, _ grpc.ServerStream, _ *grpc.StreamServerInfo, _ grpc.StreamHandler) error {
|
||||
vals = append(vals, 1)
|
||||
@@ -35,9 +30,7 @@ func TestBaseRpcServer_AddStreamInterceptors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBaseRpcServer_AddUnaryInterceptors(t *testing.T) {
|
||||
metrics := stat.NewMetrics("foo")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{metrics: metrics})
|
||||
server.SetName("bar")
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{})
|
||||
var vals []int
|
||||
f := func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (
|
||||
resp any, err error) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !no_k8s
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
|
||||
8
zrpc/resolver/internal/register.go
Normal file
8
zrpc/resolver/internal/register.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build no_k8s
|
||||
|
||||
package internal
|
||||
|
||||
// RegisterResolver registers the direct, etcd and discov schemes to the resolver.
|
||||
func RegisterResolver() {
|
||||
register()
|
||||
}
|
||||
13
zrpc/resolver/internal/register_k8s.go
Normal file
13
zrpc/resolver/internal/register_k8s.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build !no_k8s
|
||||
|
||||
package internal
|
||||
|
||||
import "google.golang.org/grpc/resolver"
|
||||
|
||||
var k8sResolverBuilder kubeBuilder
|
||||
|
||||
// RegisterResolver registers the direct, etcd, discov and k8s schemes to the resolver.
|
||||
func RegisterResolver() {
|
||||
register()
|
||||
resolver.Register(&k8sResolverBuilder)
|
||||
}
|
||||
@@ -28,15 +28,12 @@ var (
|
||||
directResolverBuilder directBuilder
|
||||
discovResolverBuilder discovBuilder
|
||||
etcdResolverBuilder etcdBuilder
|
||||
k8sResolverBuilder kubeBuilder
|
||||
)
|
||||
|
||||
// RegisterResolver registers the direct and discov schemes to the resolver.
|
||||
func RegisterResolver() {
|
||||
func register() {
|
||||
resolver.Register(&directResolverBuilder)
|
||||
resolver.Register(&discovResolverBuilder)
|
||||
resolver.Register(&etcdResolverBuilder)
|
||||
resolver.Register(&k8sResolverBuilder)
|
||||
}
|
||||
|
||||
type nopResolver struct {
|
||||
|
||||
@@ -36,21 +36,23 @@ func NewServer(c RpcServerConf, register internal.RegisterFn) (*RpcServer, error
|
||||
var server internal.Server
|
||||
metrics := stat.NewMetrics(c.ListenOn)
|
||||
serverOptions := []internal.ServerOption{
|
||||
internal.WithMetrics(metrics),
|
||||
internal.WithRpcHealth(c.Health),
|
||||
}
|
||||
|
||||
if c.HasEtcd() {
|
||||
server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, c.Middlewares, serverOptions...)
|
||||
server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, serverOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
server = internal.NewRpcServer(c.ListenOn, c.Middlewares, serverOptions...)
|
||||
server = internal.NewRpcServer(c.ListenOn, serverOptions...)
|
||||
}
|
||||
|
||||
server.SetName(c.Name)
|
||||
if err = setupInterceptors(server, c, metrics); err != nil {
|
||||
metrics.SetName(c.Name)
|
||||
setupStreamInterceptors(server, c)
|
||||
setupUnaryInterceptors(server, c, metrics)
|
||||
if err = setupAuthInterceptors(server, c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -108,6 +110,9 @@ func SetServerSlowThreshold(threshold time.Duration) {
|
||||
}
|
||||
|
||||
func setupAuthInterceptors(svr internal.Server, c RpcServerConf) error {
|
||||
if !c.Auth {
|
||||
return nil
|
||||
}
|
||||
rds, err := redis.NewRedis(c.Redis.RedisConf)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -124,22 +129,40 @@ func setupAuthInterceptors(svr internal.Server, c RpcServerConf) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func setupInterceptors(svr internal.Server, c RpcServerConf, metrics *stat.Metrics) error {
|
||||
func setupStreamInterceptors(svr internal.Server, c RpcServerConf) {
|
||||
if c.Middlewares.Trace {
|
||||
svr.AddStreamInterceptors(serverinterceptors.StreamTracingInterceptor)
|
||||
}
|
||||
if c.Middlewares.Recover {
|
||||
svr.AddStreamInterceptors(serverinterceptors.StreamRecoverInterceptor)
|
||||
}
|
||||
if c.Middlewares.Breaker {
|
||||
svr.AddStreamInterceptors(serverinterceptors.StreamBreakerInterceptor)
|
||||
}
|
||||
}
|
||||
|
||||
func setupUnaryInterceptors(svr internal.Server, c RpcServerConf, metrics *stat.Metrics) {
|
||||
if c.Middlewares.Trace {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryTracingInterceptor)
|
||||
}
|
||||
if c.Middlewares.Recover {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryRecoverInterceptor)
|
||||
}
|
||||
if c.Middlewares.Stat {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryStatInterceptor(metrics, c.Middlewares.StatConf))
|
||||
}
|
||||
if c.Middlewares.Prometheus {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryPrometheusInterceptor)
|
||||
}
|
||||
if c.Middlewares.Breaker {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryBreakerInterceptor)
|
||||
}
|
||||
if c.CpuThreshold > 0 {
|
||||
shedder := load.NewAdaptiveShedder(load.WithCpuThreshold(c.CpuThreshold))
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnarySheddingInterceptor(shedder, metrics))
|
||||
}
|
||||
|
||||
if c.Timeout > 0 {
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryTimeoutInterceptor(
|
||||
time.Duration(c.Timeout)*time.Millisecond, c.MethodTimeouts...))
|
||||
}
|
||||
|
||||
if c.Auth {
|
||||
if err := setupAuthInterceptors(svr, c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -16,47 +17,6 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TestServer_setupInterceptors(t *testing.T) {
|
||||
rds, err := miniredis.Run()
|
||||
assert.NoError(t, err)
|
||||
defer rds.Close()
|
||||
|
||||
server := new(mockedServer)
|
||||
conf := RpcServerConf{
|
||||
Auth: true,
|
||||
Redis: redis.RedisKeyConf{
|
||||
RedisConf: redis.RedisConf{
|
||||
Host: rds.Addr(),
|
||||
Type: redis.NodeType,
|
||||
},
|
||||
Key: "foo",
|
||||
},
|
||||
CpuThreshold: 10,
|
||||
Timeout: 100,
|
||||
Middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
MethodTimeouts: []MethodTimeoutConf{
|
||||
{
|
||||
FullMethod: "/foo",
|
||||
Timeout: 5 * time.Second,
|
||||
},
|
||||
},
|
||||
}
|
||||
err = setupInterceptors(server, conf, new(stat.Metrics))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(server.unaryInterceptors))
|
||||
assert.Equal(t, 1, len(server.streamInterceptors))
|
||||
|
||||
rds.SetError("mock error")
|
||||
err = setupInterceptors(server, conf, new(stat.Metrics))
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
DontLogContentForMethod("foo")
|
||||
SetServerSlowThreshold(time.Second)
|
||||
@@ -198,3 +158,153 @@ func (m *mockedServer) SetName(_ string) {
|
||||
func (m *mockedServer) Start(_ internal.RegisterFn) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Test_setupUnaryInterceptors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *mockedServer
|
||||
conf RpcServerConf
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &mockedServer{},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &mockedServer{
|
||||
unaryInterceptors: []grpc.UnaryServerInterceptor{
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &mockedServer{},
|
||||
conf: RpcServerConf{
|
||||
Middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 5,
|
||||
},
|
||||
{
|
||||
name: "internal middleware",
|
||||
r: &mockedServer{},
|
||||
conf: RpcServerConf{
|
||||
CpuThreshold: 900,
|
||||
Timeout: 100,
|
||||
Middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 7,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
metrics := stat.NewMetrics("abc")
|
||||
setupUnaryInterceptors(test.r, test.conf, metrics)
|
||||
assert.Equal(t, test.len, len(test.r.unaryInterceptors))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_setupStreamInterceptors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *mockedServer
|
||||
conf RpcServerConf
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &mockedServer{},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &mockedServer{
|
||||
streamInterceptors: []grpc.StreamServerInterceptor{
|
||||
func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
return handler(srv, ss)
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &mockedServer{},
|
||||
conf: RpcServerConf{
|
||||
Middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 3,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
setupStreamInterceptors(test.r, test.conf)
|
||||
assert.Equal(t, test.len, len(test.r.streamInterceptors))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_setupAuthInterceptors(t *testing.T) {
|
||||
t.Run("no need set auth", func(t *testing.T) {
|
||||
s := &mockedServer{}
|
||||
err := setupAuthInterceptors(s, RpcServerConf{
|
||||
Auth: false,
|
||||
Redis: redis.RedisKeyConf{},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("redis error", func(t *testing.T) {
|
||||
s := &mockedServer{}
|
||||
err := setupAuthInterceptors(s, RpcServerConf{
|
||||
Auth: true,
|
||||
Redis: redis.RedisKeyConf{},
|
||||
})
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("works", func(t *testing.T) {
|
||||
rds := miniredis.RunT(t)
|
||||
s := &mockedServer{}
|
||||
err := setupAuthInterceptors(s, RpcServerConf{
|
||||
Auth: true,
|
||||
Redis: redis.RedisKeyConf{
|
||||
RedisConf: redis.RedisConf{
|
||||
Host: rds.Addr(),
|
||||
Type: redis.NodeType,
|
||||
},
|
||||
Key: "foo",
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(s.unaryInterceptors))
|
||||
assert.Equal(t, 1, len(s.streamInterceptors))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user