mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-12 01:10:00 +08:00
Compare commits
117 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 | ||
|
|
eeda6efae7 | ||
|
|
caf0e64beb | ||
|
|
0e61303cb0 | ||
|
|
f651d7cf6c | ||
|
|
05da2c560b | ||
|
|
8ae0f287d6 | ||
|
|
8f7aff558f | ||
|
|
6e08d478fe | ||
|
|
944ac383d2 | ||
|
|
0eec33f14b | ||
|
|
9de04ee035 | ||
|
|
cf5b080fbe | ||
|
|
4a14164be1 | ||
|
|
5dd6f2a43a | ||
|
|
a00c956776 | ||
|
|
c02fb3acab | ||
|
|
9f8455ddb3 | ||
|
|
775b105ab2 | ||
|
|
ec86f22cd6 | ||
|
|
e776b5d8ab | ||
|
|
2026d4410b | ||
|
|
f8437e6364 | ||
|
|
bd2033eb35 | ||
|
|
fed835bc25 | ||
|
|
c9cbd74bf3 | ||
|
|
27ea106293 | ||
|
|
657923b9d5 | ||
|
|
8dbec6a800 | ||
|
|
490559434a | ||
|
|
4a62d084a9 | ||
|
|
2f9b6cf8ec | ||
|
|
01bbc78bac | ||
|
|
a012a9138f | ||
|
|
4ec9cac82b | ||
|
|
8d9746e794 | ||
|
|
8f83705199 | ||
|
|
f1ed7bd75d | ||
|
|
7a20608756 | ||
|
|
5cfff95e95 | ||
|
|
1e1cc1a0d9 | ||
|
|
0a1440a839 | ||
|
|
23980d29c3 | ||
|
|
424119d796 | ||
|
|
97c7835d9e | ||
|
|
7954ad3759 | ||
|
|
e8c9b0ddf8 | ||
|
|
70112e59cb | ||
|
|
7ba5ced2d9 | ||
|
|
962b36d745 | ||
|
|
57060cc6d7 | ||
|
|
e0c16059d9 | ||
|
|
a0d954dfab | ||
|
|
a5ece25c07 |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,3 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: kevwan
|
||||
github: [zeromicro]
|
||||
|
||||
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.19'
|
||||
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.19 to guarantee Go 1.19 compatibility
|
||||
go-version: '1.19'
|
||||
# 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
|
||||
@@ -105,7 +105,7 @@ func newRedisBitSet(store *redis.Redis, key string, bits uint) *redisBitSet {
|
||||
}
|
||||
|
||||
func (r *redisBitSet) buildOffsetArgs(offsets []uint) ([]string, error) {
|
||||
var args []string
|
||||
args := make([]string, 0, len(offsets))
|
||||
|
||||
for _, offset := range offsets {
|
||||
if offset >= r.bits {
|
||||
|
||||
@@ -269,7 +269,7 @@ func (ew *errorWindow) add(reason string) {
|
||||
}
|
||||
|
||||
func (ew *errorWindow) String() string {
|
||||
var reasons []string
|
||||
reasons := make([]string, 0, ew.count)
|
||||
|
||||
ew.lock.Lock()
|
||||
// reverse order
|
||||
|
||||
@@ -135,5 +135,5 @@ func verify(t *testing.T, fn func() bool) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
assert.True(t, count >= 80, fmt.Sprintf("should be greater than 80, actual %d", count))
|
||||
assert.True(t, count >= 75, fmt.Sprintf("should be greater than 75, actual %d", count))
|
||||
}
|
||||
|
||||
@@ -11,15 +11,12 @@ import (
|
||||
|
||||
const (
|
||||
// 250ms for bucket duration
|
||||
window = time.Second * 10
|
||||
buckets = 40
|
||||
maxFailBucketsToDecreaseK = 30
|
||||
minBucketsToSpeedUp = 3
|
||||
forcePassDuration = time.Second
|
||||
k = 1.5
|
||||
minK = 1.1
|
||||
recoveryK = 4 - k
|
||||
protection = 5
|
||||
window = time.Second * 10
|
||||
buckets = 40
|
||||
forcePassDuration = time.Second
|
||||
k = 1.5
|
||||
minK = 1.1
|
||||
protection = 5
|
||||
)
|
||||
|
||||
// googleBreaker is a netflixBreaker pattern from google.
|
||||
@@ -56,13 +53,8 @@ func newGoogleBreaker() *googleBreaker {
|
||||
func (b *googleBreaker) accept() error {
|
||||
var w float64
|
||||
history := b.history()
|
||||
if history.failingBuckets >= minBucketsToSpeedUp {
|
||||
w = b.k - float64(history.failingBuckets-1)*(b.k-minK)/maxFailBucketsToDecreaseK
|
||||
w = mathx.AtLeast(w, minK)
|
||||
} else {
|
||||
w = b.k
|
||||
}
|
||||
weightedAccepts := w * float64(history.accepts)
|
||||
w = b.k - (b.k-minK)*float64(history.failingBuckets)/buckets
|
||||
weightedAccepts := mathx.AtLeast(w, minK) * float64(history.accepts)
|
||||
// https://landing.google.com/sre/sre-book/chapters/handling-overload/#eq2101
|
||||
// for better performance, no need to care about the negative ratio
|
||||
dropRatio := (float64(history.total-protection) - weightedAccepts) / float64(history.total+1)
|
||||
@@ -76,11 +68,7 @@ func (b *googleBreaker) accept() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If we have more than 2 working buckets, we are in recovery mode,
|
||||
// the latest bucket is the current one, so we ignore it.
|
||||
if history.workingBuckets >= minBucketsToSpeedUp {
|
||||
dropRatio /= recoveryK
|
||||
}
|
||||
dropRatio *= float64(buckets-history.workingBuckets) / buckets
|
||||
|
||||
if b.proba.TrueOnProba(dropRatio) {
|
||||
return ErrServiceUnavailable
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestGoogleBreakerMoreFallingBuckets(t *testing.T) {
|
||||
b := getGoogleBreaker()
|
||||
|
||||
func() {
|
||||
stopChan := time.After(testInterval * minBucketsToSpeedUp * 2)
|
||||
stopChan := time.After(testInterval * 6)
|
||||
for {
|
||||
time.Sleep(time.Millisecond)
|
||||
select {
|
||||
|
||||
@@ -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 (
|
||||
@@ -30,7 +31,7 @@ var (
|
||||
// A Registry is a registry that manages the etcd client connections.
|
||||
type Registry struct {
|
||||
clusters map[string]*cluster
|
||||
lock sync.Mutex
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// GetRegistry returns a global Registry.
|
||||
@@ -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,17 +56,24 @@ 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) {
|
||||
clusterKey := getClusterKey(endpoints)
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
r.lock.RLock()
|
||||
c, exists = r.clusters[clusterKey]
|
||||
r.lock.RUnlock()
|
||||
|
||||
if !exists {
|
||||
c = newCluster(endpoints)
|
||||
r.clusters[clusterKey] = c
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
// double-check locking
|
||||
c, exists = r.clusters[clusterKey]
|
||||
if !exists {
|
||||
c = newCluster(endpoints)
|
||||
r.clusters[clusterKey] = c
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
@@ -78,7 +86,8 @@ type cluster struct {
|
||||
listeners map[string][]UpdateListener
|
||||
watchGroup *threading.RoutineGroup
|
||||
done chan lang.PlaceholderType
|
||||
lock sync.Mutex
|
||||
lock sync.RWMutex
|
||||
exactMatch bool
|
||||
}
|
||||
|
||||
func newCluster(endpoints []string) *cluster {
|
||||
@@ -108,8 +117,8 @@ func (c *cluster) getClient() (EtcdClient, error) {
|
||||
}
|
||||
|
||||
func (c *cluster) getCurrent(key string) []KV {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
var kvs []KV
|
||||
for k, v := range c.values[key] {
|
||||
@@ -125,6 +134,7 @@ func (c *cluster) getCurrent(key string) []KV {
|
||||
func (c *cluster) handleChanges(key string, kvs []KV) {
|
||||
var add []KV
|
||||
var remove []KV
|
||||
|
||||
c.lock.Lock()
|
||||
listeners := append([]UpdateListener(nil), c.listeners[key]...)
|
||||
vals, ok := c.values[key]
|
||||
@@ -173,9 +183,9 @@ func (c *cluster) handleChanges(key string, kvs []KV) {
|
||||
}
|
||||
|
||||
func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
|
||||
c.lock.Lock()
|
||||
c.lock.RLock()
|
||||
listeners := append([]UpdateListener(nil), c.listeners[key]...)
|
||||
c.lock.Unlock()
|
||||
c.lock.RUnlock()
|
||||
|
||||
for _, ev := range events {
|
||||
switch ev.Type {
|
||||
@@ -216,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
|
||||
@@ -239,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()
|
||||
@@ -307,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")
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func firstLine(file *os.File) (string, error) {
|
||||
for {
|
||||
buf := make([]byte, bufSize)
|
||||
n, err := file.ReadAt(buf, offset)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
return "", err
|
||||
}
|
||||
@@ -45,6 +46,10 @@ func firstLine(file *os.File) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
return string(append(first, buf[:n]...)), nil
|
||||
}
|
||||
|
||||
first = append(first, buf[:n]...)
|
||||
offset += bufSize
|
||||
}
|
||||
@@ -57,30 +62,42 @@ func lastLine(filename string, file *os.File) (string, error) {
|
||||
}
|
||||
|
||||
var last []byte
|
||||
bufLen := int64(bufSize)
|
||||
offset := info.Size()
|
||||
for {
|
||||
offset -= bufSize
|
||||
if offset < 0 {
|
||||
|
||||
for offset > 0 {
|
||||
if offset < bufLen {
|
||||
bufLen = offset
|
||||
offset = 0
|
||||
} else {
|
||||
offset -= bufLen
|
||||
}
|
||||
buf := make([]byte, bufSize)
|
||||
|
||||
buf := make([]byte, bufLen)
|
||||
n, err := file.ReadAt(buf, offset)
|
||||
if err != nil && err != io.EOF {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if buf[n-1] == '\n' {
|
||||
buf = buf[:n-1]
|
||||
n--
|
||||
} else {
|
||||
buf = buf[:n]
|
||||
}
|
||||
for n--; n >= 0; n-- {
|
||||
if buf[n] == '\n' {
|
||||
return string(append(buf[n+1:], last...)), nil
|
||||
|
||||
for i := n - 1; i >= 0; i-- {
|
||||
if buf[i] == '\n' {
|
||||
return string(append(buf[i+1:], last...)), nil
|
||||
}
|
||||
}
|
||||
|
||||
last = append(buf, last...)
|
||||
}
|
||||
|
||||
return string(last), nil
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ last line`
|
||||
second line
|
||||
last line
|
||||
`
|
||||
emptyContent = ``
|
||||
)
|
||||
|
||||
func TestFirstLine(t *testing.T) {
|
||||
@@ -79,6 +80,26 @@ func TestFirstLineError(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestFirstLineEmptyFile(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(emptyContent)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := FirstLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "", val)
|
||||
}
|
||||
|
||||
func TestFirstLineWithoutNewline(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(longLine)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := FirstLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, longLine, val)
|
||||
}
|
||||
|
||||
func TestLastLine(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(text)
|
||||
assert.Nil(t, err)
|
||||
@@ -99,6 +120,16 @@ func TestLastLineWithLastNewline(t *testing.T) {
|
||||
assert.Equal(t, longLine, val)
|
||||
}
|
||||
|
||||
func TestLastLineWithoutLastNewline(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(longLine)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := LastLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, longLine, val)
|
||||
}
|
||||
|
||||
func TestLastLineShort(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(shortText)
|
||||
assert.Nil(t, err)
|
||||
@@ -123,3 +154,67 @@ func TestLastLineError(t *testing.T) {
|
||||
_, err := LastLine("/tmp/does-not-exist")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestLastLineEmptyFile(t *testing.T) {
|
||||
filename, err := fs.TempFilenameWithText(emptyContent)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := LastLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "", val)
|
||||
}
|
||||
|
||||
func TestFirstLineExactlyBufSize(t *testing.T) {
|
||||
content := make([]byte, bufSize)
|
||||
for i := range content {
|
||||
content[i] = 'a'
|
||||
}
|
||||
content[bufSize-1] = '\n' // Ensure there is a newline at the edge
|
||||
|
||||
filename, err := fs.TempFilenameWithText(string(content))
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := FirstLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, string(content[:bufSize-1]), val)
|
||||
}
|
||||
|
||||
func TestLastLineExactlyBufSize(t *testing.T) {
|
||||
content := make([]byte, bufSize)
|
||||
for i := range content {
|
||||
content[i] = 'a'
|
||||
}
|
||||
content[bufSize-1] = '\n' // Ensure there is a newline at the edge
|
||||
|
||||
filename, err := fs.TempFilenameWithText(string(content))
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := LastLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, string(content[:bufSize-1]), val)
|
||||
}
|
||||
|
||||
func TestFirstLineLargeFile(t *testing.T) {
|
||||
content := text + text + text + "\n" + "extra"
|
||||
filename, err := fs.TempFilenameWithText(content)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := FirstLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "first line", val)
|
||||
}
|
||||
|
||||
func TestLastLineLargeFile(t *testing.T) {
|
||||
content := text + text + text + "\n" + "extra"
|
||||
filename, err := fs.TempFilenameWithText(content)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(filename)
|
||||
|
||||
val, err := LastLine(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "extra", val)
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ func Range(source <-chan any) Stream {
|
||||
}
|
||||
}
|
||||
|
||||
// AllMach returns whether all elements of this stream match the provided predicate.
|
||||
// AllMatch returns whether all elements of this stream match the provided predicate.
|
||||
// May not evaluate the predicate on all elements if not necessary for determining the result.
|
||||
// If the stream is empty then true is returned and the predicate is not evaluated.
|
||||
func (s Stream) AllMach(predicate func(item any) bool) bool {
|
||||
func (s Stream) AllMatch(predicate func(item any) bool) bool {
|
||||
for item := range s.source {
|
||||
if !predicate(item) {
|
||||
// make sure the former goroutine not block, and current func returns fast.
|
||||
@@ -99,10 +99,10 @@ func (s Stream) AllMach(predicate func(item any) bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// AnyMach returns whether any elements of this stream match the provided predicate.
|
||||
// AnyMatch returns whether any elements of this stream match the provided predicate.
|
||||
// May not evaluate the predicate on all elements if not necessary for determining the result.
|
||||
// If the stream is empty then false is returned and the predicate is not evaluated.
|
||||
func (s Stream) AnyMach(predicate func(item any) bool) bool {
|
||||
func (s Stream) AnyMatch(predicate func(item any) bool) bool {
|
||||
for item := range s.source {
|
||||
if predicate(item) {
|
||||
// make sure the former goroutine not block, and current func returns fast.
|
||||
|
||||
@@ -398,16 +398,16 @@ func TestWalk(t *testing.T) {
|
||||
|
||||
func TestStream_AnyMach(t *testing.T) {
|
||||
runCheckedTest(t, func(t *testing.T) {
|
||||
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item any) bool {
|
||||
assetEqual(t, false, Just(1, 2, 3).AnyMatch(func(item any) bool {
|
||||
return item.(int) == 4
|
||||
}))
|
||||
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item any) bool {
|
||||
assetEqual(t, false, Just(1, 2, 3).AnyMatch(func(item any) bool {
|
||||
return item.(int) == 0
|
||||
}))
|
||||
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item any) bool {
|
||||
assetEqual(t, true, Just(1, 2, 3).AnyMatch(func(item any) bool {
|
||||
return item.(int) == 2
|
||||
}))
|
||||
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item any) bool {
|
||||
assetEqual(t, true, Just(1, 2, 3).AnyMatch(func(item any) bool {
|
||||
return item.(int) == 2
|
||||
}))
|
||||
})
|
||||
@@ -416,17 +416,17 @@ func TestStream_AnyMach(t *testing.T) {
|
||||
func TestStream_AllMach(t *testing.T) {
|
||||
runCheckedTest(t, func(t *testing.T) {
|
||||
assetEqual(
|
||||
t, true, Just(1, 2, 3).AllMach(func(item any) bool {
|
||||
t, true, Just(1, 2, 3).AllMatch(func(item any) bool {
|
||||
return true
|
||||
}),
|
||||
)
|
||||
assetEqual(
|
||||
t, false, Just(1, 2, 3).AllMach(func(item any) bool {
|
||||
t, false, Just(1, 2, 3).AllMatch(func(item any) bool {
|
||||
return false
|
||||
}),
|
||||
)
|
||||
assetEqual(
|
||||
t, false, Just(1, 2, 3).AllMach(func(item any) bool {
|
||||
t, false, Just(1, 2, 3).AllMatch(func(item any) bool {
|
||||
return item.(int) == 1
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
|
||||
// A Logger represents a logger.
|
||||
type Logger interface {
|
||||
// Debug logs a message at info level.
|
||||
// Debug logs a message at debug level.
|
||||
Debug(...any)
|
||||
// Debugf logs a message at info level.
|
||||
// Debugf logs a message at debug level.
|
||||
Debugf(string, ...any)
|
||||
// Debugv logs a message at info level.
|
||||
// Debugv logs a message at debug level.
|
||||
Debugv(any)
|
||||
// Debugw logs a message at info level.
|
||||
// Debugw logs a message at debug level.
|
||||
Debugw(string, ...LogField)
|
||||
// Error logs a message at error level.
|
||||
Error(...any)
|
||||
|
||||
@@ -52,6 +52,26 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// AddWriter adds a new writer.
|
||||
// If there is already a writer, the new writer will be added to the writer chain.
|
||||
// For example, to write logs to both file and console, if there is already a file writer,
|
||||
// ```go
|
||||
// logx.AddWriter(logx.NewWriter(os.Stdout))
|
||||
// ```
|
||||
func AddWriter(w Writer) {
|
||||
ow := Reset()
|
||||
if ow == nil {
|
||||
SetWriter(w)
|
||||
} else {
|
||||
// no need to check if the existing writer is a comboWriter,
|
||||
// because it is not common to add more than one writer.
|
||||
// even more than one writer, the behavior is the same.
|
||||
SetWriter(comboWriter{
|
||||
writers: []Writer{ow, w},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Alert alerts v in alert level, and the message is written to error log.
|
||||
func Alert(v string) {
|
||||
getWriter().Alert(v)
|
||||
@@ -274,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 {
|
||||
|
||||
@@ -679,6 +679,10 @@ func TestSetup(t *testing.T) {
|
||||
|
||||
func TestDisable(t *testing.T) {
|
||||
Disable()
|
||||
defer func() {
|
||||
SetLevel(InfoLevel)
|
||||
atomic.StoreUint32(&encoding, jsonEncodingType)
|
||||
}()
|
||||
|
||||
var opt logOptions
|
||||
WithKeepDays(1)(&opt)
|
||||
@@ -701,6 +705,17 @@ func TestDisableStat(t *testing.T) {
|
||||
assert.Equal(t, 0, w.builder.Len())
|
||||
}
|
||||
|
||||
func TestAddWriter(t *testing.T) {
|
||||
const message = "hello there"
|
||||
w := new(mockWriter)
|
||||
AddWriter(w)
|
||||
w1 := new(mockWriter)
|
||||
AddWriter(w1)
|
||||
Error(message)
|
||||
assert.Contains(t, w.String(), message)
|
||||
assert.Contains(t, w1.String(), message)
|
||||
}
|
||||
|
||||
func TestSetWriter(t *testing.T) {
|
||||
atomic.StoreUint32(&logLevel, 0)
|
||||
Reset()
|
||||
@@ -835,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,
|
||||
|
||||
@@ -141,23 +141,43 @@ func (l *richLogger) WithCallerSkip(skip int) Logger {
|
||||
return l
|
||||
}
|
||||
|
||||
l.callerSkip = skip
|
||||
return l
|
||||
return &richLogger{
|
||||
ctx: l.ctx,
|
||||
callerSkip: skip,
|
||||
fields: l.fields,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *richLogger) WithContext(ctx context.Context) Logger {
|
||||
l.ctx = ctx
|
||||
return l
|
||||
return &richLogger{
|
||||
ctx: ctx,
|
||||
callerSkip: l.callerSkip,
|
||||
fields: l.fields,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *richLogger) WithDuration(duration time.Duration) Logger {
|
||||
l.fields = append(l.fields, Field(durationKey, timex.ReprOfDuration(duration)))
|
||||
return l
|
||||
fields := append(l.fields, Field(durationKey, timex.ReprOfDuration(duration)))
|
||||
|
||||
return &richLogger{
|
||||
ctx: l.ctx,
|
||||
callerSkip: l.callerSkip,
|
||||
fields: fields,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *richLogger) WithFields(fields ...LogField) Logger {
|
||||
l.fields = append(l.fields, fields...)
|
||||
return l
|
||||
if len(fields) == 0 {
|
||||
return l
|
||||
}
|
||||
|
||||
f := append(l.fields, fields...)
|
||||
|
||||
return &richLogger{
|
||||
ctx: l.ctx,
|
||||
callerSkip: l.callerSkip,
|
||||
fields: f,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *richLogger) buildFields(fields ...LogField) []LogField {
|
||||
|
||||
@@ -287,6 +287,54 @@ func TestLogWithCallerSkip(t *testing.T) {
|
||||
assert.True(t, w.Contains(fmt.Sprintf("%s:%d", file, line+1)))
|
||||
}
|
||||
|
||||
func TestLogWithCallerSkipCopy(t *testing.T) {
|
||||
log1 := WithCallerSkip(2)
|
||||
log2 := log1.WithCallerSkip(3)
|
||||
log3 := log2.WithCallerSkip(-1)
|
||||
assert.Equal(t, 2, log1.(*richLogger).callerSkip)
|
||||
assert.Equal(t, 3, log2.(*richLogger).callerSkip)
|
||||
assert.Equal(t, 3, log3.(*richLogger).callerSkip)
|
||||
}
|
||||
|
||||
func TestLogWithContextCopy(t *testing.T) {
|
||||
c1 := context.Background()
|
||||
c2 := context.WithValue(context.Background(), "foo", "bar")
|
||||
log1 := WithContext(c1)
|
||||
log2 := log1.WithContext(c2)
|
||||
assert.Equal(t, c1, log1.(*richLogger).ctx)
|
||||
assert.Equal(t, c2, log2.(*richLogger).ctx)
|
||||
}
|
||||
|
||||
func TestLogWithDurationCopy(t *testing.T) {
|
||||
log1 := WithContext(context.Background())
|
||||
log2 := log1.WithDuration(time.Second)
|
||||
assert.Empty(t, log1.(*richLogger).fields)
|
||||
assert.Equal(t, 1, len(log2.(*richLogger).fields))
|
||||
|
||||
var w mockWriter
|
||||
old := writer.Swap(&w)
|
||||
defer writer.Store(old)
|
||||
log2.Info("hello")
|
||||
assert.Contains(t, w.String(), `"duration":"1000.0ms"`)
|
||||
}
|
||||
|
||||
func TestLogWithFieldsCopy(t *testing.T) {
|
||||
log1 := WithContext(context.Background())
|
||||
log2 := log1.WithFields(Field("foo", "bar"))
|
||||
log3 := log1.WithFields()
|
||||
assert.Empty(t, log1.(*richLogger).fields)
|
||||
assert.Equal(t, 1, len(log2.(*richLogger).fields))
|
||||
assert.Equal(t, log1, log3)
|
||||
assert.Empty(t, log3.(*richLogger).fields)
|
||||
|
||||
var w mockWriter
|
||||
old := writer.Swap(&w)
|
||||
defer writer.Store(old)
|
||||
|
||||
log2.Info("hello")
|
||||
assert.Contains(t, w.String(), `"foo":"bar"`)
|
||||
}
|
||||
|
||||
func TestLoggerWithFields(t *testing.T) {
|
||||
w := new(mockWriter)
|
||||
old := writer.Swap(w)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
fatihcolor "github.com/fatih/color"
|
||||
"github.com/zeromicro/go-zero/core/color"
|
||||
"github.com/zeromicro/go-zero/core/errorx"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -33,6 +34,10 @@ type (
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
comboWriter struct {
|
||||
writers []Writer
|
||||
}
|
||||
|
||||
concreteWriter struct {
|
||||
infoLog io.WriteCloser
|
||||
errorLog io.WriteCloser
|
||||
@@ -88,6 +93,62 @@ func (w *atomicWriter) Swap(v Writer) Writer {
|
||||
return old
|
||||
}
|
||||
|
||||
func (c comboWriter) Alert(v any) {
|
||||
for _, w := range c.writers {
|
||||
w.Alert(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Close() error {
|
||||
var be errorx.BatchError
|
||||
for _, w := range c.writers {
|
||||
be.Add(w.Close())
|
||||
}
|
||||
return be.Err()
|
||||
}
|
||||
|
||||
func (c comboWriter) Debug(v any, fields ...LogField) {
|
||||
for _, w := range c.writers {
|
||||
w.Debug(v, fields...)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Error(v any, fields ...LogField) {
|
||||
for _, w := range c.writers {
|
||||
w.Error(v, fields...)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Info(v any, fields ...LogField) {
|
||||
for _, w := range c.writers {
|
||||
w.Info(v, fields...)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Severe(v any) {
|
||||
for _, w := range c.writers {
|
||||
w.Severe(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Slow(v any, fields ...LogField) {
|
||||
for _, w := range c.writers {
|
||||
w.Slow(v, fields...)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Stack(v any) {
|
||||
for _, w := range c.writers {
|
||||
w.Stack(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (c comboWriter) Stat(v any, fields ...LogField) {
|
||||
for _, w := range c.writers {
|
||||
w.Stat(v, fields...)
|
||||
}
|
||||
}
|
||||
|
||||
func newConsoleWriter() Writer {
|
||||
outLog := newLogWriter(log.New(fatihcolor.Output, "", flags))
|
||||
errLog := newLogWriter(log.New(fatihcolor.Error, "", flags))
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestNewWriter(t *testing.T) {
|
||||
@@ -254,6 +255,117 @@ func TestLogWithLimitContentLength(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestComboWriter(t *testing.T) {
|
||||
var mockWriters []Writer
|
||||
for i := 0; i < 3; i++ {
|
||||
mockWriters = append(mockWriters, new(tracedWriter))
|
||||
}
|
||||
|
||||
cw := comboWriter{
|
||||
writers: mockWriters,
|
||||
}
|
||||
|
||||
t.Run("Alert", func(t *testing.T) {
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Alert", "test alert").Once()
|
||||
}
|
||||
cw.Alert("test alert")
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Alert", "test alert")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Close", func(t *testing.T) {
|
||||
for i := range cw.writers {
|
||||
if i == 1 {
|
||||
cw.writers[i].(*tracedWriter).On("Close").Return(errors.New("error")).Once()
|
||||
} else {
|
||||
cw.writers[i].(*tracedWriter).On("Close").Return(nil).Once()
|
||||
}
|
||||
}
|
||||
err := cw.Close()
|
||||
assert.Error(t, err)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Close")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Debug", func(t *testing.T) {
|
||||
fields := []LogField{{Key: "key", Value: "value"}}
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Debug", "test debug", fields).Once()
|
||||
}
|
||||
cw.Debug("test debug", fields...)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Debug", "test debug", fields)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Error", func(t *testing.T) {
|
||||
fields := []LogField{{Key: "key", Value: "value"}}
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Error", "test error", fields).Once()
|
||||
}
|
||||
cw.Error("test error", fields...)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Error", "test error", fields)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Info", func(t *testing.T) {
|
||||
fields := []LogField{{Key: "key", Value: "value"}}
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Info", "test info", fields).Once()
|
||||
}
|
||||
cw.Info("test info", fields...)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Info", "test info", fields)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Severe", func(t *testing.T) {
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Severe", "test severe").Once()
|
||||
}
|
||||
cw.Severe("test severe")
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Severe", "test severe")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Slow", func(t *testing.T) {
|
||||
fields := []LogField{{Key: "key", Value: "value"}}
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Slow", "test slow", fields).Once()
|
||||
}
|
||||
cw.Slow("test slow", fields...)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Slow", "test slow", fields)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Stack", func(t *testing.T) {
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Stack", "test stack").Once()
|
||||
}
|
||||
cw.Stack("test stack")
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Stack", "test stack")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Stat", func(t *testing.T) {
|
||||
fields := []LogField{{Key: "key", Value: "value"}}
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).On("Stat", "test stat", fields).Once()
|
||||
}
|
||||
cw.Stat("test stat", fields...)
|
||||
for _, mw := range cw.writers {
|
||||
mw.(*tracedWriter).AssertCalled(t, "Stat", "test stat", fields)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type mockedEntry struct {
|
||||
Level string `json:"level"`
|
||||
Content string `json:"content"`
|
||||
@@ -285,3 +397,44 @@ type hardToWriteWriter struct{}
|
||||
func (h hardToWriteWriter) Write(_ []byte) (_ int, _ error) {
|
||||
return 0, errors.New("write error")
|
||||
}
|
||||
|
||||
type tracedWriter struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Alert(v any) {
|
||||
w.Called(v)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Close() error {
|
||||
args := w.Called()
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Debug(v any, fields ...LogField) {
|
||||
w.Called(v, fields)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Error(v any, fields ...LogField) {
|
||||
w.Called(v, fields)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Info(v any, fields ...LogField) {
|
||||
w.Called(v, fields)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Severe(v any) {
|
||||
w.Called(v)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Slow(v any, fields ...LogField) {
|
||||
w.Called(v, fields)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Stack(v any) {
|
||||
w.Called(v)
|
||||
}
|
||||
|
||||
func (w *tracedWriter) Stat(v any, fields ...LogField) {
|
||||
w.Called(v, fields)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -261,6 +261,7 @@ func TestUnmarshalInt(t *testing.T) {
|
||||
Int64FromStr int64 `key:"int64str,string"`
|
||||
DefaultInt int64 `key:"defaultint,default=11"`
|
||||
Optional int `key:"optional,optional"`
|
||||
IntOptDef int `key:"intopt,optional,default=6"`
|
||||
}
|
||||
m := map[string]any{
|
||||
"int": 1,
|
||||
@@ -289,6 +290,7 @@ func TestUnmarshalInt(t *testing.T) {
|
||||
ast.Equal(int64(9), in.Int64)
|
||||
ast.Equal(int64(10), in.Int64FromStr)
|
||||
ast.Equal(int64(11), in.DefaultInt)
|
||||
ast.Equal(6, in.IntOptDef)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5637,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"`
|
||||
|
||||
@@ -363,9 +363,7 @@ func newGuardedWriter[T any](ctx context.Context, channel chan<- T, done <-chan
|
||||
func (gw guardedWriter[T]) Write(v T) {
|
||||
select {
|
||||
case <-gw.ctx.Done():
|
||||
return
|
||||
case <-gw.done:
|
||||
return
|
||||
default:
|
||||
gw.channel <- v
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_ = mtest.Setup()
|
||||
}
|
||||
|
||||
func TestClientManger_getClient(t *testing.T) {
|
||||
mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
|
||||
mt.Run("test", func(mt *mtest.T) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package mon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
@@ -15,7 +16,8 @@ import (
|
||||
const (
|
||||
defaultSlowThreshold = time.Millisecond * 500
|
||||
// spanName is the span name of the mongo calls.
|
||||
spanName = "mongo"
|
||||
spanName = "mongo"
|
||||
duplicateKeyCode = 11000
|
||||
|
||||
// mongodb method names
|
||||
aggregate = "Aggregate"
|
||||
@@ -527,10 +529,20 @@ func (p keepablePromise) keep(err error) error {
|
||||
}
|
||||
|
||||
func acceptable(err error) bool {
|
||||
return err == nil || errorx.In(err, mongo.ErrNoDocuments, mongo.ErrNilValue,
|
||||
mongo.ErrNilDocument, mongo.ErrNilCursor, mongo.ErrEmptySlice,
|
||||
// session errors
|
||||
session.ErrSessionEnded, session.ErrNoTransactStarted, session.ErrTransactInProgress,
|
||||
session.ErrAbortAfterCommit, session.ErrAbortTwice, session.ErrCommitAfterAbort,
|
||||
session.ErrUnackWCUnsupported, session.ErrSnapshotTransaction)
|
||||
return err == nil || isDupKeyError(err) ||
|
||||
errorx.In(err, mongo.ErrNoDocuments, mongo.ErrNilValue,
|
||||
mongo.ErrNilDocument, mongo.ErrNilCursor, mongo.ErrEmptySlice,
|
||||
// session errors
|
||||
session.ErrSessionEnded, session.ErrNoTransactStarted, session.ErrTransactInProgress,
|
||||
session.ErrAbortAfterCommit, session.ErrAbortTwice, session.ErrCommitAfterAbort,
|
||||
session.ErrUnackWCUnsupported, session.ErrSnapshotTransaction)
|
||||
}
|
||||
|
||||
func isDupKeyError(err error) bool {
|
||||
var e mongo.WriteException
|
||||
if !errors.As(err, &e) {
|
||||
return false
|
||||
}
|
||||
|
||||
return e.HasErrorCode(duplicateKeyCode)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
|
||||
mopt "go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
|
||||
)
|
||||
|
||||
var errDummy = errors.New("dummy")
|
||||
@@ -572,6 +573,56 @@ func TestDecoratedCollection_LogDuration(t *testing.T) {
|
||||
assert.Contains(t, buf.String(), "slowcall")
|
||||
}
|
||||
|
||||
func TestAcceptable(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{"NilError", nil, true},
|
||||
{"NoDocuments", mongo.ErrNoDocuments, true},
|
||||
{"NilValue", mongo.ErrNilValue, true},
|
||||
{"NilDocument", mongo.ErrNilDocument, true},
|
||||
{"NilCursor", mongo.ErrNilCursor, true},
|
||||
{"EmptySlice", mongo.ErrEmptySlice, true},
|
||||
{"SessionEnded", session.ErrSessionEnded, true},
|
||||
{"NoTransactStarted", session.ErrNoTransactStarted, true},
|
||||
{"TransactInProgress", session.ErrTransactInProgress, true},
|
||||
{"AbortAfterCommit", session.ErrAbortAfterCommit, true},
|
||||
{"AbortTwice", session.ErrAbortTwice, true},
|
||||
{"CommitAfterAbort", session.ErrCommitAfterAbort, true},
|
||||
{"UnackWCUnsupported", session.ErrUnackWCUnsupported, true},
|
||||
{"SnapshotTransaction", session.ErrSnapshotTransaction, true},
|
||||
{"DuplicateKeyError", mongo.WriteException{WriteErrors: []mongo.WriteError{{Code: duplicateKeyCode}}}, true},
|
||||
{"OtherError", errors.New("other error"), false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, acceptable(tt.err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDupKeyError(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{"NilError", nil, false},
|
||||
{"NonDupKeyError", errors.New("some other error"), false},
|
||||
{"DupKeyError", mongo.WriteException{WriteErrors: []mongo.WriteError{{Code: duplicateKeyCode}}}, true},
|
||||
{"OtherMongoError", mongo.WriteException{WriteErrors: []mongo.WriteError{{Code: 12345}}}, false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, isDupKeyError(tt.err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type mockPromise struct {
|
||||
accepted bool
|
||||
reason string
|
||||
|
||||
@@ -90,6 +90,18 @@ type (
|
||||
StringCmd = red.StringCmd
|
||||
// Script is an alias of redis.Script.
|
||||
Script = red.Script
|
||||
|
||||
// Hook is an alias of redis.Hook.
|
||||
Hook = red.Hook
|
||||
// DialHook is an alias of redis.DialHook.
|
||||
DialHook = red.DialHook
|
||||
// ProcessHook is an alias of redis.ProcessHook.
|
||||
ProcessHook = red.ProcessHook
|
||||
// ProcessPipelineHook is an alias of redis.ProcessPipelineHook.
|
||||
ProcessPipelineHook = red.ProcessPipelineHook
|
||||
|
||||
// Cmder is an alias of redis.Cmder.
|
||||
Cmder = red.Cmder
|
||||
)
|
||||
|
||||
// MustNewRedis returns a Redis with given options.
|
||||
@@ -1185,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)
|
||||
@@ -1235,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...)
|
||||
@@ -1633,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)
|
||||
@@ -2363,9 +2419,9 @@ func WithTLS() Option {
|
||||
}
|
||||
}
|
||||
|
||||
// withHook customizes the given Redis with given durationHook, only for private use now,
|
||||
// WithHook customizes the given Redis with given durationHook, only for private use now,
|
||||
// maybe expose later.
|
||||
func withHook(hook red.Hook) Option {
|
||||
func WithHook(hook Hook) Option {
|
||||
return func(r *Redis) {
|
||||
r.hooks = append(r.hooks, hook)
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestRedis_NonBlock(t *testing.T) {
|
||||
Host: s.Addr(),
|
||||
NonBlock: true,
|
||||
Type: NodeType,
|
||||
}, withHook(myHook{includePing: true}))
|
||||
}, WithHook(myHook{includePing: true}))
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -170,7 +170,7 @@ func TestRedis_NonBlock(t *testing.T) {
|
||||
Host: s.Addr(),
|
||||
NonBlock: false,
|
||||
Type: NodeType,
|
||||
}, withHook(myHook{includePing: true}))
|
||||
}, WithHook(myHook{includePing: true}))
|
||||
assert.ErrorContains(t, err, "redis connect error")
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -190,6 +190,17 @@ func (cc CachedConn) QueryRowNoCacheCtx(ctx context.Context, v any, q string,
|
||||
return cc.db.QueryRowCtx(ctx, v, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowPartialNoCache unmarshals into v with given statement.
|
||||
func (cc CachedConn) QueryRowPartialNoCache(v any, q string, args ...any) error {
|
||||
return cc.QueryRowPartialNoCacheCtx(context.Background(), v, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowPartialNoCacheCtx unmarshals into v with given statement.
|
||||
func (cc CachedConn) QueryRowPartialNoCacheCtx(ctx context.Context, v any, q string,
|
||||
args ...any) error {
|
||||
return cc.db.QueryRowPartialCtx(ctx, v, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowsNoCache unmarshals into v with given statement.
|
||||
// It doesn't use cache, because it might cause consistency problem.
|
||||
func (cc CachedConn) QueryRowsNoCache(v any, q string, args ...any) error {
|
||||
@@ -203,6 +214,19 @@ func (cc CachedConn) QueryRowsNoCacheCtx(ctx context.Context, v any, q string,
|
||||
return cc.db.QueryRowsCtx(ctx, v, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowsPartialNoCache unmarshals into v with given statement.
|
||||
// It doesn't use cache, because it might cause consistency problem.
|
||||
func (cc CachedConn) QueryRowsPartialNoCache(v any, q string, args ...any) error {
|
||||
return cc.QueryRowsPartialNoCacheCtx(context.Background(), v, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowsPartialNoCacheCtx unmarshals into v with given statement.
|
||||
// It doesn't use cache, because it might cause consistency problem.
|
||||
func (cc CachedConn) QueryRowsPartialNoCacheCtx(ctx context.Context, v any, q string,
|
||||
args ...any) error {
|
||||
return cc.db.QueryRowsPartialCtx(ctx, v, q, args...)
|
||||
}
|
||||
|
||||
// SetCache sets v into cache with given key.
|
||||
func (cc CachedConn) SetCache(key string, val any) error {
|
||||
return cc.SetCacheCtx(context.Background(), key, val)
|
||||
|
||||
@@ -579,6 +579,48 @@ func TestQueryRowNoCache(t *testing.T) {
|
||||
assert.True(t, ran)
|
||||
}
|
||||
|
||||
func TestQueryRowPartialNoCache(t *testing.T) {
|
||||
r := redistest.CreateRedis(t)
|
||||
|
||||
const (
|
||||
key = "user"
|
||||
value = "any"
|
||||
)
|
||||
var user string
|
||||
var ran bool
|
||||
conn := dummySqlConn{queryRow: func(v any, q string, args ...any) error {
|
||||
user = value
|
||||
ran = true
|
||||
return nil
|
||||
}}
|
||||
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
||||
err := c.QueryRowPartialNoCache(&user, key)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, value, user)
|
||||
assert.True(t, ran)
|
||||
}
|
||||
|
||||
func TestQueryRowsPartialNoCache(t *testing.T) {
|
||||
r := redistest.CreateRedis(t)
|
||||
|
||||
var (
|
||||
key = "user"
|
||||
values = []string{"any", "any"}
|
||||
)
|
||||
var users []string
|
||||
var ran bool
|
||||
conn := dummySqlConn{queryRows: func(v any, q string, args ...any) error {
|
||||
users = values
|
||||
ran = true
|
||||
return nil
|
||||
}}
|
||||
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
||||
err := c.QueryRowsPartialNoCache(&users, key)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, values, users)
|
||||
assert.True(t, ran)
|
||||
}
|
||||
|
||||
func TestNewConnWithCache(t *testing.T) {
|
||||
r := redistest.CreateRedis(t)
|
||||
|
||||
@@ -716,7 +758,8 @@ func resetStats() {
|
||||
}
|
||||
|
||||
type dummySqlConn struct {
|
||||
queryRow func(any, string, ...any) error
|
||||
queryRow func(any, string, ...any) error
|
||||
queryRows func(any, string, ...any) error
|
||||
}
|
||||
|
||||
func (d dummySqlConn) ExecCtx(_ context.Context, _ string, _ ...any) (sql.Result, error) {
|
||||
@@ -727,7 +770,11 @@ func (d dummySqlConn) PrepareCtx(_ context.Context, _ string) (sqlx.StmtSession,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d dummySqlConn) QueryRowPartialCtx(_ context.Context, _ any, _ string, _ ...any) error {
|
||||
func (d dummySqlConn) QueryRowPartialCtx(_ context.Context, v any, query string, args ...any) error {
|
||||
if d.queryRow != nil {
|
||||
return d.queryRow(v, query, args...)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -735,7 +782,11 @@ func (d dummySqlConn) QueryRowsCtx(_ context.Context, _ any, _ string, _ ...any)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d dummySqlConn) QueryRowsPartialCtx(_ context.Context, _ any, _ string, _ ...any) error {
|
||||
func (d dummySqlConn) QueryRowsPartialCtx(_ context.Context, v any, query string, args ...any) error {
|
||||
if d.queryRows != nil {
|
||||
return d.queryRows(v, query, args...)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,12 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
case kindOtlpHttp:
|
||||
// Not support flexible configuration now.
|
||||
opts := []otlptracehttp.Option{
|
||||
otlptracehttp.WithInsecure(),
|
||||
otlptracehttp.WithEndpoint(c.Endpoint),
|
||||
}
|
||||
|
||||
if !c.OtlpHttpSecure {
|
||||
opts = append(opts, otlptracehttp.WithInsecure())
|
||||
}
|
||||
if len(c.OtlpHeaders) > 0 {
|
||||
opts = append(opts, otlptracehttp.WithHeaders(c.OtlpHeaders))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ type Config struct {
|
||||
// For example
|
||||
// /v1/traces
|
||||
OtlpHttpPath string `json:",optional"`
|
||||
// OtlpHttpSecure represents the scheme to use for OTLP HTTP transport.
|
||||
OtlpHttpSecure bool `json:",optional"`
|
||||
// Disabled indicates whether StartAgent starts the agent.
|
||||
Disabled bool `json:",optional"`
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
@@ -13,8 +14,9 @@ import (
|
||||
)
|
||||
|
||||
func TestMessageType_Event(t *testing.T) {
|
||||
var span mockSpan
|
||||
ctx := trace.ContextWithSpan(context.Background(), &span)
|
||||
ctx, s := otel.Tracer(TraceName).Start(context.Background(), "test")
|
||||
span := mockSpan{Span: s}
|
||||
ctx = trace.ContextWithSpan(ctx, &span)
|
||||
MessageReceived.Event(ctx, 1, "foo")
|
||||
assert.Equal(t, messageEvent, span.name)
|
||||
assert.NotEmpty(t, span.options)
|
||||
@@ -30,6 +32,7 @@ func TestMessageType_EventProtoMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
type mockSpan struct {
|
||||
trace.Span
|
||||
name string
|
||||
options []trace.EventOption
|
||||
}
|
||||
|
||||
107
go.mod
107
go.mod
@@ -1,61 +1,61 @@
|
||||
module github.com/zeromicro/go-zero
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/alicebob/miniredis/v2 v2.32.1
|
||||
github.com/fatih/color v1.16.0
|
||||
github.com/alicebob/miniredis/v2 v2.33.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.5.5
|
||||
github.com/jhump/protoreflect v1.16.0
|
||||
github.com/jackc/pgx/v5 v5.6.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.18.0
|
||||
github.com/redis/go-redis/v9 v9.4.0
|
||||
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.13
|
||||
go.etcd.io/etcd/client/v3 v3.5.13
|
||||
go.mongodb.org/mongo-driver v1.13.1
|
||||
go.opentelemetry.io/otel v1.19.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.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.19.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.19.0
|
||||
go.opentelemetry.io/otel/sdk v1.19.0
|
||||
go.opentelemetry.io/otel/trace v1.19.0
|
||||
go.uber.org/automaxprocs v1.5.3
|
||||
go.uber.org/goleak v1.2.1
|
||||
golang.org/x/net v0.25.0
|
||||
golang.org/x/sys v0.20.0
|
||||
golang.org/x/time v0.5.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
|
||||
google.golang.org/grpc v1.63.2
|
||||
google.golang.org/protobuf v1.34.1
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0
|
||||
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.6.0
|
||||
go.uber.org/goleak v1.3.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.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
|
||||
k8s.io/api v0.29.3
|
||||
k8s.io/apimachinery v0.29.4
|
||||
k8s.io/client-go v0.29.3
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
|
||||
)
|
||||
|
||||
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/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // 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
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
@@ -63,7 +63,7 @@ require (
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
|
||||
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||
@@ -73,49 +73,48 @@ require (
|
||||
github.com/google/gnostic-models v0.6.8 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
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.16.7 // 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
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.2 // 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.45.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.13 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.19.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
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.23.0 // indirect
|
||||
golang.org/x/oauth2 v0.17.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/term v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // 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
|
||||
k8s.io/klog/v2 v2.110.1 // indirect
|
||||
|
||||
230
go.sum
230
go.sum
@@ -2,27 +2,23 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
|
||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||
github.com/alicebob/miniredis/v2 v2.32.1 h1:Bz7CciDnYSaa0mX5xODh6GUITRSx+cVhjNoOR4JssBo=
|
||||
github.com/alicebob/miniredis/v2 v2.32.1/go.mod h1:AqkLNAfUm0K07J28hnAyyQKf/x0YkCY/g5DCtuL01Mw=
|
||||
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
|
||||
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
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/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
|
||||
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ=
|
||||
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
|
||||
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=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw=
|
||||
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
|
||||
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
|
||||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||
@@ -39,13 +35,14 @@ 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.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
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=
|
||||
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
||||
@@ -61,22 +58,16 @@ 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/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
|
||||
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.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
@@ -86,20 +77,20 @@ github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
|
||||
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/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=
|
||||
@@ -107,15 +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.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
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=
|
||||
@@ -126,15 +118,13 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
@@ -143,24 +133,24 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
|
||||
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
|
||||
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
|
||||
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
|
||||
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
|
||||
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/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.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
|
||||
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
|
||||
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.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
|
||||
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
|
||||
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.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=
|
||||
github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
||||
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=
|
||||
@@ -186,63 +176,60 @@ 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-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
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=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||
go.etcd.io/etcd/api/v3 v3.5.13 h1:8WXU2/NBge6AUF1K1gOexB6e07NgsN1hXK0rSTtgSp4=
|
||||
go.etcd.io/etcd/api/v3 v3.5.13/go.mod h1:gBqlqkcMMZMVTMm4NDZloEVJzxQOQIls8splbqBDa0c=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.13 h1:RVZSAnWWWiI5IrYAXjQorajncORbS0zI48LQlE2kQWg=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.13/go.mod h1:XxHT4u1qU12E2+po+UVPrEeL94Um6zL58ppuJWXSAB8=
|
||||
go.etcd.io/etcd/client/v3 v3.5.13 h1:o0fHTNJLeO0MyVbc7I3fsCf6nrOqn5d+diSarKnB2js=
|
||||
go.etcd.io/etcd/client/v3 v3.5.13/go.mod h1:cqiAeY8b5DEEcpxvgWKsbLIWNM/8Wy2xJSDMtioMcoI=
|
||||
go.mongodb.org/mongo-driver v1.13.1 h1:YIc7HTYsKndGK4RFzJ3covLz1byri52x0IoMB0Pt/vk=
|
||||
go.mongodb.org/mongo-driver v1.13.1/go.mod h1:wcDf1JBCXy2mOW0bWHwO/IOYqdca1MPCwDtFu/Z9+eo=
|
||||
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
|
||||
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
|
||||
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=
|
||||
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.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=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 h1:3d+S281UTjM+AbF31XSOYn1qXn3BgIdWl8HNEpx08Jk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0/go.mod h1:0+KuTDyKL4gjKCF75pHOX4wuzYDUZYfAQdSu43o+Z2I=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 h1:Nw7Dv4lwvGrI68+wULbcq7su9K2cebeCUrDjVrUJHxM=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0/go.mod h1:1MsF6Y7gTqosgoZvHlzcaaM8DIMNZgJh87ykokoNH7Y=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.19.0 h1:EGY0h5mGliP9o/nIkVuLI0vRiQqmsYOcbwCuotksO1o=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.19.0/go.mod h1:JQgTGJP11yi3o4GHzIWYodhPisxANdqxF1eHwDSnJrI=
|
||||
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
|
||||
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
|
||||
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
|
||||
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
|
||||
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
|
||||
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
|
||||
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
|
||||
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 h1:Mw5xcxMwlqoJd97vwPxA8isEaIoxsta9/Q51+TTJLGE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0/go.mod h1:CQNu9bj7o7mC6U7+CA/schKEYakYXWr79ucDHTMGhCM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 h1:s0PHtIkN+3xrbDOpt2M8OTG92cWqUESvzh2MxiR5xY8=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0/go.mod h1:hZlFbDbRt++MMPCCfSJfmhkGIWnX1h3XjkfxZUjLrIA=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 h1:3evrL5poBuh1KF51D9gO/S+N/1msnm4DaBqs/rpXUqY=
|
||||
go.opentelemetry.io/otel/exporters/zipkin v1.24.0/go.mod h1:0EHgD8R0+8yRhUYJOGR8Hfg2dpiJQxDOszd5smVO9wM=
|
||||
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
|
||||
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
|
||||
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
|
||||
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
|
||||
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
|
||||
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
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/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
|
||||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
||||
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=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||
go.uber.org/zap v1.24.0/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.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
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=
|
||||
@@ -253,73 +240,62 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
|
||||
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
|
||||
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.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
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=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.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.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
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.6/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.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
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=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
|
||||
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
|
||||
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
|
||||
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.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=
|
||||
@@ -345,8 +321,8 @@ k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
|
||||
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
|
||||
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
|
||||
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
22
readme-cn.md
22
readme-cn.md
@@ -8,13 +8,14 @@
|
||||
|
||||
[](https://github.com/zeromicro/go-zero/actions)
|
||||
[](https://goreportcard.com/report/github.com/zeromicro/go-zero)
|
||||
[](https://goproxy.cn/stats/github.com/tal-tech/go-zero/badges/download-count.svg)
|
||||
[](https://goproxy.cn/stats/github.com/zeromicro/go-zero/badges/download-count.svg)
|
||||
[](https://codecov.io/gh/zeromicro/go-zero)
|
||||
[](https://github.com/zeromicro/go-zero)
|
||||
[](https://pkg.go.dev/github.com/zeromicro/go-zero)
|
||||
[](https://github.com/avelino/awesome-go)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
<a href="https://trendshift.io/repositories/3263" target="_blank"><img src="https://trendshift.io/api/badge/repositories/3263" alt="zeromicro%2Fgo-zero | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||
<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go-zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go-zero - A web & rpc framework written in Go. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
||||
|
||||
## 0. go-zero 介绍
|
||||
@@ -117,25 +118,19 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
|
||||
# For Mac
|
||||
brew install goctl
|
||||
|
||||
# docker for amd64 architecture
|
||||
# docker for all platforms
|
||||
docker pull kevinwan/goctl
|
||||
# run goctl like
|
||||
# run goctl
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl --help
|
||||
|
||||
# docker for arm64(Mac) architecture
|
||||
docker pull kevinwan/goctl:latest-arm64
|
||||
# run goctl like
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 --help
|
||||
```
|
||||
|
||||
确保 goctl 可执行
|
||||
确保 goctl 可执行,并且在 $PATH 环境变量里。
|
||||
|
||||
2. 快速生成 api 服务
|
||||
|
||||
```shell
|
||||
goctl api new greet
|
||||
cd greet
|
||||
go mod init
|
||||
go mod tidy
|
||||
go run greet.go -f etc/greet-api.yaml
|
||||
```
|
||||
@@ -303,6 +298,7 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>99. 新华三技术有限公司
|
||||
>100. 上海邑脉科技有限公司
|
||||
>101. 上海巨瓴科技有限公司
|
||||
>102. 深圳市兴海物联科技有限公司
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
@@ -333,8 +329,8 @@ go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape
|
||||
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" />
|
||||
|
||||
## 13. 赞助一下👍
|
||||
## 13. 知识星球
|
||||
|
||||
如果觉得项目有帮助,可以请作者喝杯咖啡 🍹
|
||||
官方团队运营的知识星球
|
||||
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/sponsor.png" alt="wechat" width="300" />
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zsxq.jpg" alt="知识星球" width="300" />
|
||||
|
||||
16
readme.md
16
readme.md
@@ -22,6 +22,7 @@ go-zero is a web and rpc framework with lots of builtin engineering practices. I
|
||||
## 🤷 What is go-zero?
|
||||
English | [简体中文](readme-cn.md)
|
||||
|
||||
<a href="https://trendshift.io/repositories/3263" target="_blank"><img src="https://trendshift.io/api/badge/repositories/3263" alt="zeromicro%2Fgo-zero | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||
<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go-zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go-zero - A web & rpc framework written in Go. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
||||
|
||||
|
||||
@@ -42,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
|
||||
@@ -124,18 +124,13 @@ go get -u github.com/zeromicro/go-zero
|
||||
# For Mac
|
||||
brew install goctl
|
||||
|
||||
# docker for amd64 architecture
|
||||
# docker for all platforms
|
||||
docker pull kevinwan/goctl
|
||||
# run goctl like
|
||||
# run goctl
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl --help
|
||||
|
||||
# docker for arm64(Mac) architecture
|
||||
docker pull kevinwan/goctl:latest-arm64
|
||||
# run goctl like
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 --help
|
||||
```
|
||||
|
||||
make sure goctl is executable.
|
||||
make sure goctl is executable and in your $PATH.
|
||||
|
||||
3. Create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
|
||||
|
||||
@@ -194,7 +189,6 @@ go get -u github.com/zeromicro/go-zero
|
||||
|
||||
```shell
|
||||
cd greet
|
||||
go mod init
|
||||
go mod tidy
|
||||
go run greet.go -f etc/greet-api.yaml
|
||||
```
|
||||
@@ -256,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
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ func fillPath(u *nurl.URL, val map[string]any) error {
|
||||
delete(val, key)
|
||||
}
|
||||
|
||||
var unused []string
|
||||
unused := make([]string, 0, len(val))
|
||||
for key := range val {
|
||||
unused = append(unused, key)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
79
rest/internal/fileserver/filehandler.go
Normal file
79
rest/internal/fileserver/filehandler.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package fileserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Middleware returns a middleware that serves files from the given file system.
|
||||
func Middleware(path string, fs http.FileSystem) func(http.HandlerFunc) http.HandlerFunc {
|
||||
fileServer := http.FileServer(fs)
|
||||
pathWithoutTrailSlash := ensureNoTrailingSlash(path)
|
||||
canServe := createServeChecker(path, fs)
|
||||
|
||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if canServe(r) {
|
||||
r.URL.Path = r.URL.Path[len(pathWithoutTrailSlash):]
|
||||
fileServer.ServeHTTP(w, r)
|
||||
} else {
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createFileChecker(fs http.FileSystem) func(string) bool {
|
||||
var lock sync.RWMutex
|
||||
fileChecker := make(map[string]bool)
|
||||
|
||||
return func(path string) bool {
|
||||
lock.RLock()
|
||||
exist, ok := fileChecker[path]
|
||||
lock.RUnlock()
|
||||
if ok {
|
||||
return exist
|
||||
}
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
file, err := fs.Open(path)
|
||||
exist = err == nil
|
||||
fileChecker[path] = exist
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
_ = file.Close()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func createServeChecker(path string, fs http.FileSystem) func(r *http.Request) bool {
|
||||
pathWithTrailSlash := ensureTrailingSlash(path)
|
||||
fileChecker := createFileChecker(fs)
|
||||
|
||||
return func(r *http.Request) bool {
|
||||
return r.Method == http.MethodGet &&
|
||||
strings.HasPrefix(r.URL.Path, pathWithTrailSlash) &&
|
||||
fileChecker(r.URL.Path[len(pathWithTrailSlash):])
|
||||
}
|
||||
}
|
||||
|
||||
func ensureTrailingSlash(path string) string {
|
||||
if strings.HasSuffix(path, "/") {
|
||||
return path
|
||||
}
|
||||
|
||||
return path + "/"
|
||||
}
|
||||
|
||||
func ensureNoTrailingSlash(path string) string {
|
||||
if strings.HasSuffix(path, "/") {
|
||||
return path[:len(path)-1]
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
122
rest/internal/fileserver/filehandler_test.go
Normal file
122
rest/internal/fileserver/filehandler_test.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package fileserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMiddleware(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
dir string
|
||||
requestPath string
|
||||
expectedStatus int
|
||||
expectedContent string
|
||||
}{
|
||||
{
|
||||
name: "Serve static file",
|
||||
path: "/static/",
|
||||
dir: "./testdata",
|
||||
requestPath: "/static/example.txt",
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedContent: "1",
|
||||
},
|
||||
{
|
||||
name: "Pass through non-matching path",
|
||||
path: "/static/",
|
||||
dir: "./testdata",
|
||||
requestPath: "/other/path",
|
||||
expectedStatus: http.StatusAlreadyReported,
|
||||
},
|
||||
{
|
||||
name: "Directory with trailing slash",
|
||||
path: "/assets",
|
||||
dir: "testdata",
|
||||
requestPath: "/assets/sample.txt",
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedContent: "2",
|
||||
},
|
||||
{
|
||||
name: "Not exist file",
|
||||
path: "/assets",
|
||||
dir: "testdata",
|
||||
requestPath: "/assets/not-exist.txt",
|
||||
expectedStatus: http.StatusAlreadyReported,
|
||||
},
|
||||
{
|
||||
name: "Not exist file in root",
|
||||
path: "/",
|
||||
dir: "testdata",
|
||||
requestPath: "/not-exist.txt",
|
||||
expectedStatus: http.StatusAlreadyReported,
|
||||
},
|
||||
{
|
||||
name: "websocket request",
|
||||
path: "/",
|
||||
dir: "testdata",
|
||||
requestPath: "/ws",
|
||||
expectedStatus: http.StatusAlreadyReported,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
middleware := Middleware(tt.path, http.Dir(tt.dir))
|
||||
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusAlreadyReported)
|
||||
})
|
||||
|
||||
handlerToTest := middleware(nextHandler)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
req := httptest.NewRequest(http.MethodGet, tt.requestPath, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handlerToTest.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, tt.expectedStatus, rr.Code)
|
||||
if len(tt.expectedContent) > 0 {
|
||||
assert.Equal(t, tt.expectedContent, rr.Body.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureTrailingSlash(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"path", "path/"},
|
||||
{"path/", "path/"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
result := ensureTrailingSlash(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureNoTrailingSlash(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"path", "path"},
|
||||
{"path/", "path"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
result := ensureNoTrailingSlash(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
1
rest/internal/fileserver/testdata/example.txt
vendored
Normal file
1
rest/internal/fileserver/testdata/example.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
1
rest/internal/fileserver/testdata/sample.txt
vendored
Normal file
1
rest/internal/fileserver/testdata/sample.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
2
|
||||
@@ -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()
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/internal"
|
||||
"github.com/zeromicro/go-zero/rest/internal/cors"
|
||||
"github.com/zeromicro/go-zero/rest/internal/fileserver"
|
||||
"github.com/zeromicro/go-zero/rest/router"
|
||||
)
|
||||
|
||||
@@ -85,7 +86,7 @@ func (s *Server) PrintRoutes() {
|
||||
|
||||
// Routes returns the HTTP routers that registered in the server.
|
||||
func (s *Server) Routes() []Route {
|
||||
var routes []Route
|
||||
routes := make([]Route, 0, len(s.ngin.routes))
|
||||
|
||||
for _, r := range s.ngin.routes {
|
||||
routes = append(routes, r.routes...)
|
||||
@@ -160,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),
|
||||
@@ -170,6 +183,13 @@ func WithCustomCors(middlewareFn func(header http.Header), notAllowedFn func(htt
|
||||
}
|
||||
}
|
||||
|
||||
// WithFileServer returns a RunOption to serve files from given dir with given path.
|
||||
func WithFileServer(path string, fs http.FileSystem) RunOption {
|
||||
return func(server *Server) {
|
||||
server.router = newFileServingRouter(server.router, path, fs)
|
||||
}
|
||||
}
|
||||
|
||||
// WithJwt returns a func to enable jwt authentication in given route.
|
||||
func WithJwt(secret string) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
@@ -241,7 +261,7 @@ func WithNotAllowedHandler(handler http.Handler) RunOption {
|
||||
// WithPrefix adds group as a prefix to the route paths.
|
||||
func WithPrefix(group string) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
var routes []Route
|
||||
routes := make([]Route, 0, len(r.routes))
|
||||
for _, rt := range r.routes {
|
||||
p := path.Join(group, rt.Path)
|
||||
routes = append(routes, Route{
|
||||
@@ -337,3 +357,19 @@ func newCorsRouter(router httpx.Router, headerFn func(http.Header), origins ...s
|
||||
func (c *corsRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.middleware(c.Router.ServeHTTP)(w, r)
|
||||
}
|
||||
|
||||
type fileServingRouter struct {
|
||||
httpx.Router
|
||||
middleware Middleware
|
||||
}
|
||||
|
||||
func newFileServingRouter(router httpx.Router, path string, fs http.FileSystem) httpx.Router {
|
||||
return &fileServingRouter{
|
||||
Router: router,
|
||||
middleware: fileserver.Middleware(path, fs),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fileServingRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
f.middleware(f.Router.ServeHTTP)(w, r)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package rest
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -21,6 +23,11 @@ import (
|
||||
"github.com/zeromicro/go-zero/rest/router"
|
||||
)
|
||||
|
||||
const (
|
||||
exampleContent = "example content"
|
||||
sampleContent = "sample content"
|
||||
)
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
logtest.Discard(t)
|
||||
|
||||
@@ -184,6 +191,56 @@ func TestWithMiddleware(t *testing.T) {
|
||||
}, m)
|
||||
}
|
||||
|
||||
func TestWithFileServerMiddleware(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
dir string
|
||||
requestPath string
|
||||
expectedStatus int
|
||||
expectedContent string
|
||||
}{
|
||||
{
|
||||
name: "Serve static file",
|
||||
path: "/assets/",
|
||||
dir: "./testdata",
|
||||
requestPath: "/assets/example.txt",
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedContent: exampleContent,
|
||||
},
|
||||
{
|
||||
name: "Pass through non-matching path",
|
||||
path: "/static/",
|
||||
dir: "./testdata",
|
||||
requestPath: "/other/path",
|
||||
expectedStatus: http.StatusNotFound,
|
||||
},
|
||||
{
|
||||
name: "Directory with trailing slash",
|
||||
path: "/static",
|
||||
dir: "testdata",
|
||||
requestPath: "/static/sample.txt",
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedContent: sampleContent,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
server := MustNewServer(RestConf{}, WithFileServer(tt.path, http.Dir(tt.dir)))
|
||||
req := httptest.NewRequest(http.MethodGet, tt.requestPath, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
server.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, tt.expectedStatus, rr.Code)
|
||||
if len(tt.expectedContent) > 0 {
|
||||
assert.Equal(t, tt.expectedContent, rr.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiMiddlewares(t *testing.T) {
|
||||
m := make(map[string]string)
|
||||
rt := router.NewRouter()
|
||||
@@ -363,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 = `
|
||||
@@ -638,3 +753,18 @@ Port: 54321
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//go:embed testdata
|
||||
var content embed.FS
|
||||
|
||||
func TestServerEmbedFileSystem(t *testing.T) {
|
||||
filesys, err := fs.Sub(content, "testdata")
|
||||
assert.NoError(t, err)
|
||||
|
||||
server := MustNewServer(RestConf{}, WithFileServer("/assets", http.FS(filesys)))
|
||||
req, err := http.NewRequest(http.MethodGet, "/assets/sample.txt", http.NoBody)
|
||||
assert.Nil(t, err)
|
||||
rr := httptest.NewRecorder()
|
||||
server.ServeHTTP(rr, req)
|
||||
assert.Equal(t, sampleContent, rr.Body.String())
|
||||
}
|
||||
|
||||
1
rest/testdata/example.txt
vendored
Normal file
1
rest/testdata/example.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example content
|
||||
1
rest/testdata/sample.txt
vendored
Normal file
1
rest/testdata/sample.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
sample content
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dartgen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -8,8 +9,8 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
)
|
||||
|
||||
const dataTemplate = `// --{{with .Info}}{{.Title}}{{end}}--
|
||||
{{ range .Types}}
|
||||
const dataTemplate = `// --{{with .APISpec.Info}}{{.Title}}{{end}}--
|
||||
{{ range .APISpec.Types}}
|
||||
class {{.Name}}{
|
||||
{{range .Members}}
|
||||
/// {{.Comment}}
|
||||
@@ -28,12 +29,16 @@ class {{.Name}}{
|
||||
'{{getPropertyFromMember .}}': {{if isDirectType .Type.Name}}{{lowCamelCase .Name}}{{else if isClassListType .Type.Name}}{{lowCamelCase .Name}}.map((i) => i.toJson()){{else}}{{lowCamelCase .Name}}.toJson(){{end}},{{end}}
|
||||
};
|
||||
}
|
||||
|
||||
{{ range $.InnerClassList}}
|
||||
{{.}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
`
|
||||
|
||||
const dataTemplateV2 = `// --{{with .Info}}{{.Title}}{{end}}--
|
||||
{{ range .Types}}
|
||||
const dataTemplateV2 = `// --{{with .APISpec.Info}}{{.Title}}{{end}}--
|
||||
{{ range .APISpec.Types}}
|
||||
class {{.Name}} {
|
||||
{{range .Members}}
|
||||
{{if .Comment}}{{.Comment}}{{end}}
|
||||
@@ -73,9 +78,18 @@ class {{.Name}} {
|
||||
,{{end}}
|
||||
};
|
||||
}
|
||||
|
||||
{{ range $.InnerClassList}}
|
||||
{{.}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}`
|
||||
|
||||
type DartSpec struct {
|
||||
APISpec *spec.ApiSpec
|
||||
InnerClassList []string
|
||||
}
|
||||
|
||||
func genData(dir string, api *spec.ApiSpec, isLegacy bool) error {
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
@@ -104,12 +118,12 @@ func genData(dir string, api *spec.ApiSpec, isLegacy bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = convertDataType(api)
|
||||
err, dartSpec := convertDataType(api, isLegacy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.Execute(file, api)
|
||||
return t.Execute(file, dartSpec)
|
||||
}
|
||||
|
||||
func genTokens(dir string, isLeagcy bool) error {
|
||||
@@ -132,24 +146,61 @@ func genTokens(dir string, isLeagcy bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func convertDataType(api *spec.ApiSpec) error {
|
||||
func convertDataType(api *spec.ApiSpec, isLegacy bool) (error, *DartSpec) {
|
||||
var result DartSpec
|
||||
types := api.Types
|
||||
if len(types) == 0 {
|
||||
return nil
|
||||
return nil, &result
|
||||
}
|
||||
|
||||
for _, ty := range types {
|
||||
defineStruct, ok := ty.(spec.DefineStruct)
|
||||
if ok {
|
||||
for index, member := range defineStruct.Members {
|
||||
tp, err := specTypeToDart(member.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
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)
|
||||
tpl := dataTemplateV2
|
||||
if isLegacy {
|
||||
tpl = dataTemplate
|
||||
}
|
||||
t, err := t.Parse(tpl)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
var innerClassSpec = &spec.ApiSpec{
|
||||
Types: []spec.Type{
|
||||
spec.DefineStruct{
|
||||
RawName: member.Name,
|
||||
Members: structMember.Members,
|
||||
},
|
||||
},
|
||||
}
|
||||
err, dartSpec := convertDataType(innerClassSpec, isLegacy)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
writer := bytes.NewBuffer(nil)
|
||||
err = t.Execute(writer, dartSpec)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
result.InnerClassList = append(result.InnerClassList, writer.String())
|
||||
} else {
|
||||
tp, err := specTypeToDart(member.Type)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
defineStruct.Members[index].Type = buildSpecType(member.Type, tp)
|
||||
}
|
||||
defineStruct.Members[index].Type = buildSpecType(member.Type, tp)
|
||||
}
|
||||
}
|
||||
}
|
||||
result.APISpec = api
|
||||
|
||||
return nil
|
||||
return nil, &result
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ var (
|
||||
importTwiceApi string
|
||||
//go:embed testdata/another_import_api.api
|
||||
anotherImportApi string
|
||||
//go:embed testdata/example.api
|
||||
exampleApi string
|
||||
)
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
@@ -316,15 +318,32 @@ func TestCamelStyle(t *testing.T) {
|
||||
validateWithCamel(t, filename, "GoZero")
|
||||
}
|
||||
|
||||
func TestExampleGen(t *testing.T) {
|
||||
env.Set(t, env.GoctlExperimental, env.ExperimentalOn)
|
||||
filename := "greet.api"
|
||||
err := os.WriteFile(filename, []byte(exampleApi), os.ModePerm)
|
||||
assert.Nil(t, err)
|
||||
t.Cleanup(func() {
|
||||
_ = os.Remove(filename)
|
||||
})
|
||||
|
||||
spec, err := parser.Parse(filename)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(spec.Types), 10)
|
||||
|
||||
validate(t, filename)
|
||||
}
|
||||
|
||||
func validate(t *testing.T, api string) {
|
||||
validateWithCamel(t, api, "gozero")
|
||||
}
|
||||
|
||||
func validateWithCamel(t *testing.T, api, camel string) {
|
||||
dir := "workspace"
|
||||
defer func() {
|
||||
os.RemoveAll(dir)
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
_ = os.RemoveAll(dir)
|
||||
})
|
||||
|
||||
err := pathx.MkdirIfNotExist(dir)
|
||||
assert.Nil(t, err)
|
||||
err = initMod(dir)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -74,8 +76,21 @@ func writeType(writer io.Writer, tp spec.Type) error {
|
||||
return fmt.Errorf("unspport struct type: %s", tp.Name())
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "type %s struct {\n", util.Title(tp.Name()))
|
||||
for _, member := range structType.Members {
|
||||
_, err := fmt.Fprintf(writer, "type %s struct {\n", util.Title(tp.Name()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := writeMember(writer, structType.Members); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(writer, "}")
|
||||
return err
|
||||
}
|
||||
|
||||
func writeMember(writer io.Writer, members []spec.Member) error {
|
||||
for _, member := range members {
|
||||
if member.IsInline {
|
||||
if _, err := fmt.Fprintf(writer, "%s\n", strings.Title(member.Type.Name())); err != nil {
|
||||
return err
|
||||
@@ -88,6 +103,5 @@ func writeType(writer io.Writer, tp spec.Type) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(writer, "}")
|
||||
return nil
|
||||
}
|
||||
|
||||
99
tools/goctl/api/gogen/testdata/example.api
vendored
Normal file
99
tools/goctl/api/gogen/testdata/example.api
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
syntax = "v1"
|
||||
|
||||
info(
|
||||
title: "demo title"
|
||||
desc: "demo desc"
|
||||
author: "keson.an"
|
||||
date: "2024-06-25"
|
||||
version: "v1"
|
||||
)
|
||||
|
||||
// empty structure
|
||||
type Foo {
|
||||
}
|
||||
|
||||
// type lit
|
||||
type Bar {
|
||||
Foo int `json:"foo"`
|
||||
Bar bool `json:"bar"`
|
||||
Baz []string `json:"baz"`
|
||||
Qux map[string]string `json:"qux"`
|
||||
}
|
||||
|
||||
type Baz {
|
||||
Foo `json:"foo"`
|
||||
// array type
|
||||
Arr [2]int `json:"arr"`
|
||||
// nested type
|
||||
Bar {
|
||||
Foo string `json:"foo"`
|
||||
Bar bool `json:"bar"`
|
||||
Baz {
|
||||
Foo string `json:"foo"`
|
||||
Bar bool `json:"bar"`
|
||||
}
|
||||
Qux {
|
||||
Foo string `json:"foo"`
|
||||
Bar bool `json:"bar"`
|
||||
} `json:"qux"`
|
||||
} `json:"bar"`
|
||||
}
|
||||
|
||||
|
||||
type UpdateReq {
|
||||
Arg1 string `json:"arg1"`
|
||||
}
|
||||
|
||||
type ListItem {
|
||||
Value1 string `json:"value1"`
|
||||
}
|
||||
|
||||
type LoginReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type LoginResp {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FormExampleReq {
|
||||
Name string `form:"name"`
|
||||
}
|
||||
|
||||
type PathExampleReq {
|
||||
ID string `path:"id"`
|
||||
}
|
||||
|
||||
type PathExampleResp {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
@server(
|
||||
jwt: Auth
|
||||
prefix: /v1
|
||||
group: g1
|
||||
timeout: 3s
|
||||
middleware: AuthInterceptor
|
||||
maxBytes: 1048576
|
||||
)
|
||||
service Foo {
|
||||
@handler ping
|
||||
get /ping
|
||||
|
||||
@handler update
|
||||
post /update (UpdateReq)
|
||||
|
||||
@handler list
|
||||
get /list returns ([]ListItem)
|
||||
|
||||
@handler login
|
||||
post /login (LoginReq) returns (LoginResp)
|
||||
|
||||
@handler formExample
|
||||
post /form/example (FormExampleReq)
|
||||
|
||||
@handler pathExample
|
||||
get /path/example/:id (PathExampleReq) returns (PathExampleResp)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl {{.version}}
|
||||
|
||||
package types{{if .containsTime}}
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -59,16 +59,59 @@ func genFile(c fileGenConfig) error {
|
||||
|
||||
func writeProperty(writer io.Writer, name, tag, comment string, tp spec.Type, indent int) error {
|
||||
util.WriteIndent(writer, indent)
|
||||
var err error
|
||||
var (
|
||||
err error
|
||||
isNestedStruct bool
|
||||
)
|
||||
structType, ok := tp.(spec.NestedStruct)
|
||||
if ok {
|
||||
isNestedStruct = true
|
||||
}
|
||||
if len(comment) > 0 {
|
||||
comment = strings.TrimPrefix(comment, "//")
|
||||
comment = "//" + comment
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s %s\n", strings.Title(name), tp.Name(), tag, comment)
|
||||
} else {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s\n", strings.Title(name), tp.Name(), tag)
|
||||
}
|
||||
|
||||
return err
|
||||
if isNestedStruct {
|
||||
_, err = fmt.Fprintf(writer, "%s struct {\n", strings.Title(name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := writeMember(writer, structType.Members); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(writer, "} %s", tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(comment) > 0 {
|
||||
_, err = fmt.Fprintf(writer, " %s", comment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = fmt.Fprint(writer, "\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if len(comment) > 0 {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s %s\n", strings.Title(name), tp.Name(), tag, comment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s\n", strings.Title(name), tp.Name(), tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAuths(api *spec.ApiSpec) []string {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
)
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
|
||||
// ImportExpr defines import syntax for api
|
||||
type ImportExpr struct {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
)
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
|
||||
// InfoExpr defines info syntax for api
|
||||
type InfoExpr struct {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
)
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||
|
||||
// SyntaxExpr describes syntax for api
|
||||
type SyntaxExpr struct {
|
||||
|
||||
@@ -30,6 +30,21 @@ func (t DefineStruct) Documents() []string {
|
||||
return t.Docs
|
||||
}
|
||||
|
||||
// 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
|
||||
func (t MapType) Name() string {
|
||||
return t.RawName
|
||||
|
||||
@@ -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,19 +8,38 @@ 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"
|
||||
)
|
||||
|
||||
//go:embed components.tpl
|
||||
var componentsTemplate string
|
||||
|
||||
// BuildTypes generates the typescript code for the types.
|
||||
func BuildTypes(types []spec.Type) (string, error) {
|
||||
var builder strings.Builder
|
||||
first := true
|
||||
for _, tp := range types {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
builder.WriteString("\n")
|
||||
}
|
||||
if err := writeType(&builder, tp); err != nil {
|
||||
return "", apiutil.WrapErr(err, "Type "+tp.Name()+" generate error")
|
||||
}
|
||||
}
|
||||
|
||||
return builder.String(), nil
|
||||
}
|
||||
|
||||
func genComponents(dir string, api *spec.ApiSpec) error {
|
||||
types := api.Types
|
||||
if len(types) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
val, err := buildTypes(types)
|
||||
val, err := BuildTypes(types)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,22 +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,
|
||||
})
|
||||
}
|
||||
|
||||
func buildTypes(types []spec.Type) (string, error) {
|
||||
var builder strings.Builder
|
||||
first := true
|
||||
for _, tp := range types {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
builder.WriteString("\n")
|
||||
}
|
||||
if err := writeType(&builder, tp); err != nil {
|
||||
return "", apiutil.WrapErr(err, "Type "+tp.Name()+" generate error")
|
||||
}
|
||||
}
|
||||
|
||||
return builder.String(), nil
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tsgen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -19,7 +20,7 @@ const (
|
||||
|
||||
func writeProperty(writer io.Writer, member spec.Member, indent int) error {
|
||||
writeIndent(writer, indent)
|
||||
ty, err := genTsType(member)
|
||||
ty, err := genTsType(member, indent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -40,7 +41,7 @@ func writeProperty(writer io.Writer, member spec.Member, indent int) error {
|
||||
}
|
||||
if len(member.Docs) > 0 {
|
||||
fmt.Fprintf(writer, "%s\n", strings.Join(member.Docs, ""))
|
||||
writeIndent(writer, 1)
|
||||
writeIndent(writer, indent)
|
||||
}
|
||||
_, err = fmt.Fprintf(writer, "%s%s: %s%s\n", name, optionalTag, ty, comment)
|
||||
return err
|
||||
@@ -52,7 +53,27 @@ func writeIndent(writer io.Writer, indent int) {
|
||||
}
|
||||
}
|
||||
|
||||
func genTsType(m spec.Member) (ty string, err error) {
|
||||
func genTsType(m spec.Member, indent int) (ty string, err error) {
|
||||
v, ok := m.Type.(spec.NestedStruct)
|
||||
if ok {
|
||||
writer := bytes.NewBuffer(nil)
|
||||
_, err := fmt.Fprintf(writer, "{\n")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := writeMembers(writer, v, false, indent+1); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
writeIndent(writer, indent)
|
||||
_, err = fmt.Fprintf(writer, "}")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return writer.String(), nil
|
||||
}
|
||||
|
||||
ty, err = goTypeToTs(m.Type, false)
|
||||
if enums := m.GetEnumOptions(); enums != nil {
|
||||
if ty == "string" {
|
||||
@@ -130,7 +151,7 @@ func primitiveType(tp string) (string, bool) {
|
||||
|
||||
func writeType(writer io.Writer, tp spec.Type) error {
|
||||
fmt.Fprintf(writer, "export interface %s {\n", util.Title(tp.Name()))
|
||||
if err := writeMembers(writer, tp, false); err != nil {
|
||||
if err := writeMembers(writer, tp, false, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -166,12 +187,12 @@ func genParamsTypesIfNeed(writer io.Writer, tp spec.Type) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeMembers(writer io.Writer, tp spec.Type, isParam bool) error {
|
||||
func writeMembers(writer io.Writer, tp spec.Type, isParam bool, indent int) error {
|
||||
definedType, ok := tp.(spec.DefineStruct)
|
||||
if !ok {
|
||||
pointType, ok := tp.(spec.PointerType)
|
||||
if ok {
|
||||
return writeMembers(writer, pointType.Type, isParam)
|
||||
return writeMembers(writer, pointType.Type, isParam, indent)
|
||||
}
|
||||
|
||||
return fmt.Errorf("type %s not supported", tp.Name())
|
||||
@@ -183,13 +204,13 @@ func writeMembers(writer io.Writer, tp spec.Type, isParam bool) error {
|
||||
}
|
||||
for _, member := range members {
|
||||
if member.IsInline {
|
||||
if err := writeMembers(writer, member.Type, isParam); err != nil {
|
||||
if err := writeMembers(writer, member.Type, isParam, indent); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if err := writeProperty(writer, member, 1); err != nil {
|
||||
if err := writeProperty(writer, member, indent); err != nil {
|
||||
return apiutil.WrapErr(err, " type "+tp.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ func TestGenTsType(t *testing.T) {
|
||||
Docs: nil,
|
||||
IsInline: false,
|
||||
}
|
||||
ty, err := genTsType(member)
|
||||
ty, err := genTsType(member, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, `'foo' | 'bar' | 'options' | '123'`, ty)
|
||||
|
||||
member.IsInline = true
|
||||
ty, err = genTsType(member)
|
||||
ty, err = genTsType(member, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func TestGenTsType(t *testing.T) {
|
||||
|
||||
member.Type = spec.PrimitiveType{RawName: "int"}
|
||||
member.Tag = `json:"foo,options=1|3|4|123"`
|
||||
ty, err = genTsType(member)
|
||||
ty, err = genTsType(member, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
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{}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user