mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-12 01:10:00 +08:00
Compare commits
89 Commits
tools/goct
...
v1.6.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25821bdee6 | ||
|
|
b624b966f0 | ||
|
|
df96262235 | ||
|
|
2629636f64 | ||
|
|
708ad207d7 | ||
|
|
b53ba76a99 | ||
|
|
be7f93924a | ||
|
|
45be48a4ee | ||
|
|
e08ba2fee8 | ||
|
|
a5d2b971a1 | ||
|
|
9763c8b143 | ||
|
|
4e3f1776dc | ||
|
|
e38036cea2 | ||
|
|
8e97c5819f | ||
|
|
0ee44c7064 | ||
|
|
a1bacd3fc8 | ||
|
|
c98d5fdaf4 | ||
|
|
2ee43b41b8 | ||
|
|
8367af3416 | ||
|
|
03b6e377d7 | ||
|
|
ec41880476 | ||
|
|
5263805b3b | ||
|
|
a7363f0c21 | ||
|
|
52e5d85221 | ||
|
|
88aab8f635 | ||
|
|
1f63cbe9c6 | ||
|
|
0dfaf135dd | ||
|
|
914bcdcf2b | ||
|
|
e38cb0118d | ||
|
|
cb8161c799 | ||
|
|
c4dac2095f | ||
|
|
25a807afb2 | ||
|
|
6be37ad533 | ||
|
|
28cb2c5804 | ||
|
|
0f1d4c6bca | ||
|
|
bfe8335cb2 | ||
|
|
3c10ce0115 | ||
|
|
1303e0fe6f | ||
|
|
9c17499757 | ||
|
|
8ceb2885db | ||
|
|
00944894b4 | ||
|
|
609fb3d59e | ||
|
|
01c330abe7 | ||
|
|
2ccef5bb4f | ||
|
|
10f1d93e2a | ||
|
|
dd518c8eac | ||
|
|
97cf2421de | ||
|
|
786a80131e | ||
|
|
93d257f9f5 | ||
|
|
f79535057f | ||
|
|
a905f4c20c | ||
|
|
3331954a78 | ||
|
|
f54c2e384f | ||
|
|
4b83f2ebd0 | ||
|
|
1c572ee16b | ||
|
|
b3402430e8 | ||
|
|
076f5de7d9 | ||
|
|
303a74559a | ||
|
|
c08e741d7a | ||
|
|
06d2c07fce | ||
|
|
b6f00a5789 | ||
|
|
dace520654 | ||
|
|
44d347d48a | ||
|
|
408827d876 | ||
|
|
9e33b557b1 | ||
|
|
368caa7608 | ||
|
|
7822a4c1cb | ||
|
|
0441f84606 | ||
|
|
81d72b5010 | ||
|
|
7ba8adfc74 | ||
|
|
ffd2a78623 | ||
|
|
1b9b3cada7 | ||
|
|
38c8f9cf21 | ||
|
|
54dbb05bb9 | ||
|
|
9a671f6059 | ||
|
|
80aab0b3f8 | ||
|
|
2d0286646f | ||
|
|
d012fe97b1 | ||
|
|
7ca13bc25e | ||
|
|
9c20f10743 | ||
|
|
6ec38ec056 | ||
|
|
28c742a1e1 | ||
|
|
b3b6cfe947 | ||
|
|
a8ef7b51eb | ||
|
|
124968114a | ||
|
|
04ed821b65 | ||
|
|
15599ac0a0 | ||
|
|
0cf6971664 | ||
|
|
47c4f2831c |
@@ -1 +1,7 @@
|
||||
**/.git
|
||||
.dockerignore
|
||||
Dockerfile
|
||||
goctl
|
||||
Makefile
|
||||
readme.md
|
||||
readme-cn.md
|
||||
|
||||
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -5,6 +5,14 @@
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "docker" # Update image tags in Dockerfile
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "github-actions" # Update GitHub Actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "gomod" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
|
||||
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -64,4 +64,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
||||
10
.github/workflows/go.yml
vendored
10
.github/workflows/go.yml
vendored
@@ -15,9 +15,9 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.19
|
||||
go-version: '1.19'
|
||||
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@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
|
||||
test-win:
|
||||
name: Windows
|
||||
@@ -50,10 +50,10 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
# use 1.19 to guarantee Go 1.19 compatibility
|
||||
go-version: 1.19
|
||||
go-version: '1.19'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
2
.github/workflows/issues.yml
vendored
2
.github/workflows/issues.yml
vendored
@@ -7,7 +7,7 @@ jobs:
|
||||
close-issues:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v8
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
days-before-issue-stale: 365
|
||||
days-before-issue-close: 90
|
||||
|
||||
@@ -53,16 +53,19 @@ type (
|
||||
// DoWithFallback runs the fallback if the Breaker rejects the request.
|
||||
// If a panic occurs in the request, the Breaker handles it as an error
|
||||
// and causes the same panic again.
|
||||
DoWithFallback(req func() error, fallback func(err error) error) error
|
||||
DoWithFallback(req func() error, fallback Fallback) error
|
||||
|
||||
// DoWithFallbackAcceptable runs the given request if the Breaker accepts it.
|
||||
// DoWithFallbackAcceptable runs the fallback if the Breaker rejects the request.
|
||||
// If a panic occurs in the request, the Breaker handles it as an error
|
||||
// and causes the same panic again.
|
||||
// acceptable checks if it's a successful call, even if the error is not nil.
|
||||
DoWithFallbackAcceptable(req func() error, fallback func(err error) error, acceptable Acceptable) error
|
||||
DoWithFallbackAcceptable(req func() error, fallback Fallback, acceptable Acceptable) error
|
||||
}
|
||||
|
||||
// Fallback is the func to be called if the request is rejected.
|
||||
Fallback func(err error) error
|
||||
|
||||
// Option defines the method to customize a Breaker.
|
||||
Option func(breaker *circuitBreaker)
|
||||
|
||||
@@ -86,12 +89,12 @@ type (
|
||||
|
||||
internalThrottle interface {
|
||||
allow() (internalPromise, error)
|
||||
doReq(req func() error, fallback func(err error) error, acceptable Acceptable) error
|
||||
doReq(req func() error, fallback Fallback, acceptable Acceptable) error
|
||||
}
|
||||
|
||||
throttle interface {
|
||||
allow() (Promise, error)
|
||||
doReq(req func() error, fallback func(err error) error, acceptable Acceptable) error
|
||||
doReq(req func() error, fallback Fallback, acceptable Acceptable) error
|
||||
}
|
||||
)
|
||||
|
||||
@@ -122,11 +125,11 @@ func (cb *circuitBreaker) DoWithAcceptable(req func() error, acceptable Acceptab
|
||||
return cb.throttle.doReq(req, nil, acceptable)
|
||||
}
|
||||
|
||||
func (cb *circuitBreaker) DoWithFallback(req func() error, fallback func(err error) error) error {
|
||||
func (cb *circuitBreaker) DoWithFallback(req func() error, fallback Fallback) error {
|
||||
return cb.throttle.doReq(req, fallback, defaultAcceptable)
|
||||
}
|
||||
|
||||
func (cb *circuitBreaker) DoWithFallbackAcceptable(req func() error, fallback func(err error) error,
|
||||
func (cb *circuitBreaker) DoWithFallbackAcceptable(req func() error, fallback Fallback,
|
||||
acceptable Acceptable) error {
|
||||
return cb.throttle.doReq(req, fallback, acceptable)
|
||||
}
|
||||
@@ -168,7 +171,7 @@ func (lt loggedThrottle) allow() (Promise, error) {
|
||||
}, lt.logError(err)
|
||||
}
|
||||
|
||||
func (lt loggedThrottle) doReq(req func() error, fallback func(err error) error, acceptable Acceptable) error {
|
||||
func (lt loggedThrottle) doReq(req func() error, fallback Fallback, acceptable Acceptable) error {
|
||||
return lt.logError(lt.internalThrottle.doReq(req, fallback, func(err error) bool {
|
||||
accept := acceptable(err)
|
||||
if !accept && err != nil {
|
||||
|
||||
@@ -22,14 +22,14 @@ func DoWithAcceptable(name string, req func() error, acceptable Acceptable) erro
|
||||
}
|
||||
|
||||
// DoWithFallback calls Breaker.DoWithFallback on the Breaker with given name.
|
||||
func DoWithFallback(name string, req func() error, fallback func(err error) error) error {
|
||||
func DoWithFallback(name string, req func() error, fallback Fallback) error {
|
||||
return do(name, func(b Breaker) error {
|
||||
return b.DoWithFallback(req, fallback)
|
||||
})
|
||||
}
|
||||
|
||||
// DoWithFallbackAcceptable calls Breaker.DoWithFallbackAcceptable on the Breaker with given name.
|
||||
func DoWithFallbackAcceptable(name string, req func() error, fallback func(err error) error,
|
||||
func DoWithFallbackAcceptable(name string, req func() error, fallback Fallback,
|
||||
acceptable Acceptable) error {
|
||||
return do(name, func(b Breaker) error {
|
||||
return b.DoWithFallbackAcceptable(req, fallback, acceptable)
|
||||
@@ -59,7 +59,7 @@ func GetBreaker(name string) Breaker {
|
||||
// NoBreakerFor disables the circuit breaker for the given name.
|
||||
func NoBreakerFor(name string) {
|
||||
lock.Lock()
|
||||
breakers[name] = newNopBreaker()
|
||||
breakers[name] = NopBreaker()
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package breaker
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/collection"
|
||||
@@ -38,7 +37,8 @@ func (b *googleBreaker) accept() error {
|
||||
accepts, total := b.history()
|
||||
weightedAccepts := b.k * float64(accepts)
|
||||
// https://landing.google.com/sre/sre-book/chapters/handling-overload/#eq2101
|
||||
dropRatio := math.Max(0, (float64(total-protection)-weightedAccepts)/float64(total+1))
|
||||
// for better performance, no need to care about negative ratio
|
||||
dropRatio := (float64(total-protection) - weightedAccepts) / float64(total+1)
|
||||
if dropRatio <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -60,8 +60,9 @@ func (b *googleBreaker) allow() (internalPromise, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *googleBreaker) doReq(req func() error, fallback func(err error) error, acceptable Acceptable) error {
|
||||
func (b *googleBreaker) doReq(req func() error, fallback Fallback, acceptable Acceptable) error {
|
||||
if err := b.accept(); err != nil {
|
||||
b.markFailure()
|
||||
if fallback != nil {
|
||||
return fallback(err)
|
||||
}
|
||||
@@ -69,18 +70,19 @@ func (b *googleBreaker) doReq(req func() error, fallback func(err error) error,
|
||||
return err
|
||||
}
|
||||
|
||||
var success bool
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
// if req() panic, success is false, mark as failure
|
||||
if success {
|
||||
b.markSuccess()
|
||||
} else {
|
||||
b.markFailure()
|
||||
panic(e)
|
||||
}
|
||||
}()
|
||||
|
||||
err := req()
|
||||
if acceptable(err) {
|
||||
b.markSuccess()
|
||||
} else {
|
||||
b.markFailure()
|
||||
success = true
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -206,7 +206,7 @@ func BenchmarkGoogleBreakerAllow(b *testing.B) {
|
||||
breaker := getGoogleBreaker()
|
||||
b.ResetTimer()
|
||||
for i := 0; i <= b.N; i++ {
|
||||
breaker.accept()
|
||||
_ = breaker.accept()
|
||||
if i%2 == 0 {
|
||||
breaker.markSuccess()
|
||||
} else {
|
||||
@@ -215,6 +215,16 @@ func BenchmarkGoogleBreakerAllow(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGoogleBreakerDoReq(b *testing.B) {
|
||||
breaker := getGoogleBreaker()
|
||||
b.ResetTimer()
|
||||
for i := 0; i <= b.N; i++ {
|
||||
_ = breaker.doReq(func() error {
|
||||
return nil
|
||||
}, nil, defaultAcceptable)
|
||||
}
|
||||
}
|
||||
|
||||
func markSuccess(b *googleBreaker, count int) {
|
||||
for i := 0; i < count; i++ {
|
||||
p, err := b.allow()
|
||||
|
||||
@@ -4,7 +4,8 @@ const nopBreakerName = "nopBreaker"
|
||||
|
||||
type nopBreaker struct{}
|
||||
|
||||
func newNopBreaker() Breaker {
|
||||
// NopBreaker returns a breaker that never trigger breaker circuit.
|
||||
func NopBreaker() Breaker {
|
||||
return nopBreaker{}
|
||||
}
|
||||
|
||||
@@ -24,12 +25,11 @@ func (b nopBreaker) DoWithAcceptable(req func() error, _ Acceptable) error {
|
||||
return req()
|
||||
}
|
||||
|
||||
func (b nopBreaker) DoWithFallback(req func() error, _ func(err error) error) error {
|
||||
func (b nopBreaker) DoWithFallback(req func() error, _ Fallback) error {
|
||||
return req()
|
||||
}
|
||||
|
||||
func (b nopBreaker) DoWithFallbackAcceptable(req func() error, _ func(err error) error,
|
||||
_ Acceptable) error {
|
||||
func (b nopBreaker) DoWithFallbackAcceptable(req func() error, _ Fallback, _ Acceptable) error {
|
||||
return req()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNopBreaker(t *testing.T) {
|
||||
b := newNopBreaker()
|
||||
b := NopBreaker()
|
||||
assert.Equal(t, nopBreakerName, b.Name())
|
||||
p, err := b.Allow()
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -12,7 +12,7 @@ type RestfulConf struct {
|
||||
MaxConns int `json:",default=10000"`
|
||||
MaxBytes int64 `json:",default=1048576"`
|
||||
Timeout time.Duration `json:",default=3s"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000)"`
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package errorx
|
||||
|
||||
import "bytes"
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type (
|
||||
// A BatchError is an error that can hold multiple errors.
|
||||
BatchError struct {
|
||||
errs errorArray
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
errorArray []error
|
||||
@@ -13,6 +17,9 @@ type (
|
||||
|
||||
// Add adds errs to be, nil errors are ignored.
|
||||
func (be *BatchError) Add(errs ...error) {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
be.errs = append(be.errs, err)
|
||||
@@ -22,6 +29,9 @@ func (be *BatchError) Add(errs ...error) {
|
||||
|
||||
// Err returns an error that represents all errors.
|
||||
func (be *BatchError) Err() error {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
|
||||
switch len(be.errs) {
|
||||
case 0:
|
||||
return nil
|
||||
@@ -34,6 +44,9 @@ func (be *BatchError) Err() error {
|
||||
|
||||
// NotNil checks if any error inside.
|
||||
func (be *BatchError) NotNil() bool {
|
||||
be.lock.Lock()
|
||||
defer be.lock.Unlock()
|
||||
|
||||
return len(be.errs) > 0
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package errorx
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -33,7 +34,7 @@ func TestBatchErrorNilFromFunc(t *testing.T) {
|
||||
func TestBatchErrorOneError(t *testing.T) {
|
||||
var batch BatchError
|
||||
batch.Add(errors.New(err1))
|
||||
assert.NotNil(t, batch)
|
||||
assert.NotNil(t, batch.Err())
|
||||
assert.Equal(t, err1, batch.Err().Error())
|
||||
assert.True(t, batch.NotNil())
|
||||
}
|
||||
@@ -42,7 +43,26 @@ func TestBatchErrorWithErrors(t *testing.T) {
|
||||
var batch BatchError
|
||||
batch.Add(errors.New(err1))
|
||||
batch.Add(errors.New(err2))
|
||||
assert.NotNil(t, batch)
|
||||
assert.NotNil(t, batch.Err())
|
||||
assert.Equal(t, fmt.Sprintf("%s\n%s", err1, err2), batch.Err().Error())
|
||||
assert.True(t, batch.NotNil())
|
||||
}
|
||||
|
||||
func TestBatchErrorConcurrentAdd(t *testing.T) {
|
||||
const count = 10000
|
||||
var batch BatchError
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(count)
|
||||
for i := 0; i < count; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
batch.Add(errors.New(err1))
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
assert.NotNil(t, batch.Err())
|
||||
assert.Equal(t, count, len(batch.errs))
|
||||
assert.True(t, batch.NotNil())
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package fx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/errorx"
|
||||
@@ -14,9 +15,10 @@ type (
|
||||
RetryOption func(*retryOptions)
|
||||
|
||||
retryOptions struct {
|
||||
times int
|
||||
interval time.Duration
|
||||
timeout time.Duration
|
||||
times int
|
||||
interval time.Duration
|
||||
timeout time.Duration
|
||||
ignoreErrors []error
|
||||
}
|
||||
)
|
||||
|
||||
@@ -62,6 +64,11 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt
|
||||
select {
|
||||
case err := <-errChan:
|
||||
if err != nil {
|
||||
for _, ignoreErr := range options.ignoreErrors {
|
||||
if errors.Is(err, ignoreErr) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
berr.Add(err)
|
||||
} else {
|
||||
return nil
|
||||
@@ -84,19 +91,28 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt
|
||||
return berr.Err()
|
||||
}
|
||||
|
||||
// WithRetry customize a DoWithRetry call with given retry times.
|
||||
func WithRetry(times int) RetryOption {
|
||||
// WithIgnoreErrors Ignore the specified errors
|
||||
func WithIgnoreErrors(ignoreErrors []error) RetryOption {
|
||||
return func(options *retryOptions) {
|
||||
options.times = times
|
||||
options.ignoreErrors = ignoreErrors
|
||||
}
|
||||
}
|
||||
|
||||
// WithInterval customizes a DoWithRetry call with given interval.
|
||||
func WithInterval(interval time.Duration) RetryOption {
|
||||
return func(options *retryOptions) {
|
||||
options.interval = interval
|
||||
}
|
||||
}
|
||||
|
||||
// WithRetry customizes a DoWithRetry call with given retry times.
|
||||
func WithRetry(times int) RetryOption {
|
||||
return func(options *retryOptions) {
|
||||
options.times = times
|
||||
}
|
||||
}
|
||||
|
||||
// WithTimeout customizes a DoWithRetry call with given timeout.
|
||||
func WithTimeout(timeout time.Duration) RetryOption {
|
||||
return func(options *retryOptions) {
|
||||
options.timeout = timeout
|
||||
|
||||
@@ -97,6 +97,24 @@ func TestRetryWithInterval(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestRetryWithWithIgnoreErrors(t *testing.T) {
|
||||
ignoreErr1 := errors.New("ignore error1")
|
||||
ignoreErr2 := errors.New("ignore error2")
|
||||
ignoreErrs := []error{ignoreErr1, ignoreErr2}
|
||||
|
||||
assert.Nil(t, DoWithRetry(func() error {
|
||||
return ignoreErr1
|
||||
}, WithIgnoreErrors(ignoreErrs)))
|
||||
|
||||
assert.Nil(t, DoWithRetry(func() error {
|
||||
return ignoreErr2
|
||||
}, WithIgnoreErrors(ignoreErrs)))
|
||||
|
||||
assert.NotNil(t, DoWithRetry(func() error {
|
||||
return errors.New("any")
|
||||
}))
|
||||
}
|
||||
|
||||
func TestRetryCtx(t *testing.T) {
|
||||
t.Run("with timeout", func(t *testing.T) {
|
||||
assert.NotNil(t, DoWithRetryCtx(context.Background(), func(ctx context.Context, retryCount int) error {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/zeromicro/go-zero/core/collection"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/mathx"
|
||||
"github.com/zeromicro/go-zero/core/stat"
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
@@ -21,8 +22,11 @@ const (
|
||||
defaultCpuThreshold = 900
|
||||
defaultMinRt = float64(time.Second / time.Millisecond)
|
||||
// moving average hyperparameter beta for calculating requests on the fly
|
||||
flyingBeta = 0.9
|
||||
coolOffDuration = time.Second
|
||||
flyingBeta = 0.9
|
||||
coolOffDuration = time.Second
|
||||
cpuMax = 1000 // millicpu
|
||||
millisecondsPerSecond = 1000
|
||||
overloadFactorLowerBound = 0.1
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -66,7 +70,7 @@ type (
|
||||
|
||||
adaptiveShedder struct {
|
||||
cpuThreshold int64
|
||||
windows int64
|
||||
windowScale float64
|
||||
flying int64
|
||||
avgFlying float64
|
||||
avgFlyingLock syncx.SpinLock
|
||||
@@ -105,7 +109,7 @@ func NewAdaptiveShedder(opts ...ShedderOption) Shedder {
|
||||
bucketDuration := options.window / time.Duration(options.buckets)
|
||||
return &adaptiveShedder{
|
||||
cpuThreshold: options.cpuThreshold,
|
||||
windows: int64(time.Second / bucketDuration),
|
||||
windowScale: float64(time.Second) / float64(bucketDuration) / millisecondsPerSecond,
|
||||
overloadTime: syncx.NewAtomicDuration(),
|
||||
droppedRecently: syncx.NewAtomicBool(),
|
||||
passCounter: collection.NewRollingWindow(options.buckets, bucketDuration,
|
||||
@@ -136,7 +140,7 @@ func (as *adaptiveShedder) addFlying(delta int64) {
|
||||
// update avgFlying when the request is finished.
|
||||
// this strategy makes avgFlying have a little bit lag against flying, and smoother.
|
||||
// when the flying requests increase rapidly, avgFlying increase slower, accept more requests.
|
||||
// when the flying requests drop rapidly, avgFlying drop slower, accept less requests.
|
||||
// when the flying requests drop rapidly, avgFlying drop slower, accept fewer requests.
|
||||
// it makes the service to serve as more requests as possible.
|
||||
if delta < 0 {
|
||||
as.avgFlyingLock.Lock()
|
||||
@@ -149,16 +153,17 @@ func (as *adaptiveShedder) highThru() bool {
|
||||
as.avgFlyingLock.Lock()
|
||||
avgFlying := as.avgFlying
|
||||
as.avgFlyingLock.Unlock()
|
||||
maxFlight := as.maxFlight()
|
||||
return int64(avgFlying) > maxFlight && atomic.LoadInt64(&as.flying) > maxFlight
|
||||
maxFlight := as.maxFlight() * as.overloadFactor()
|
||||
return avgFlying > maxFlight && float64(atomic.LoadInt64(&as.flying)) > maxFlight
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) maxFlight() int64 {
|
||||
func (as *adaptiveShedder) maxFlight() float64 {
|
||||
// windows = buckets per second
|
||||
// maxQPS = maxPASS * windows
|
||||
// minRT = min average response time in milliseconds
|
||||
// maxQPS * minRT / milliseconds_per_second
|
||||
return int64(math.Max(1, float64(as.maxPass()*as.windows)*(as.minRt()/1e3)))
|
||||
// allowedFlying = maxQPS * minRT / milliseconds_per_second
|
||||
maxFlight := float64(as.maxPass()) * as.minRt() * as.windowScale
|
||||
return mathx.AtLeast(maxFlight, 1)
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) maxPass() int64 {
|
||||
@@ -174,6 +179,8 @@ func (as *adaptiveShedder) maxPass() int64 {
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) minRt() float64 {
|
||||
// if no requests in previous windows, return defaultMinRt,
|
||||
// its a reasonable large value to avoid dropping requests.
|
||||
result := defaultMinRt
|
||||
|
||||
as.rtCounter.Reduce(func(b *collection.Bucket) {
|
||||
@@ -190,6 +197,13 @@ func (as *adaptiveShedder) minRt() float64 {
|
||||
return result
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) overloadFactor() float64 {
|
||||
// as.cpuThreshold must be less than cpuMax
|
||||
factor := (cpuMax - float64(stat.CpuUsage())) / (cpuMax - float64(as.cpuThreshold))
|
||||
// at least accept 10% of acceptable requests even cpu is highly overloaded.
|
||||
return mathx.Between(factor, overloadFactorLowerBound, 1)
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) shouldDrop() bool {
|
||||
if as.systemOverloaded() || as.stillHot() {
|
||||
if as.highThru() {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
const (
|
||||
buckets = 10
|
||||
bucketDuration = time.Millisecond * 50
|
||||
windowFactor = 0.01
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -114,10 +115,10 @@ func TestAdaptiveShedderMaxFlight(t *testing.T) {
|
||||
shedder := &adaptiveShedder{
|
||||
passCounter: passCounter,
|
||||
rtCounter: rtCounter,
|
||||
windows: buckets,
|
||||
windowScale: windowFactor,
|
||||
droppedRecently: syncx.NewAtomicBool(),
|
||||
}
|
||||
assert.Equal(t, int64(54), shedder.maxFlight())
|
||||
assert.Equal(t, float64(54), shedder.maxFlight())
|
||||
}
|
||||
|
||||
func TestAdaptiveShedderShouldDrop(t *testing.T) {
|
||||
@@ -136,7 +137,7 @@ func TestAdaptiveShedderShouldDrop(t *testing.T) {
|
||||
shedder := &adaptiveShedder{
|
||||
passCounter: passCounter,
|
||||
rtCounter: rtCounter,
|
||||
windows: buckets,
|
||||
windowScale: windowFactor,
|
||||
overloadTime: syncx.NewAtomicDuration(),
|
||||
droppedRecently: syncx.NewAtomicBool(),
|
||||
}
|
||||
@@ -149,7 +150,8 @@ func TestAdaptiveShedderShouldDrop(t *testing.T) {
|
||||
|
||||
// cpu >= 800, inflight > maxPass
|
||||
shedder.avgFlying = 80
|
||||
shedder.flying = 50
|
||||
// because of the overloadFactor, so we need to make sure maxFlight is greater than flying
|
||||
shedder.flying = int64(shedder.maxFlight()*shedder.overloadFactor()) - 5
|
||||
assert.False(t, shedder.shouldDrop())
|
||||
|
||||
// cpu >= 800, inflight > maxPass
|
||||
@@ -190,7 +192,7 @@ func TestAdaptiveShedderStillHot(t *testing.T) {
|
||||
shedder := &adaptiveShedder{
|
||||
passCounter: passCounter,
|
||||
rtCounter: rtCounter,
|
||||
windows: buckets,
|
||||
windowScale: windowFactor,
|
||||
overloadTime: syncx.NewAtomicDuration(),
|
||||
droppedRecently: syncx.ForAtomicBool(true),
|
||||
}
|
||||
@@ -239,6 +241,30 @@ func BenchmarkAdaptiveShedder_Allow(b *testing.B) {
|
||||
b.Run("low load", bench)
|
||||
}
|
||||
|
||||
func BenchmarkMaxFlight(b *testing.B) {
|
||||
passCounter := newRollingWindow()
|
||||
rtCounter := newRollingWindow()
|
||||
for i := 0; i < 10; i++ {
|
||||
if i > 0 {
|
||||
time.Sleep(bucketDuration)
|
||||
}
|
||||
passCounter.Add(float64((i + 1) * 100))
|
||||
for j := i*10 + 1; j <= i*10+10; j++ {
|
||||
rtCounter.Add(float64(j))
|
||||
}
|
||||
}
|
||||
shedder := &adaptiveShedder{
|
||||
passCounter: passCounter,
|
||||
rtCounter: rtCounter,
|
||||
windowScale: windowFactor,
|
||||
droppedRecently: syncx.NewAtomicBool(),
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = shedder.maxFlight()
|
||||
}
|
||||
}
|
||||
|
||||
func newRollingWindow() *collection.RollingWindow {
|
||||
return collection.NewRollingWindow(buckets, bucketDuration, collection.IgnoreCurrentBucket())
|
||||
}
|
||||
|
||||
@@ -17,14 +17,13 @@ import (
|
||||
const callerDepth = 4
|
||||
|
||||
var (
|
||||
timeFormat = "2006-01-02T15:04:05.000Z07:00"
|
||||
logLevel uint32
|
||||
timeFormat = "2006-01-02T15:04:05.000Z07:00"
|
||||
encoding uint32 = jsonEncodingType
|
||||
// maxContentLength is used to truncate the log content, 0 for not truncating.
|
||||
maxContentLength uint32
|
||||
// use uint32 for atomic operations
|
||||
disableLog uint32
|
||||
disableStat uint32
|
||||
logLevel uint32
|
||||
options logOptions
|
||||
writer = new(atomicWriter)
|
||||
setupOnce sync.Once
|
||||
@@ -96,7 +95,7 @@ func Debugw(msg string, fields ...LogField) {
|
||||
|
||||
// Disable disables the logging.
|
||||
func Disable() {
|
||||
atomic.StoreUint32(&disableLog, 1)
|
||||
atomic.StoreUint32(&logLevel, disableLevel)
|
||||
writer.Store(nopWriter{})
|
||||
}
|
||||
|
||||
@@ -250,7 +249,7 @@ func SetLevel(level uint32) {
|
||||
|
||||
// SetWriter sets the logging writer. It can be used to customize the logging.
|
||||
func SetWriter(w Writer) {
|
||||
if atomic.LoadUint32(&disableLog) == 0 {
|
||||
if atomic.LoadUint32(&logLevel) != disableLevel {
|
||||
writer.Store(w)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,6 +666,7 @@ func TestDisable(t *testing.T) {
|
||||
WithMaxSize(1024)(&opt)
|
||||
assert.Nil(t, Close())
|
||||
assert.Nil(t, Close())
|
||||
assert.Equal(t, uint32(disableLevel), atomic.LoadUint32(&logLevel))
|
||||
}
|
||||
|
||||
func TestDisableStat(t *testing.T) {
|
||||
@@ -680,7 +681,7 @@ func TestDisableStat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetWriter(t *testing.T) {
|
||||
atomic.StoreUint32(&disableLog, 0)
|
||||
atomic.StoreUint32(&logLevel, 0)
|
||||
Reset()
|
||||
SetWriter(nopWriter{})
|
||||
assert.NotNil(t, writer.Load())
|
||||
|
||||
@@ -15,6 +15,8 @@ const (
|
||||
ErrorLevel
|
||||
// SevereLevel only log severe messages
|
||||
SevereLevel
|
||||
// disableLevel doesn't log any messages
|
||||
disableLevel = 0xff
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -224,11 +223,11 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
||||
switch v := mapValue.(type) {
|
||||
case fmt.Stringer:
|
||||
if err := jsonx.UnmarshalFromString(v.String(), &slice); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("fullName: `%s`, error: `%w`", fullName, err)
|
||||
}
|
||||
case string:
|
||||
if err := jsonx.UnmarshalFromString(v, &slice); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("fullName: `%s`, error: `%w`", fullName, err)
|
||||
}
|
||||
default:
|
||||
return errUnsupportedType
|
||||
@@ -250,6 +249,10 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
||||
|
||||
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
||||
baseKind reflect.Kind, value any, fullName string) error {
|
||||
if value == nil {
|
||||
return errNilSliceElement
|
||||
}
|
||||
|
||||
ithVal := slice.Index(index)
|
||||
switch v := value.(type) {
|
||||
case fmt.Stringer:
|
||||
@@ -425,6 +428,10 @@ func (u *Unmarshaler) parseOptionsWithContext(field reflect.StructField, m Value
|
||||
}
|
||||
}
|
||||
|
||||
if u.opts.fillDefault {
|
||||
return key, &options.fieldOptionsWithContext, nil
|
||||
}
|
||||
|
||||
optsWithContext, err := options.toOptionsWithContext(key, m, fullName)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
@@ -622,7 +629,12 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
|
||||
return err
|
||||
}
|
||||
|
||||
if fValue > math.MaxFloat32 {
|
||||
// if value is a pointer, we need to check overflow with the pointer's value.
|
||||
derefedValue := value
|
||||
for derefedValue.Type().Kind() == reflect.Ptr {
|
||||
derefedValue = derefedValue.Elem()
|
||||
}
|
||||
if derefedValue.CanFloat() && derefedValue.OverflowFloat(fValue) {
|
||||
return fmt.Errorf("parsing %q as float32: value out of range", v.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -976,6 +976,19 @@ func TestUnmarshalFloat32WithOverflow(t *testing.T) {
|
||||
assert.Error(t, UnmarshalKey(m, &in))
|
||||
})
|
||||
|
||||
t.Run("float32 from string less than float32", func(t *testing.T) {
|
||||
type inner struct {
|
||||
Value float32 `key:"float, string"`
|
||||
}
|
||||
|
||||
m := map[string]any{
|
||||
"float": "-1.79769313486231570814527423731704356798070e+300", // overflow
|
||||
}
|
||||
|
||||
var in inner
|
||||
assert.Error(t, UnmarshalKey(m, &in))
|
||||
})
|
||||
|
||||
t.Run("float32 from json.Number greater than float64", func(t *testing.T) {
|
||||
type inner struct {
|
||||
Value float32 `key:"float"`
|
||||
@@ -1001,6 +1014,19 @@ func TestUnmarshalFloat32WithOverflow(t *testing.T) {
|
||||
var in inner
|
||||
assert.Error(t, UnmarshalKey(m, &in))
|
||||
})
|
||||
|
||||
t.Run("float32 from json number less than float32", func(t *testing.T) {
|
||||
type inner struct {
|
||||
Value float32 `key:"float"`
|
||||
}
|
||||
|
||||
m := map[string]any{
|
||||
"float": json.Number("-1.79769313486231570814527423731704356798070e+300"), // overflow
|
||||
}
|
||||
|
||||
var in inner
|
||||
assert.Error(t, UnmarshalKey(m, &in))
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalFloat64WithOverflow(t *testing.T) {
|
||||
@@ -1303,6 +1329,47 @@ func TestUnmarshalInt64Slice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalNullableSlice(t *testing.T) {
|
||||
var v struct {
|
||||
Ages []int64 `key:"ages"`
|
||||
Slice []int8 `key:"slice"`
|
||||
}
|
||||
m := map[string]any{
|
||||
"ages": []int64{1, 2},
|
||||
"slice": `[null,2]`,
|
||||
}
|
||||
|
||||
assert.New(t).Equal(UnmarshalKey(m, &v), errNilSliceElement)
|
||||
}
|
||||
|
||||
func TestUnmarshalWithFloatPtr(t *testing.T) {
|
||||
t.Run("*float32", func(t *testing.T) {
|
||||
var v struct {
|
||||
WeightFloat32 *float32 `key:"weightFloat32,optional"`
|
||||
}
|
||||
m := map[string]any{
|
||||
"weightFloat32": json.Number("3.2"),
|
||||
}
|
||||
|
||||
if assert.NoError(t, UnmarshalKey(m, &v)) {
|
||||
assert.Equal(t, float32(3.2), *v.WeightFloat32)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("**float32", func(t *testing.T) {
|
||||
var v struct {
|
||||
WeightFloat32 **float32 `key:"weightFloat32,optional"`
|
||||
}
|
||||
m := map[string]any{
|
||||
"weightFloat32": json.Number("3.2"),
|
||||
}
|
||||
|
||||
if assert.NoError(t, UnmarshalKey(m, &v)) {
|
||||
assert.Equal(t, float32(3.2), **v.WeightFloat32)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalIntSlice(t *testing.T) {
|
||||
var v struct {
|
||||
Ages []int `key:"ages"`
|
||||
@@ -5344,6 +5411,15 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
assert.Equal(t, "c", st.C)
|
||||
})
|
||||
|
||||
t.Run("optional !", func(t *testing.T) {
|
||||
var st struct {
|
||||
A string `json:",optional"`
|
||||
B string `json:",optional=!A"`
|
||||
}
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("has value", func(t *testing.T) {
|
||||
type St struct {
|
||||
A string `json:",default=a"`
|
||||
|
||||
@@ -36,6 +36,7 @@ const (
|
||||
var (
|
||||
errUnsupportedType = errors.New("unsupported type on setting field value")
|
||||
errNumberRange = errors.New("wrong number range setting")
|
||||
errNilSliceElement = errors.New("null element for slice")
|
||||
optionsCache = make(map[string]optionsCacheValue)
|
||||
cacheLock sync.RWMutex
|
||||
structRequiredCache = make(map[reflect.Type]requiredCacheValue)
|
||||
|
||||
@@ -15,3 +15,17 @@ func TestCalcEntropy(t *testing.T) {
|
||||
}
|
||||
assert.True(t, CalcEntropy(m) > .99)
|
||||
}
|
||||
|
||||
func TestCalcEmptyEntropy(t *testing.T) {
|
||||
m := make(map[any]int)
|
||||
assert.Equal(t, float64(1), CalcEntropy(m))
|
||||
}
|
||||
|
||||
func TestCalcDiffEntropy(t *testing.T) {
|
||||
const total = 1000
|
||||
m := make(map[any]int, total)
|
||||
for i := 0; i < total; i++ {
|
||||
m[i] = i
|
||||
}
|
||||
assert.True(t, CalcEntropy(m) < .99)
|
||||
}
|
||||
|
||||
34
core/mathx/range.go
Normal file
34
core/mathx/range.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package mathx
|
||||
|
||||
type numerical interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
// AtLeast returns the greater of x or lower.
|
||||
func AtLeast[T numerical](x, lower T) T {
|
||||
if x < lower {
|
||||
return lower
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// AtMost returns the smaller of x or upper.
|
||||
func AtMost[T numerical](x, upper T) T {
|
||||
if x > upper {
|
||||
return upper
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// Between returns the value of x clamped to the range [lower, upper].
|
||||
func Between[T numerical](x, lower, upper T) T {
|
||||
if x < lower {
|
||||
return lower
|
||||
}
|
||||
if x > upper {
|
||||
return upper
|
||||
}
|
||||
return x
|
||||
}
|
||||
513
core/mathx/range_test.go
Normal file
513
core/mathx/range_test.go
Normal file
@@ -0,0 +1,513 @@
|
||||
package mathx
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAtLeast(t *testing.T) {
|
||||
t.Run("test int", func(t *testing.T) {
|
||||
if got := AtLeast(10, 5); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(3, 5); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(5, 5); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int8", func(t *testing.T) {
|
||||
if got := AtLeast(int8(10), int8(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(int8(3), int8(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(int8(5), int8(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int16", func(t *testing.T) {
|
||||
if got := AtLeast(int16(10), int16(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(int16(3), int16(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(int16(5), int16(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int32", func(t *testing.T) {
|
||||
if got := AtLeast(int32(10), int32(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(int32(3), int32(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(int32(5), int32(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int64", func(t *testing.T) {
|
||||
if got := AtLeast(int64(10), int64(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(int64(3), int64(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(int64(5), int64(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint", func(t *testing.T) {
|
||||
if got := AtLeast(uint(10), uint(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(uint(3), uint(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(uint(5), uint(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint8", func(t *testing.T) {
|
||||
if got := AtLeast(uint8(10), uint8(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(uint8(3), uint8(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(uint8(5), uint8(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint16", func(t *testing.T) {
|
||||
if got := AtLeast(uint16(10), uint16(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(uint16(3), uint16(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(uint16(5), uint16(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint32", func(t *testing.T) {
|
||||
if got := AtLeast(uint32(10), uint32(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(uint32(3), uint32(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(uint32(5), uint32(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint64", func(t *testing.T) {
|
||||
if got := AtLeast(uint64(10), uint64(5)); got != 10 {
|
||||
t.Errorf("AtLeast() = %v, want 10", got)
|
||||
}
|
||||
if got := AtLeast(uint64(3), uint64(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
if got := AtLeast(uint64(5), uint64(5)); got != 5 {
|
||||
t.Errorf("AtLeast() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float32", func(t *testing.T) {
|
||||
if got := AtLeast(float32(10.0), float32(5.0)); got != 10.0 {
|
||||
t.Errorf("AtLeast() = %v, want 10.0", got)
|
||||
}
|
||||
if got := AtLeast(float32(3.0), float32(5.0)); got != 5.0 {
|
||||
t.Errorf("AtLeast() = %v, want 5.0", got)
|
||||
}
|
||||
if got := AtLeast(float32(5.0), float32(5.0)); got != 5.0 {
|
||||
t.Errorf("AtLeast() = %v, want 5.0", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float64", func(t *testing.T) {
|
||||
if got := AtLeast(10.0, 5.0); got != 10.0 {
|
||||
t.Errorf("AtLeast() = %v, want 10.0", got)
|
||||
}
|
||||
if got := AtLeast(3.0, 5.0); got != 5.0 {
|
||||
t.Errorf("AtLeast() = %v, want 5.0", got)
|
||||
}
|
||||
if got := AtLeast(5.0, 5.0); got != 5.0 {
|
||||
t.Errorf("AtLeast() = %v, want 5.0", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAtMost(t *testing.T) {
|
||||
t.Run("test int", func(t *testing.T) {
|
||||
if got := AtMost(10, 5); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(3, 5); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(5, 5); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int8", func(t *testing.T) {
|
||||
if got := AtMost(int8(10), int8(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(int8(3), int8(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(int8(5), int8(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int16", func(t *testing.T) {
|
||||
if got := AtMost(int16(10), int16(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(int16(3), int16(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(int16(5), int16(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int32", func(t *testing.T) {
|
||||
if got := AtMost(int32(10), int32(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(int32(3), int32(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(int32(5), int32(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int64", func(t *testing.T) {
|
||||
if got := AtMost(int64(10), int64(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(int64(3), int64(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(int64(5), int64(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint", func(t *testing.T) {
|
||||
if got := AtMost(uint(10), uint(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(uint(3), uint(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(uint(5), uint(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint8", func(t *testing.T) {
|
||||
if got := AtMost(uint8(10), uint8(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(uint8(3), uint8(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(uint8(5), uint8(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint16", func(t *testing.T) {
|
||||
if got := AtMost(uint16(10), uint16(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(uint16(3), uint16(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(uint16(5), uint16(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint32", func(t *testing.T) {
|
||||
if got := AtMost(uint32(10), uint32(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(uint32(3), uint32(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(uint32(5), uint32(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint64", func(t *testing.T) {
|
||||
if got := AtMost(uint64(10), uint64(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
if got := AtMost(uint64(3), uint64(5)); got != 3 {
|
||||
t.Errorf("AtMost() = %v, want 3", got)
|
||||
}
|
||||
if got := AtMost(uint64(5), uint64(5)); got != 5 {
|
||||
t.Errorf("AtMost() = %v, want 5", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float32", func(t *testing.T) {
|
||||
if got := AtMost(float32(10.0), float32(5.0)); got != 5.0 {
|
||||
t.Errorf("AtMost() = %v, want 5.0", got)
|
||||
}
|
||||
if got := AtMost(float32(3.0), float32(5.0)); got != 3.0 {
|
||||
t.Errorf("AtMost() = %v, want 3.0", got)
|
||||
}
|
||||
if got := AtMost(float32(5.0), float32(5.0)); got != 5.0 {
|
||||
t.Errorf("AtMost() = %v, want 5.0", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float64", func(t *testing.T) {
|
||||
if got := AtMost(10.0, 5.0); got != 5.0 {
|
||||
t.Errorf("AtMost() = %v, want 5.0", got)
|
||||
}
|
||||
if got := AtMost(3.0, 5.0); got != 3.0 {
|
||||
t.Errorf("AtMost() = %v, want 3.0", got)
|
||||
}
|
||||
if got := AtMost(5.0, 5.0); got != 5.0 {
|
||||
t.Errorf("AtMost() = %v, want 5.0", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBetween(t *testing.T) {
|
||||
t.Run("test int", func(t *testing.T) {
|
||||
if got := Between(10, 5, 15); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(3, 5, 15); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(20, 5, 15); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(5, 5, 15); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(15, 5, 15); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int8", func(t *testing.T) {
|
||||
if got := Between(int8(10), int8(5), int8(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(int8(3), int8(5), int8(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int8(20), int8(5), int8(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(int8(5), int8(5), int8(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int8(15), int8(5), int8(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int16", func(t *testing.T) {
|
||||
if got := Between(int16(10), int16(5), int16(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(int16(3), int16(5), int16(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int16(20), int16(5), int16(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(int16(5), int16(5), int16(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int16(15), int16(5), int16(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int32", func(t *testing.T) {
|
||||
if got := Between(int32(10), int32(5), int32(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(int32(3), int32(5), int32(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int32(20), int32(5), int32(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(int32(5), int32(5), int32(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int32(15), int32(5), int32(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test int64", func(t *testing.T) {
|
||||
if got := Between(int64(10), int64(5), int64(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(int64(3), int64(5), int64(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int64(20), int64(5), int64(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(int64(5), int64(5), int64(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(int64(15), int64(5), int64(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint", func(t *testing.T) {
|
||||
if got := Between(uint(10), uint(5), uint(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(uint(3), uint(5), uint(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint(20), uint(5), uint(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(uint(5), uint(5), uint(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint(15), uint(5), uint(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint8", func(t *testing.T) {
|
||||
if got := Between(uint8(10), uint8(5), uint8(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(uint8(3), uint8(5), uint8(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint8(20), uint8(5), uint8(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(uint8(5), uint8(5), uint8(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint8(15), uint8(5), uint8(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint16", func(t *testing.T) {
|
||||
if got := Between(uint16(10), uint16(5), uint16(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(uint16(3), uint16(5), uint16(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint16(20), uint16(5), uint16(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(uint16(5), uint16(5), uint16(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint16(15), uint16(5), uint16(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint32", func(t *testing.T) {
|
||||
if got := Between(uint32(10), uint32(5), uint32(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(uint32(3), uint32(5), uint32(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint32(20), uint32(5), uint32(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(uint32(5), uint32(5), uint32(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint32(15), uint32(5), uint32(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test uint64", func(t *testing.T) {
|
||||
if got := Between(uint64(10), uint64(5), uint64(15)); got != 10 {
|
||||
t.Errorf("Between() = %v, want 10", got)
|
||||
}
|
||||
if got := Between(uint64(3), uint64(5), uint64(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint64(20), uint64(5), uint64(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
if got := Between(uint64(5), uint64(5), uint64(15)); got != 5 {
|
||||
t.Errorf("Between() = %v, want 5", got)
|
||||
}
|
||||
if got := Between(uint64(15), uint64(5), uint64(15)); got != 15 {
|
||||
t.Errorf("Between() = %v, want 15", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float32", func(t *testing.T) {
|
||||
if got := Between(float32(10.0), float32(5.0), float32(15.0)); got != 10.0 {
|
||||
t.Errorf("Between() = %v, want 10.0", got)
|
||||
}
|
||||
if got := Between(float32(3.0), float32(5.0), float32(15.0)); got != 5.0 {
|
||||
t.Errorf("Between() = %v, want 5.0", got)
|
||||
}
|
||||
if got := Between(float32(20.0), float32(5.0), float32(15.0)); got != 15.0 {
|
||||
t.Errorf("Between() = %v, want 15.0", got)
|
||||
}
|
||||
if got := Between(float32(5.0), float32(5.0), float32(15.0)); got != 5.0 {
|
||||
t.Errorf("Between() = %v, want 5.0", got)
|
||||
}
|
||||
if got := Between(float32(15.0), float32(5.0), float32(15.0)); got != 15.0 {
|
||||
t.Errorf("Between() = %v, want 15.0", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("test float64", func(t *testing.T) {
|
||||
if got := Between(10.0, 5.0, 15.0); got != 10.0 {
|
||||
t.Errorf("Between() = %v, want 10.0", got)
|
||||
}
|
||||
if got := Between(3.0, 5.0, 15.0); got != 5.0 {
|
||||
t.Errorf("Between() = %v, want 5.0", got)
|
||||
}
|
||||
if got := Between(20.0, 5.0, 15.0); got != 15.0 {
|
||||
t.Errorf("Between() = %v, want 15.0", got)
|
||||
}
|
||||
if got := Between(5.0, 5.0, 15.0); got != 5.0 {
|
||||
t.Errorf("Between() = %v, want 5.0", got)
|
||||
}
|
||||
if got := Between(15.0, 5.0, 15.0); got != 15.0 {
|
||||
t.Errorf("Between() = %v, want 15.0", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func FuzzMapReduce(f *testing.F) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
f.Add(int64(10), runtime.NumCPU())
|
||||
f.Fuzz(func(t *testing.T, n int64, workers int) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
// If Fuzz stuck, we don't know why, because it only returns hung or unexpected,
|
||||
// so we need to simulate the fuzz test in test mode.
|
||||
func TestMapReduceRandom(t *testing.T) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
const (
|
||||
times = 10000
|
||||
|
||||
@@ -2,6 +2,7 @@ package internal
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
|
||||
const (
|
||||
cgroupDir = "/sys/fs/cgroup"
|
||||
cpuMaxFile = cgroupDir + "/cpu.max"
|
||||
cpuStatFile = cgroupDir + "/cpu.stat"
|
||||
cpusetFile = cgroupDir + "/cpuset.cpus.effective"
|
||||
)
|
||||
@@ -30,10 +32,9 @@ var (
|
||||
)
|
||||
|
||||
type cgroup interface {
|
||||
cpuQuotaUs() (int64, error)
|
||||
cpuPeriodUs() (uint64, error)
|
||||
cpus() ([]uint64, error)
|
||||
usageAllCpus() (uint64, error)
|
||||
cpuQuota() (float64, error)
|
||||
cpuUsage() (uint64, error)
|
||||
effectiveCpus() (int, error)
|
||||
}
|
||||
|
||||
func currentCgroup() (cgroup, error) {
|
||||
@@ -48,13 +49,22 @@ type cgroupV1 struct {
|
||||
cgroups map[string]string
|
||||
}
|
||||
|
||||
func (c *cgroupV1) cpuQuotaUs() (int64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpu"], "cpu.cfs_quota_us"))
|
||||
func (c *cgroupV1) cpuQuota() (float64, error) {
|
||||
quotaUs, err := c.cpuQuotaUs()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(data, 10, 64)
|
||||
if quotaUs == -1 {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
periodUs, err := c.cpuPeriodUs()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return float64(quotaUs) / float64(periodUs), nil
|
||||
}
|
||||
|
||||
func (c *cgroupV1) cpuPeriodUs() (uint64, error) {
|
||||
@@ -66,16 +76,16 @@ func (c *cgroupV1) cpuPeriodUs() (uint64, error) {
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
func (c *cgroupV1) cpus() ([]uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuset"], "cpuset.cpus"))
|
||||
func (c *cgroupV1) cpuQuotaUs() (int64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpu"], "cpu.cfs_quota_us"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUints(data)
|
||||
return strconv.ParseInt(data, 10, 64)
|
||||
}
|
||||
|
||||
func (c *cgroupV1) usageAllCpus() (uint64, error) {
|
||||
func (c *cgroupV1) cpuUsage() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuacct"], "cpuacct.usage"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -84,38 +94,53 @@ func (c *cgroupV1) usageAllCpus() (uint64, error) {
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
func (c *cgroupV1) effectiveCpus() (int, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuset"], "cpuset.cpus"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
cpus, err := parseUints(data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return len(cpus), nil
|
||||
}
|
||||
|
||||
type cgroupV2 struct {
|
||||
cgroups map[string]string
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpuQuotaUs() (int64, error) {
|
||||
data, err := iox.ReadText(path.Join(cgroupDir, "cpu.cfs_quota_us"))
|
||||
func (c *cgroupV2) cpuQuota() (float64, error) {
|
||||
data, err := iox.ReadText(cpuMaxFile)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(data, 10, 64)
|
||||
}
|
||||
fields := strings.Fields(data)
|
||||
if len(fields) != 2 {
|
||||
return 0, fmt.Errorf("cgroup: bad /sys/fs/cgroup/cpu.max file: %s", data)
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpuPeriodUs() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(cgroupDir, "cpu.cfs_period_us"))
|
||||
if fields[0] == "max" {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
quotaUs, err := strconv.ParseInt(fields[0], 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpus() ([]uint64, error) {
|
||||
data, err := iox.ReadText(cpusetFile)
|
||||
periodUs, err := strconv.ParseUint(fields[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUints(data)
|
||||
return float64(quotaUs) / float64(periodUs), nil
|
||||
}
|
||||
|
||||
func (c *cgroupV2) usageAllCpus() (uint64, error) {
|
||||
func (c *cgroupV2) cpuUsage() (uint64, error) {
|
||||
usec, err := parseUint(c.cgroups["usage_usec"])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -124,6 +149,20 @@ func (c *cgroupV2) usageAllCpus() (uint64, error) {
|
||||
return usec * uint64(time.Microsecond), nil
|
||||
}
|
||||
|
||||
func (c *cgroupV2) effectiveCpus() (int, error) {
|
||||
data, err := iox.ReadText(cpusetFile)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
cpus, err := parseUints(data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return len(cpus), nil
|
||||
}
|
||||
|
||||
func currentCgroupV1() (cgroup, error) {
|
||||
cgroupFile := fmt.Sprintf("/proc/%d/cgroup", os.Getpid())
|
||||
lines, err := iox.ReadTextLines(cgroupFile, iox.WithoutBlank())
|
||||
@@ -200,7 +239,7 @@ func isCgroup2UnifiedMode() bool {
|
||||
func parseUint(s string) (uint64, error) {
|
||||
v, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
if err.(*strconv.NumError).Err == strconv.ErrRange {
|
||||
if errors.Is(err, strconv.ErrRange) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -225,21 +264,21 @@ func parseUints(val string) ([]uint64, error) {
|
||||
for _, r := range cols {
|
||||
if strings.Contains(r, "-") {
|
||||
fields := strings.SplitN(r, "-", 2)
|
||||
min, err := parseUint(fields[0])
|
||||
minimum, err := parseUint(fields[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cgroup: bad int list format: %s", val)
|
||||
}
|
||||
|
||||
max, err := parseUint(fields[1])
|
||||
maximum, err := parseUint(fields[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cgroup: bad int list format: %s", val)
|
||||
}
|
||||
|
||||
if max < min {
|
||||
if maximum < minimum {
|
||||
return nil, fmt.Errorf("cgroup: bad int list format: %s", val)
|
||||
}
|
||||
|
||||
for i := min; i <= max; i++ {
|
||||
for i := minimum; i <= maximum; i++ {
|
||||
if _, ok := ints[i]; !ok {
|
||||
ints[i] = lang.Placeholder
|
||||
sets = append(sets, i)
|
||||
|
||||
@@ -12,18 +12,29 @@ func TestRunningInUserNS(t *testing.T) {
|
||||
assert.False(t, runningInUserNS())
|
||||
}
|
||||
|
||||
func TestCgroupV1(t *testing.T) {
|
||||
if isCgroup2UnifiedMode() {
|
||||
func TestCgroups(t *testing.T) {
|
||||
// test cgroup legacy(v1) & hybrid
|
||||
if !isCgroup2UnifiedMode() {
|
||||
cg, err := currentCgroupV1()
|
||||
assert.NoError(t, err)
|
||||
_, err = cg.cpus()
|
||||
assert.Error(t, err)
|
||||
_, err = cg.cpuPeriodUs()
|
||||
assert.Error(t, err)
|
||||
_, err = cg.cpuQuotaUs()
|
||||
assert.Error(t, err)
|
||||
_, err = cg.usageAllCpus()
|
||||
_, err = cg.effectiveCpus()
|
||||
assert.NoError(t, err)
|
||||
_, err = cg.cpuQuota()
|
||||
assert.NoError(t, err)
|
||||
_, err = cg.cpuUsage()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// test cgroup v2
|
||||
if isCgroup2UnifiedMode() {
|
||||
cg, err := currentCgroupV2()
|
||||
assert.NoError(t, err)
|
||||
_, err = cg.effectiveCpus()
|
||||
assert.NoError(t, err)
|
||||
_, err = cg.cpuQuota()
|
||||
assert.Error(t, err)
|
||||
_, err = cg.cpuUsage()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,60 +14,28 @@ import (
|
||||
const (
|
||||
cpuTicks = 100
|
||||
cpuFields = 8
|
||||
cpuMax = 1000
|
||||
statFile = "/proc/stat"
|
||||
)
|
||||
|
||||
var (
|
||||
preSystem uint64
|
||||
preTotal uint64
|
||||
quota float64
|
||||
limit float64
|
||||
cores uint64
|
||||
noCgroup bool
|
||||
initOnce sync.Once
|
||||
)
|
||||
|
||||
// if /proc not present, ignore the cpu calculation, like wsl linux
|
||||
func initialize() {
|
||||
cpus, err := cpuSets()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
cores = uint64(len(cpus))
|
||||
quota = float64(len(cpus))
|
||||
cq, err := cpuQuota()
|
||||
if err == nil {
|
||||
if cq != -1 {
|
||||
period, err := cpuPeriod()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
limit := float64(cq) / float64(period)
|
||||
if limit < quota {
|
||||
quota = limit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preSystem, err = systemCpuUsage()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
preTotal, err = totalCpuUsage()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// RefreshCpu refreshes cpu usage and returns.
|
||||
func RefreshCpu() uint64 {
|
||||
initOnce.Do(initialize)
|
||||
initializeOnce()
|
||||
|
||||
total, err := totalCpuUsage()
|
||||
if noCgroup {
|
||||
return 0
|
||||
}
|
||||
|
||||
total, err := cpuUsage()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -81,7 +49,10 @@ func RefreshCpu() uint64 {
|
||||
cpuDelta := total - preTotal
|
||||
systemDelta := system - preSystem
|
||||
if cpuDelta > 0 && systemDelta > 0 {
|
||||
usage = uint64(float64(cpuDelta*cores*1e3) / (float64(systemDelta) * quota))
|
||||
usage = uint64(float64(cpuDelta*cores*cpuMax) / (float64(systemDelta) * limit))
|
||||
if usage > cpuMax {
|
||||
usage = cpuMax
|
||||
}
|
||||
}
|
||||
preSystem = system
|
||||
preTotal = total
|
||||
@@ -89,35 +60,76 @@ func RefreshCpu() uint64 {
|
||||
return usage
|
||||
}
|
||||
|
||||
func cpuQuota() (int64, error) {
|
||||
func cpuQuota() (float64, error) {
|
||||
cg, err := currentCgroup()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cg.cpuQuotaUs()
|
||||
return cg.cpuQuota()
|
||||
}
|
||||
|
||||
func cpuPeriod() (uint64, error) {
|
||||
func cpuUsage() (uint64, error) {
|
||||
cg, err := currentCgroup()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cg.cpuPeriodUs()
|
||||
return cg.cpuUsage()
|
||||
}
|
||||
|
||||
func cpuSets() ([]uint64, error) {
|
||||
func effectiveCpus() (int, error) {
|
||||
cg, err := currentCgroup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cg.cpus()
|
||||
return cg.effectiveCpus()
|
||||
}
|
||||
|
||||
// if /proc not present, ignore the cpu calculation, like wsl linux
|
||||
func initialize() error {
|
||||
cpus, err := effectiveCpus()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cores = uint64(cpus)
|
||||
limit = float64(cpus)
|
||||
quota, err := cpuQuota()
|
||||
if err == nil && quota > 0 {
|
||||
if quota < limit {
|
||||
limit = quota
|
||||
}
|
||||
}
|
||||
|
||||
preSystem, err = systemCpuUsage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
preTotal, err = cpuUsage()
|
||||
return err
|
||||
}
|
||||
|
||||
func initializeOnce() {
|
||||
initOnce.Do(func() {
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
noCgroup = true
|
||||
logx.Error(p)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := initialize(); err != nil {
|
||||
noCgroup = true
|
||||
logx.Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func systemCpuUsage() (uint64, error) {
|
||||
lines, err := iox.ReadTextLines("/proc/stat", iox.WithoutBlank())
|
||||
lines, err := iox.ReadTextLines(statFile, iox.WithoutBlank())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -145,12 +157,3 @@ func systemCpuUsage() (uint64, error) {
|
||||
|
||||
return 0, errors.New("bad stats format")
|
||||
}
|
||||
|
||||
func totalCpuUsage() (usage uint64, err error) {
|
||||
var cg cgroup
|
||||
if cg, err = currentCgroup(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return cg.usageAllCpus()
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package stat
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/logx/logtest"
|
||||
)
|
||||
|
||||
func TestMetrics(t *testing.T) {
|
||||
@@ -30,6 +32,34 @@ func TestMetrics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopDurationWithEmpty(t *testing.T) {
|
||||
assert.Equal(t, float32(0), getTopDuration(nil))
|
||||
assert.Equal(t, float32(0), getTopDuration([]Task{}))
|
||||
}
|
||||
|
||||
func TestLogAndReport(t *testing.T) {
|
||||
buf := logtest.NewCollector(t)
|
||||
old := logEnabled.True()
|
||||
logEnabled.Set(true)
|
||||
t.Cleanup(func() {
|
||||
logEnabled.Set(old)
|
||||
})
|
||||
|
||||
log(&StatReport{})
|
||||
assert.NotEmpty(t, buf.String())
|
||||
|
||||
writerLock.Lock()
|
||||
writer := reportWriter
|
||||
writerLock.Unlock()
|
||||
buf = logtest.NewCollector(t)
|
||||
t.Cleanup(func() {
|
||||
SetReportWriter(writer)
|
||||
})
|
||||
SetReportWriter(&badWriter{})
|
||||
writeReport(&StatReport{})
|
||||
assert.NotEmpty(t, buf.String())
|
||||
}
|
||||
|
||||
type mockedWriter struct {
|
||||
report *StatReport
|
||||
}
|
||||
@@ -38,3 +68,9 @@ func (m *mockedWriter) Write(report *StatReport) error {
|
||||
m.report = report
|
||||
return nil
|
||||
}
|
||||
|
||||
type badWriter struct{}
|
||||
|
||||
func (b *badWriter) Write(report *StatReport) error {
|
||||
return errors.New("bad")
|
||||
}
|
||||
|
||||
@@ -603,11 +603,11 @@ func (d *dropBreaker) DoWithAcceptable(_ func() error, _ breaker.Acceptable) err
|
||||
return errDummy
|
||||
}
|
||||
|
||||
func (d *dropBreaker) DoWithFallback(_ func() error, _ func(err error) error) error {
|
||||
func (d *dropBreaker) DoWithFallback(_ func() error, _ breaker.Fallback) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *dropBreaker) DoWithFallbackAcceptable(_ func() error, _ func(err error) error,
|
||||
func (d *dropBreaker) DoWithFallbackAcceptable(_ func() error, _ breaker.Fallback,
|
||||
_ breaker.Acceptable) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package mon
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
mopt "go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
@@ -16,10 +19,17 @@ var (
|
||||
)
|
||||
|
||||
type (
|
||||
options = mopt.ClientOptions
|
||||
|
||||
// Option defines the method to customize a mongo model.
|
||||
Option func(opts *options)
|
||||
|
||||
// TypeCodec is a struct that stores specific type Encoder/Decoder.
|
||||
TypeCodec struct {
|
||||
ValueType reflect.Type
|
||||
Encoder bsoncodec.ValueEncoder
|
||||
Decoder bsoncodec.ValueDecoder
|
||||
}
|
||||
|
||||
options = mopt.ClientOptions
|
||||
)
|
||||
|
||||
// DisableLog disables logging of mongo commands, includes info and slow logs.
|
||||
@@ -38,15 +48,27 @@ func SetSlowThreshold(threshold time.Duration) {
|
||||
slowThreshold.Set(threshold)
|
||||
}
|
||||
|
||||
func defaultTimeoutOption() Option {
|
||||
return func(opts *options) {
|
||||
opts.SetTimeout(defaultTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// WithTimeout set the mon client operation timeout.
|
||||
func WithTimeout(timeout time.Duration) Option {
|
||||
return func(opts *options) {
|
||||
opts.SetTimeout(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
// WithTypeCodec registers TypeCodecs to convert custom types.
|
||||
func WithTypeCodec(typeCodecs ...TypeCodec) Option {
|
||||
return func(opts *options) {
|
||||
registry := bson.NewRegistry()
|
||||
for _, v := range typeCodecs {
|
||||
registry.RegisterTypeEncoder(v.ValueType, v.Encoder)
|
||||
registry.RegisterTypeDecoder(v.ValueType, v.Decoder)
|
||||
}
|
||||
opts.SetRegistry(registry)
|
||||
}
|
||||
}
|
||||
|
||||
func defaultTimeoutOption() Option {
|
||||
return func(opts *options) {
|
||||
opts.SetTimeout(defaultTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package mon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
mopt "go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
@@ -51,3 +55,56 @@ func TestDisableInfoLog(t *testing.T) {
|
||||
assert.False(t, logMon.True())
|
||||
assert.True(t, logSlowMon.True())
|
||||
}
|
||||
|
||||
func TestWithRegistryForTimestampRegisterType(t *testing.T) {
|
||||
opts := mopt.Client()
|
||||
|
||||
// mongoDateTimeEncoder allow user convert time.Time to primitive.DateTime.
|
||||
var mongoDateTimeEncoder bsoncodec.ValueEncoderFunc = func(ect bsoncodec.EncodeContext, w bsonrw.ValueWriter, value reflect.Value) error {
|
||||
// Use reflect, determine if it can be converted to time.Time.
|
||||
dec, ok := value.Interface().(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("value %v to encode is not of type time.Time", value)
|
||||
}
|
||||
return w.WriteDateTime(dec.Unix())
|
||||
}
|
||||
|
||||
// mongoDateTimeEncoder allow user convert primitive.DateTime to time.Time.
|
||||
var mongoDateTimeDecoder bsoncodec.ValueDecoderFunc = func(ect bsoncodec.DecodeContext, r bsonrw.ValueReader, value reflect.Value) error {
|
||||
primTime, err := r.ReadDateTime()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading primitive.DateTime from ValueReader: %v", err)
|
||||
}
|
||||
value.Set(reflect.ValueOf(time.Unix(primTime, 0)))
|
||||
return nil
|
||||
}
|
||||
|
||||
codecs := []TypeCodec{
|
||||
{
|
||||
ValueType: reflect.TypeOf(time.Time{}),
|
||||
Encoder: mongoDateTimeEncoder,
|
||||
Decoder: mongoDateTimeDecoder,
|
||||
},
|
||||
}
|
||||
WithTypeCodec(codecs...)(opts)
|
||||
|
||||
for _, v := range codecs {
|
||||
// Validate Encoder
|
||||
enc, err := opts.Registry.LookupEncoder(v.ValueType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if assert.ObjectsAreEqual(v.Encoder, enc) {
|
||||
t.Errorf("Encoder got from Registry: %v, but want: %v", enc, v.Encoder)
|
||||
}
|
||||
|
||||
// Validate Decoder
|
||||
dec, err := opts.Registry.LookupDecoder(v.ValueType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if assert.ObjectsAreEqual(v.Decoder, dec) {
|
||||
t.Errorf("Decoder got from Registry: %v, but want: %v", dec, v.Decoder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/errorx"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/mapping"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
@@ -23,112 +23,84 @@ import (
|
||||
const spanName = "redis"
|
||||
|
||||
var (
|
||||
startTimeKey = contextKey("startTime")
|
||||
durationHook = hook{}
|
||||
redisCmdsAttributeKey = attribute.Key("redis.cmds")
|
||||
)
|
||||
|
||||
type (
|
||||
contextKey string
|
||||
hook struct{}
|
||||
)
|
||||
type hook struct{}
|
||||
|
||||
func (h hook) BeforeProcess(ctx context.Context, cmd red.Cmder) (context.Context, error) {
|
||||
return h.startSpan(context.WithValue(ctx, startTimeKey, timex.Now()), cmd), nil
|
||||
func (h hook) DialHook(next red.DialHook) red.DialHook {
|
||||
return next
|
||||
}
|
||||
|
||||
func (h hook) AfterProcess(ctx context.Context, cmd red.Cmder) error {
|
||||
err := cmd.Err()
|
||||
h.endSpan(ctx, err)
|
||||
func (h hook) ProcessHook(next red.ProcessHook) red.ProcessHook {
|
||||
return func(ctx context.Context, cmd red.Cmder) error {
|
||||
start := timex.Now()
|
||||
ctx, endSpan := h.startSpan(ctx, cmd)
|
||||
|
||||
val := ctx.Value(startTimeKey)
|
||||
if val == nil {
|
||||
return nil
|
||||
}
|
||||
err := next(ctx, cmd)
|
||||
|
||||
start, ok := val.(time.Duration)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
endSpan(err)
|
||||
duration := timex.Since(start)
|
||||
|
||||
duration := timex.Since(start)
|
||||
if duration > slowThreshold.Load() {
|
||||
logDuration(ctx, []red.Cmder{cmd}, duration)
|
||||
metricSlowCount.Inc(cmd.Name())
|
||||
}
|
||||
|
||||
metricReqDur.ObserveFloat(float64(duration)/float64(time.Millisecond), cmd.Name())
|
||||
if msg := formatError(err); len(msg) > 0 {
|
||||
metricReqErr.Inc(cmd.Name(), msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h hook) BeforeProcessPipeline(ctx context.Context, cmds []red.Cmder) (context.Context, error) {
|
||||
if len(cmds) == 0 {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
return h.startSpan(context.WithValue(ctx, startTimeKey, timex.Now()), cmds...), nil
|
||||
}
|
||||
|
||||
func (h hook) AfterProcessPipeline(ctx context.Context, cmds []red.Cmder) error {
|
||||
if len(cmds) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
batchError := errorx.BatchError{}
|
||||
for _, cmd := range cmds {
|
||||
err := cmd.Err()
|
||||
if err == nil {
|
||||
continue
|
||||
if duration > slowThreshold.Load() {
|
||||
logDuration(ctx, []red.Cmder{cmd}, duration)
|
||||
metricSlowCount.Inc(cmd.Name())
|
||||
}
|
||||
|
||||
batchError.Add(err)
|
||||
}
|
||||
h.endSpan(ctx, batchError.Err())
|
||||
metricReqDur.Observe(duration.Milliseconds(), cmd.Name())
|
||||
if msg := formatError(err); len(msg) > 0 {
|
||||
metricReqErr.Inc(cmd.Name(), msg)
|
||||
}
|
||||
|
||||
val := ctx.Value(startTimeKey)
|
||||
if val == nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
start, ok := val.(time.Duration)
|
||||
if !ok {
|
||||
return nil
|
||||
func (h hook) ProcessPipelineHook(next red.ProcessPipelineHook) red.ProcessPipelineHook {
|
||||
return func(ctx context.Context, cmds []red.Cmder) error {
|
||||
if len(cmds) == 0 {
|
||||
return next(ctx, cmds)
|
||||
}
|
||||
|
||||
start := timex.Now()
|
||||
ctx, endSpan := h.startSpan(ctx, cmds...)
|
||||
|
||||
err := next(ctx, cmds)
|
||||
|
||||
endSpan(err)
|
||||
duration := timex.Since(start)
|
||||
if duration > slowThreshold.Load()*time.Duration(len(cmds)) {
|
||||
logDuration(ctx, cmds, duration)
|
||||
}
|
||||
|
||||
metricReqDur.Observe(duration.Milliseconds(), "Pipeline")
|
||||
if msg := formatError(err); len(msg) > 0 {
|
||||
metricReqErr.Inc("Pipeline", msg)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
duration := timex.Since(start)
|
||||
if duration > slowThreshold.Load()*time.Duration(len(cmds)) {
|
||||
logDuration(ctx, cmds, duration)
|
||||
}
|
||||
|
||||
metricReqDur.Observe(duration.Milliseconds(), "Pipeline")
|
||||
if msg := formatError(batchError.Err()); len(msg) > 0 {
|
||||
metricReqErr.Inc("Pipeline", msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatError(err error) string {
|
||||
if err == nil || err == red.Nil {
|
||||
if err == nil || errors.Is(err, red.Nil) {
|
||||
return ""
|
||||
}
|
||||
|
||||
opErr, ok := err.(*net.OpError)
|
||||
var opErr *net.OpError
|
||||
ok := errors.As(err, &opErr)
|
||||
if ok && opErr.Timeout() {
|
||||
return "timeout"
|
||||
}
|
||||
|
||||
switch err {
|
||||
case io.EOF:
|
||||
switch {
|
||||
case err == io.EOF:
|
||||
return "eof"
|
||||
case context.DeadlineExceeded:
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return "context deadline"
|
||||
case breaker.ErrServiceUnavailable:
|
||||
return "breaker"
|
||||
case errors.Is(err, breaker.ErrServiceUnavailable):
|
||||
return "breaker open"
|
||||
default:
|
||||
return "unexpected error"
|
||||
}
|
||||
@@ -152,7 +124,7 @@ func logDuration(ctx context.Context, cmds []red.Cmder, duration time.Duration)
|
||||
logx.WithContext(ctx).WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
|
||||
}
|
||||
|
||||
func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) context.Context {
|
||||
func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) (context.Context, func(err error)) {
|
||||
tracer := trace.TracerFromContext(ctx)
|
||||
|
||||
ctx, span := tracer.Start(ctx,
|
||||
@@ -166,18 +138,15 @@ func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) context.Context
|
||||
}
|
||||
span.SetAttributes(redisCmdsAttributeKey.StringSlice(cmdStrs))
|
||||
|
||||
return ctx
|
||||
}
|
||||
return ctx, func(err error) {
|
||||
defer span.End()
|
||||
|
||||
func (h hook) endSpan(ctx context.Context, err error) {
|
||||
span := oteltrace.SpanFromContext(ctx)
|
||||
defer span.End()
|
||||
if err == nil || errors.Is(err, red.Nil) {
|
||||
span.SetStatus(codes.Ok, "")
|
||||
return
|
||||
}
|
||||
|
||||
if err == nil || err == red.Nil {
|
||||
span.SetStatus(codes.Ok, "")
|
||||
return
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
span.RecordError(err)
|
||||
}
|
||||
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
span.RecordError(err)
|
||||
}
|
||||
|
||||
@@ -4,167 +4,103 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/logx/logtest"
|
||||
ztrace "github.com/zeromicro/go-zero/core/trace"
|
||||
"github.com/zeromicro/go-zero/core/trace/tracetest"
|
||||
tracesdk "go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func TestHookProcessCase1(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
defer ztrace.StopAgent()
|
||||
tracetest.NewInMemoryExporter(t)
|
||||
w := logtest.NewCollector(t)
|
||||
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
defer log.SetOutput(writer)
|
||||
|
||||
ctx, err := durationHook.BeforeProcess(context.Background(), red.NewCmd(context.Background()))
|
||||
err := durationHook.ProcessHook(func(ctx context.Context, cmd red.Cmder) error {
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
return nil
|
||||
})(context.Background(), red.NewCmd(context.Background()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcess(ctx, red.NewCmd(context.Background())))
|
||||
assert.False(t, strings.Contains(buf.String(), "slow"))
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
assert.False(t, strings.Contains(w.String(), "slow"))
|
||||
}
|
||||
|
||||
func TestHookProcessCase2(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
defer ztrace.StopAgent()
|
||||
|
||||
tracetest.NewInMemoryExporter(t)
|
||||
w := logtest.NewCollector(t)
|
||||
ctx, err := durationHook.BeforeProcess(context.Background(), red.NewCmd(context.Background()))
|
||||
|
||||
err := durationHook.ProcessHook(func(ctx context.Context, cmd red.Cmder) error {
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
return nil
|
||||
})(context.Background(), red.NewCmd(context.Background()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcess(ctx, red.NewCmd(context.Background(), "foo", "bar")))
|
||||
assert.True(t, strings.Contains(w.String(), "slow"))
|
||||
}
|
||||
|
||||
func TestHookProcessCase3(t *testing.T) {
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
defer log.SetOutput(writer)
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcess(context.Background(), red.NewCmd(context.Background())))
|
||||
assert.True(t, buf.Len() == 0)
|
||||
}
|
||||
|
||||
func TestHookProcessCase4(t *testing.T) {
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
defer log.SetOutput(writer)
|
||||
|
||||
ctx := context.WithValue(context.Background(), startTimeKey, "foo")
|
||||
assert.Nil(t, durationHook.AfterProcess(ctx, red.NewCmd(context.Background())))
|
||||
assert.True(t, buf.Len() == 0)
|
||||
assert.True(t, strings.Contains(w.String(), "trace"))
|
||||
assert.True(t, strings.Contains(w.String(), "span"))
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase1(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
defer ztrace.StopAgent()
|
||||
tracetest.NewInMemoryExporter(t)
|
||||
w := logtest.NewCollector(t)
|
||||
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
defer log.SetOutput(writer)
|
||||
|
||||
_, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{})
|
||||
err := durationHook.ProcessPipelineHook(func(ctx context.Context, cmds []red.Cmder) error {
|
||||
return nil
|
||||
})(context.Background(), nil)
|
||||
assert.NoError(t, err)
|
||||
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{
|
||||
|
||||
err = durationHook.ProcessPipelineHook(func(ctx context.Context, cmds []red.Cmder) error {
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
return nil
|
||||
})(context.Background(), []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{}))
|
||||
assert.NoError(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
}))
|
||||
assert.False(t, strings.Contains(buf.String(), "slow"))
|
||||
assert.False(t, strings.Contains(w.String(), "slow"))
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase2(t *testing.T) {
|
||||
ztrace.StartAgent(ztrace.Config{
|
||||
Name: "go-zero-test",
|
||||
Endpoint: "http://localhost:14268/api/traces",
|
||||
Batcher: "jaeger",
|
||||
Sampler: 1.0,
|
||||
})
|
||||
defer ztrace.StopAgent()
|
||||
|
||||
tracetest.NewInMemoryExporter(t)
|
||||
w := logtest.NewCollector(t)
|
||||
ctx, err := durationHook.BeforeProcessPipeline(context.Background(), []red.Cmder{
|
||||
|
||||
err := durationHook.ProcessPipelineHook(func(ctx context.Context, cmds []red.Cmder) error {
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
return nil
|
||||
})(context.Background(), []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
time.Sleep(slowThreshold.Load() + time.Millisecond)
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
||||
red.NewCmd(context.Background(), "foo", "bar"),
|
||||
}))
|
||||
assert.True(t, strings.Contains(w.String(), "slow"))
|
||||
assert.True(t, strings.Contains(w.String(), "trace"))
|
||||
assert.True(t, strings.Contains(w.String(), "span"))
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase3(t *testing.T) {
|
||||
w := logtest.NewCollector(t)
|
||||
te := tracetest.NewInMemoryExporter(t)
|
||||
|
||||
assert.Nil(t, durationHook.AfterProcessPipeline(context.Background(), []red.Cmder{
|
||||
err := durationHook.ProcessPipelineHook(func(ctx context.Context, cmds []red.Cmder) error {
|
||||
assert.Equal(t, "redis", tracesdk.SpanFromContext(ctx).(interface{ Name() string }).Name())
|
||||
return assert.AnError
|
||||
})(context.Background(), []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
}))
|
||||
assert.True(t, len(w.String()) == 0)
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase4(t *testing.T) {
|
||||
w := logtest.NewCollector(t)
|
||||
|
||||
ctx := context.WithValue(context.Background(), startTimeKey, "foo")
|
||||
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
}))
|
||||
assert.True(t, len(w.String()) == 0)
|
||||
}
|
||||
|
||||
func TestHookProcessPipelineCase5(t *testing.T) {
|
||||
writer := log.Writer()
|
||||
var buf strings.Builder
|
||||
log.SetOutput(&buf)
|
||||
defer log.SetOutput(writer)
|
||||
|
||||
ctx := context.WithValue(context.Background(), startTimeKey, "foo")
|
||||
assert.Nil(t, durationHook.AfterProcessPipeline(ctx, []red.Cmder{
|
||||
red.NewCmd(context.Background()),
|
||||
}))
|
||||
assert.True(t, buf.Len() == 0)
|
||||
})
|
||||
assert.ErrorIs(t, err, assert.AnError)
|
||||
traceLogs := te.GetSpans().Snapshots()[0]
|
||||
assert.Equal(t, "redis", traceLogs.Name())
|
||||
assert.Equal(t, assert.AnError.Error(), traceLogs.Events()[0].Attributes[1].Value.AsString(), "trace should record error")
|
||||
}
|
||||
|
||||
func TestLogDuration(t *testing.T) {
|
||||
@@ -202,7 +138,7 @@ func TestFormatError(t *testing.T) {
|
||||
assert.Equal(t, "context deadline", formatError(context.DeadlineExceeded))
|
||||
|
||||
// Test case: err is breaker.ErrServiceUnavailable
|
||||
assert.Equal(t, "breaker", formatError(breaker.ErrServiceUnavailable))
|
||||
assert.Equal(t, "breaker open", formatError(breaker.ErrServiceUnavailable))
|
||||
|
||||
// Test case: err is unknown
|
||||
assert.Equal(t, "unexpected error", formatError(errors.New("some error")))
|
||||
|
||||
@@ -3,8 +3,8 @@ package redis
|
||||
import (
|
||||
"sync"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/internal/devserver"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/errorx"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -64,6 +64,7 @@ type (
|
||||
// RedisNode interface represents a redis node.
|
||||
RedisNode interface {
|
||||
red.Cmdable
|
||||
red.BitMapCmdable
|
||||
}
|
||||
|
||||
// GeoLocation is used with GeoAdd to add geospatial location.
|
||||
@@ -482,13 +483,8 @@ func (s *Redis) ExistsManyCtx(ctx context.Context, keys ...string) (val int64, e
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.Exists(ctx, keys...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.Exists(ctx, keys...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -542,13 +538,8 @@ func (s *Redis) GeoAddCtx(ctx context.Context, key string, geoLocation ...*GeoLo
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoAdd(ctx, key, geoLocation...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoAdd(ctx, key, geoLocation...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -568,13 +559,8 @@ func (s *Redis) GeoDistCtx(ctx context.Context, key, member1, member2, unit stri
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoDist(ctx, key, member1, member2, unit).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoDist(ctx, key, member1, member2, unit).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -594,13 +580,8 @@ func (s *Redis) GeoHashCtx(ctx context.Context, key string, members ...string) (
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoHash(ctx, key, members...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoHash(ctx, key, members...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -621,13 +602,8 @@ func (s *Redis) GeoRadiusCtx(ctx context.Context, key string, longitude, latitud
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoRadius(ctx, key, longitude, latitude, query).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoRadius(ctx, key, longitude, latitude, query).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -647,13 +623,8 @@ func (s *Redis) GeoRadiusByMemberCtx(ctx context.Context, key, member string,
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoRadiusByMember(ctx, key, member, query).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoRadiusByMember(ctx, key, member, query).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -673,13 +644,8 @@ func (s *Redis) GeoPosCtx(ctx context.Context, key string, members ...string) (
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.GeoPos(ctx, key, members...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.GeoPos(ctx, key, members...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -698,7 +664,7 @@ func (s *Redis) GetCtx(ctx context.Context, key string) (val string, err error)
|
||||
return err
|
||||
}
|
||||
|
||||
if val, err = conn.Get(ctx, key).Result(); err == red.Nil {
|
||||
if val, err = conn.Get(ctx, key).Result(); errors.Is(err, red.Nil) {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
@@ -748,7 +714,7 @@ func (s *Redis) GetSetCtx(ctx context.Context, key, value string) (val string, e
|
||||
return err
|
||||
}
|
||||
|
||||
if val, err = conn.GetSet(ctx, key, value).Result(); err == red.Nil {
|
||||
if val, err = conn.GetSet(ctx, key, value).Result(); errors.Is(err, red.Nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -874,17 +840,16 @@ func (s *Redis) HincrbyFloat(key, field string, increment float64) (float64, err
|
||||
}
|
||||
|
||||
// HincrbyFloatCtx is the implementation of redis hincrbyfloat command.
|
||||
func (s *Redis) HincrbyFloatCtx(ctx context.Context, key, field string, increment float64) (val float64, err error) {
|
||||
func (s *Redis) HincrbyFloatCtx(ctx context.Context, key, field string, increment float64) (
|
||||
val float64, err error) {
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, err = conn.HIncrByFloat(ctx, key, field, increment).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -1338,6 +1303,26 @@ func (s *Redis) MgetCtx(ctx context.Context, keys ...string) (val []string, err
|
||||
return
|
||||
}
|
||||
|
||||
// Mset is the implementation of redis mset command.
|
||||
func (s *Redis) Mset(fieldsAndValues ...any) (string, error) {
|
||||
return s.MsetCtx(context.Background(), fieldsAndValues...)
|
||||
}
|
||||
|
||||
// MsetCtx is the implementation of redis mset command.
|
||||
func (s *Redis) MsetCtx(ctx context.Context, fieldsAndValues ...any) (val string, err error) {
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, err = conn.MSet(ctx, fieldsAndValues...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Persist is the implementation of redis persist command.
|
||||
func (s *Redis) Persist(key string) (bool, error) {
|
||||
return s.PersistCtx(context.Background(), key)
|
||||
@@ -2027,6 +2012,7 @@ func (s *Redis) TtlCtx(ctx context.Context, key string) (val int, err error) {
|
||||
// -1 means key exists but has no expire
|
||||
val = int(duration)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, acceptable)
|
||||
|
||||
@@ -2058,7 +2044,47 @@ func (s *Redis) ZaddFloatCtx(ctx context.Context, key string, score float64, val
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.ZAdd(ctx, key, &red.Z{
|
||||
v, err := conn.ZAdd(ctx, key, red.Z{
|
||||
Score: score,
|
||||
Member: value,
|
||||
}).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v == 1
|
||||
return nil
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Zaddnx is the implementation of redis zadd nx command.
|
||||
func (s *Redis) Zaddnx(key string, score int64, value string) (val bool, err error) {
|
||||
return s.ZaddnxCtx(context.Background(), key, score, value)
|
||||
}
|
||||
|
||||
// ZaddnxCtx is the implementation of redis zadd nx command.
|
||||
func (s *Redis) ZaddnxCtx(ctx context.Context, key string, score int64, value string) (
|
||||
val bool, err error) {
|
||||
return s.ZaddnxFloatCtx(ctx, key, float64(score), value)
|
||||
}
|
||||
|
||||
// ZaddnxFloat is the implementation of redis zaddnx command.
|
||||
func (s *Redis) ZaddnxFloat(key string, score float64, value string) (bool, error) {
|
||||
return s.ZaddFloatCtx(context.Background(), key, score, value)
|
||||
}
|
||||
|
||||
// ZaddnxFloatCtx is the implementation of redis zaddnx command.
|
||||
func (s *Redis) ZaddnxFloatCtx(ctx context.Context, key string, score float64, value string) (
|
||||
val bool, err error) {
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
conn, err := getRedis(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := conn.ZAddNX(ctx, key, red.Z{
|
||||
Score: score,
|
||||
Member: value,
|
||||
}).Result()
|
||||
@@ -2086,19 +2112,14 @@ func (s *Redis) ZaddsCtx(ctx context.Context, key string, ps ...Pair) (val int64
|
||||
return err
|
||||
}
|
||||
|
||||
var zs []*red.Z
|
||||
var zs []red.Z
|
||||
for _, p := range ps {
|
||||
z := &red.Z{Score: float64(p.Score), Member: p.Key}
|
||||
z := red.Z{Score: float64(p.Score), Member: p.Key}
|
||||
zs = append(zs, z)
|
||||
}
|
||||
|
||||
v, err := conn.ZAdd(ctx, key, zs...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val = v
|
||||
return nil
|
||||
val, err = conn.ZAdd(ctx, key, zs...).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
@@ -2218,6 +2239,7 @@ func (s *Redis) ZscoreByFloatCtx(ctx context.Context, key, value string) (val fl
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, err = conn.ZScore(ctx, key, value).Result()
|
||||
return err
|
||||
}, acceptable)
|
||||
@@ -2882,7 +2904,7 @@ func withHook(hook red.Hook) Option {
|
||||
}
|
||||
|
||||
func acceptable(err error) bool {
|
||||
return err == nil || err == red.Nil || errors.Is(err, context.Canceled)
|
||||
return err == nil || errors.Is(err, red.Nil) || errors.Is(err, context.Canceled)
|
||||
}
|
||||
|
||||
func getRedis(r *Redis) (RedisNode, error) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ package redis
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"io"
|
||||
"runtime"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
red "github.com/go-redis/redis/v8"
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
red "github.com/go-redis/redis/v8"
|
||||
|
||||
red "github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
@@ -42,7 +41,7 @@ type RedisLock struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// NewRedisLock returns a RedisLock.
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
)
|
||||
|
||||
const namespace = "mysql_client"
|
||||
const namespace = "sql_client"
|
||||
|
||||
var (
|
||||
metricReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
|
||||
|
||||
@@ -34,10 +34,10 @@ func TestSqlxMetric(t *testing.T) {
|
||||
s, err := io.ReadAll(resp.Body)
|
||||
assert.Nil(t, err)
|
||||
content := string(s)
|
||||
assert.Contains(t, content, "mysql_client_requests_duration_ms_sum{command=\"test-cmd\"} 8\n")
|
||||
assert.Contains(t, content, "mysql_client_requests_duration_ms_count{command=\"test-cmd\"} 1\n")
|
||||
assert.Contains(t, content, "mysql_client_requests_error_total{command=\"test-cmd\",error=\"internal-error\"} 1\n")
|
||||
assert.Contains(t, content, "mysql_client_requests_slow_total{command=\"test-cmd\"} 1\n")
|
||||
assert.Contains(t, content, "sql_client_requests_duration_ms_sum{command=\"test-cmd\"} 8\n")
|
||||
assert.Contains(t, content, "sql_client_requests_duration_ms_count{command=\"test-cmd\"} 1\n")
|
||||
assert.Contains(t, content, "sql_client_requests_error_total{command=\"test-cmd\",error=\"internal-error\"} 1\n")
|
||||
assert.Contains(t, content, "sql_client_requests_slow_total{command=\"test-cmd\"} 1\n")
|
||||
}
|
||||
|
||||
func TestMetricCollector(t *testing.T) {
|
||||
@@ -95,51 +95,51 @@ func TestMetricCollector(t *testing.T) {
|
||||
},
|
||||
})
|
||||
val := `
|
||||
# HELP mysql_client_idle_connections The number of idle connections.
|
||||
# TYPE mysql_client_idle_connections gauge
|
||||
mysql_client_idle_connections{db_name="db-1",hash="hash-1"} 4
|
||||
mysql_client_idle_connections{db_name="db-1",hash="hash-2"} 40
|
||||
mysql_client_idle_connections{db_name="db-2",hash="hash-2"} 400
|
||||
# HELP mysql_client_in_use_connections The number of connections currently in use.
|
||||
# TYPE mysql_client_in_use_connections gauge
|
||||
mysql_client_in_use_connections{db_name="db-1",hash="hash-1"} 3
|
||||
mysql_client_in_use_connections{db_name="db-1",hash="hash-2"} 30
|
||||
mysql_client_in_use_connections{db_name="db-2",hash="hash-2"} 300
|
||||
# HELP mysql_client_max_idle_closed_total The total number of connections closed due to SetMaxIdleConns.
|
||||
# TYPE mysql_client_max_idle_closed_total counter
|
||||
mysql_client_max_idle_closed_total{db_name="db-1",hash="hash-1"} 7
|
||||
mysql_client_max_idle_closed_total{db_name="db-1",hash="hash-2"} 70
|
||||
mysql_client_max_idle_closed_total{db_name="db-2",hash="hash-2"} 700
|
||||
# HELP mysql_client_max_idle_time_closed_total The total number of connections closed due to SetConnMaxIdleTime.
|
||||
# TYPE mysql_client_max_idle_time_closed_total counter
|
||||
mysql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-1"} 8
|
||||
mysql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-2"} 80
|
||||
mysql_client_max_idle_time_closed_total{db_name="db-2",hash="hash-2"} 800
|
||||
# HELP mysql_client_max_lifetime_closed_total The total number of connections closed due to SetConnMaxLifetime.
|
||||
# TYPE mysql_client_max_lifetime_closed_total counter
|
||||
mysql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-1"} 9
|
||||
mysql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-2"} 90
|
||||
mysql_client_max_lifetime_closed_total{db_name="db-2",hash="hash-2"} 900
|
||||
# HELP mysql_client_max_open_connections Maximum number of open connections to the database.
|
||||
# TYPE mysql_client_max_open_connections gauge
|
||||
mysql_client_max_open_connections{db_name="db-1",hash="hash-1"} 1
|
||||
mysql_client_max_open_connections{db_name="db-1",hash="hash-2"} 10
|
||||
mysql_client_max_open_connections{db_name="db-2",hash="hash-2"} 100
|
||||
# HELP mysql_client_open_connections The number of established connections both in use and idle.
|
||||
# TYPE mysql_client_open_connections gauge
|
||||
mysql_client_open_connections{db_name="db-1",hash="hash-1"} 2
|
||||
mysql_client_open_connections{db_name="db-1",hash="hash-2"} 20
|
||||
mysql_client_open_connections{db_name="db-2",hash="hash-2"} 200
|
||||
# HELP mysql_client_wait_count_total The total number of connections waited for.
|
||||
# TYPE mysql_client_wait_count_total counter
|
||||
mysql_client_wait_count_total{db_name="db-1",hash="hash-1"} 5
|
||||
mysql_client_wait_count_total{db_name="db-1",hash="hash-2"} 50
|
||||
mysql_client_wait_count_total{db_name="db-2",hash="hash-2"} 500
|
||||
# HELP mysql_client_wait_duration_seconds_total The total time blocked waiting for a new connection.
|
||||
# TYPE mysql_client_wait_duration_seconds_total counter
|
||||
mysql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-1"} 6
|
||||
mysql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-2"} 60
|
||||
mysql_client_wait_duration_seconds_total{db_name="db-2",hash="hash-2"} 600
|
||||
# HELP sql_client_idle_connections The number of idle connections.
|
||||
# TYPE sql_client_idle_connections gauge
|
||||
sql_client_idle_connections{db_name="db-1",hash="hash-1"} 4
|
||||
sql_client_idle_connections{db_name="db-1",hash="hash-2"} 40
|
||||
sql_client_idle_connections{db_name="db-2",hash="hash-2"} 400
|
||||
# HELP sql_client_in_use_connections The number of connections currently in use.
|
||||
# TYPE sql_client_in_use_connections gauge
|
||||
sql_client_in_use_connections{db_name="db-1",hash="hash-1"} 3
|
||||
sql_client_in_use_connections{db_name="db-1",hash="hash-2"} 30
|
||||
sql_client_in_use_connections{db_name="db-2",hash="hash-2"} 300
|
||||
# HELP sql_client_max_idle_closed_total The total number of connections closed due to SetMaxIdleConns.
|
||||
# TYPE sql_client_max_idle_closed_total counter
|
||||
sql_client_max_idle_closed_total{db_name="db-1",hash="hash-1"} 7
|
||||
sql_client_max_idle_closed_total{db_name="db-1",hash="hash-2"} 70
|
||||
sql_client_max_idle_closed_total{db_name="db-2",hash="hash-2"} 700
|
||||
# HELP sql_client_max_idle_time_closed_total The total number of connections closed due to SetConnMaxIdleTime.
|
||||
# TYPE sql_client_max_idle_time_closed_total counter
|
||||
sql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-1"} 8
|
||||
sql_client_max_idle_time_closed_total{db_name="db-1",hash="hash-2"} 80
|
||||
sql_client_max_idle_time_closed_total{db_name="db-2",hash="hash-2"} 800
|
||||
# HELP sql_client_max_lifetime_closed_total The total number of connections closed due to SetConnMaxLifetime.
|
||||
# TYPE sql_client_max_lifetime_closed_total counter
|
||||
sql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-1"} 9
|
||||
sql_client_max_lifetime_closed_total{db_name="db-1",hash="hash-2"} 90
|
||||
sql_client_max_lifetime_closed_total{db_name="db-2",hash="hash-2"} 900
|
||||
# HELP sql_client_max_open_connections Maximum number of open connections to the database.
|
||||
# TYPE sql_client_max_open_connections gauge
|
||||
sql_client_max_open_connections{db_name="db-1",hash="hash-1"} 1
|
||||
sql_client_max_open_connections{db_name="db-1",hash="hash-2"} 10
|
||||
sql_client_max_open_connections{db_name="db-2",hash="hash-2"} 100
|
||||
# HELP sql_client_open_connections The number of established connections both in use and idle.
|
||||
# TYPE sql_client_open_connections gauge
|
||||
sql_client_open_connections{db_name="db-1",hash="hash-1"} 2
|
||||
sql_client_open_connections{db_name="db-1",hash="hash-2"} 20
|
||||
sql_client_open_connections{db_name="db-2",hash="hash-2"} 200
|
||||
# HELP sql_client_wait_count_total The total number of connections waited for.
|
||||
# TYPE sql_client_wait_count_total counter
|
||||
sql_client_wait_count_total{db_name="db-1",hash="hash-1"} 5
|
||||
sql_client_wait_count_total{db_name="db-1",hash="hash-2"} 50
|
||||
sql_client_wait_count_total{db_name="db-2",hash="hash-2"} 500
|
||||
# HELP sql_client_wait_duration_seconds_total The total time blocked waiting for a new connection.
|
||||
# TYPE sql_client_wait_duration_seconds_total counter
|
||||
sql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-1"} 6
|
||||
sql_client_wait_duration_seconds_total{db_name="db-1",hash="hash-2"} 60
|
||||
sql_client_wait_duration_seconds_total{db_name="db-2",hash="hash-2"} 600
|
||||
`
|
||||
|
||||
err := testutil.CollectAndCompare(c, strings.NewReader(val))
|
||||
|
||||
@@ -42,21 +42,6 @@ type (
|
||||
// SqlOption defines the method to customize a sql connection.
|
||||
SqlOption func(*commonSqlConn)
|
||||
|
||||
// StmtSession interface represents a session that can be used to execute statements.
|
||||
StmtSession interface {
|
||||
Close() error
|
||||
Exec(args ...any) (sql.Result, error)
|
||||
ExecCtx(ctx context.Context, args ...any) (sql.Result, error)
|
||||
QueryRow(v any, args ...any) error
|
||||
QueryRowCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRowPartial(v any, args ...any) error
|
||||
QueryRowPartialCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRows(v any, args ...any) error
|
||||
QueryRowsCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRowsPartial(v any, args ...any) error
|
||||
QueryRowsPartialCtx(ctx context.Context, v any, args ...any) error
|
||||
}
|
||||
|
||||
// thread-safe
|
||||
// Because CORBA doesn't support PREPARE, so we need to combine the
|
||||
// query arguments into one string and do underlying query without arguments
|
||||
@@ -65,7 +50,7 @@ type (
|
||||
onError func(context.Context, error)
|
||||
beginTx beginnable
|
||||
brk breaker.Breaker
|
||||
accept func(error) bool
|
||||
accept breaker.Acceptable
|
||||
}
|
||||
|
||||
connProvider func() (*sql.DB, error)
|
||||
@@ -76,18 +61,6 @@ type (
|
||||
Query(query string, args ...any) (*sql.Rows, error)
|
||||
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
|
||||
}
|
||||
|
||||
statement struct {
|
||||
query string
|
||||
stmt *sql.Stmt
|
||||
}
|
||||
|
||||
stmtConn interface {
|
||||
Exec(args ...any) (sql.Result, error)
|
||||
ExecContext(ctx context.Context, args ...any) (sql.Result, error)
|
||||
Query(args ...any) (*sql.Rows, error)
|
||||
QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
|
||||
}
|
||||
)
|
||||
|
||||
// NewSqlConn returns a SqlConn with given driver name and datasource.
|
||||
@@ -189,8 +162,10 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm
|
||||
}
|
||||
|
||||
stmt = statement{
|
||||
query: query,
|
||||
stmt: st,
|
||||
query: query,
|
||||
stmt: st,
|
||||
brk: db.brk,
|
||||
accept: db.acceptable,
|
||||
}
|
||||
return nil
|
||||
}, db.acceptable)
|
||||
@@ -311,7 +286,7 @@ func (db *commonSqlConn) acceptable(err error) bool {
|
||||
|
||||
func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows) error,
|
||||
q string, args ...any) (err error) {
|
||||
var qerr error
|
||||
var scanFailed bool
|
||||
err = db.brk.DoWithAcceptable(func() error {
|
||||
conn, err := db.connProv()
|
||||
if err != nil {
|
||||
@@ -320,11 +295,14 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
|
||||
}
|
||||
|
||||
return query(ctx, conn, func(rows *sql.Rows) error {
|
||||
qerr = scanner(rows)
|
||||
return qerr
|
||||
e := scanner(rows)
|
||||
if e != nil {
|
||||
scanFailed = true
|
||||
}
|
||||
return e
|
||||
}, q, args...)
|
||||
}, func(err error) bool {
|
||||
return errors.Is(err, qerr) || db.acceptable(err)
|
||||
return scanFailed || db.acceptable(err)
|
||||
})
|
||||
if errors.Is(err, breaker.ErrServiceUnavailable) {
|
||||
metricReqErr.Inc("queryRows", "breaker")
|
||||
@@ -333,83 +311,6 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
|
||||
return
|
||||
}
|
||||
|
||||
func (s statement) Close() error {
|
||||
return s.stmt.Close()
|
||||
}
|
||||
|
||||
func (s statement) Exec(args ...any) (sql.Result, error) {
|
||||
return s.ExecCtx(context.Background(), args...)
|
||||
}
|
||||
|
||||
func (s statement) ExecCtx(ctx context.Context, args ...any) (result sql.Result, err error) {
|
||||
ctx, span := startSpan(ctx, "Exec")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return execStmt(ctx, s.stmt, s.query, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRow(v any, args ...any) error {
|
||||
return s.QueryRowCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRow")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRow(v, rows, true)
|
||||
}, s.query, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartial(v any, args ...any) error {
|
||||
return s.QueryRowPartialCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartialCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRowPartial")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRow(v, rows, false)
|
||||
}, s.query, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRows(v any, args ...any) error {
|
||||
return s.QueryRowsCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRows")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRows(v, rows, true)
|
||||
}, s.query, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartial(v any, args ...any) error {
|
||||
return s.QueryRowsPartialCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartialCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRowsPartial")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRows(v, rows, false)
|
||||
}, s.query, args...)
|
||||
}
|
||||
|
||||
// WithAcceptable returns a SqlOption that setting the acceptable function.
|
||||
// acceptable is the func to check if the error can be accepted.
|
||||
func WithAcceptable(acceptable func(err error) bool) SqlOption {
|
||||
|
||||
@@ -156,6 +156,7 @@ func TestStatement(t *testing.T) {
|
||||
st := statement{
|
||||
query: "foo",
|
||||
stmt: stmt,
|
||||
brk: breaker.NopBreaker(),
|
||||
}
|
||||
assert.NoError(t, st.Close())
|
||||
})
|
||||
|
||||
@@ -3,8 +3,10 @@ package sqlx
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/syncx"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
@@ -18,6 +20,145 @@ var (
|
||||
logSlowSql = syncx.ForAtomicBool(true)
|
||||
)
|
||||
|
||||
type (
|
||||
// StmtSession interface represents a session that can be used to execute statements.
|
||||
StmtSession interface {
|
||||
Close() error
|
||||
Exec(args ...any) (sql.Result, error)
|
||||
ExecCtx(ctx context.Context, args ...any) (sql.Result, error)
|
||||
QueryRow(v any, args ...any) error
|
||||
QueryRowCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRowPartial(v any, args ...any) error
|
||||
QueryRowPartialCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRows(v any, args ...any) error
|
||||
QueryRowsCtx(ctx context.Context, v any, args ...any) error
|
||||
QueryRowsPartial(v any, args ...any) error
|
||||
QueryRowsPartialCtx(ctx context.Context, v any, args ...any) error
|
||||
}
|
||||
|
||||
statement struct {
|
||||
query string
|
||||
stmt *sql.Stmt
|
||||
brk breaker.Breaker
|
||||
accept breaker.Acceptable
|
||||
}
|
||||
|
||||
stmtConn interface {
|
||||
Exec(args ...any) (sql.Result, error)
|
||||
ExecContext(ctx context.Context, args ...any) (sql.Result, error)
|
||||
Query(args ...any) (*sql.Rows, error)
|
||||
QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
|
||||
}
|
||||
)
|
||||
|
||||
func (s statement) Close() error {
|
||||
return s.stmt.Close()
|
||||
}
|
||||
|
||||
func (s statement) Exec(args ...any) (sql.Result, error) {
|
||||
return s.ExecCtx(context.Background(), args...)
|
||||
}
|
||||
|
||||
func (s statement) ExecCtx(ctx context.Context, args ...any) (result sql.Result, err error) {
|
||||
ctx, span := startSpan(ctx, "Exec")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
result, err = execStmt(ctx, s.stmt, s.query, args...)
|
||||
return err
|
||||
}, func(err error) bool {
|
||||
return s.accept(err)
|
||||
})
|
||||
if errors.Is(err, breaker.ErrServiceUnavailable) {
|
||||
metricReqErr.Inc("stmt_exec", "breaker")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s statement) QueryRow(v any, args ...any) error {
|
||||
return s.QueryRowCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRow")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return s.queryRows(ctx, func(v any, scanner rowsScanner) error {
|
||||
return unmarshalRow(v, scanner, true)
|
||||
}, v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartial(v any, args ...any) error {
|
||||
return s.QueryRowPartialCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartialCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRowPartial")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return s.queryRows(ctx, func(v any, scanner rowsScanner) error {
|
||||
return unmarshalRow(v, scanner, false)
|
||||
}, v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRows(v any, args ...any) error {
|
||||
return s.QueryRowsCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRows")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return s.queryRows(ctx, func(v any, scanner rowsScanner) error {
|
||||
return unmarshalRows(v, scanner, true)
|
||||
}, v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartial(v any, args ...any) error {
|
||||
return s.QueryRowsPartialCtx(context.Background(), v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartialCtx(ctx context.Context, v any, args ...any) (err error) {
|
||||
ctx, span := startSpan(ctx, "QueryRowsPartial")
|
||||
defer func() {
|
||||
endSpan(span, err)
|
||||
}()
|
||||
|
||||
return s.queryRows(ctx, func(v any, scanner rowsScanner) error {
|
||||
return unmarshalRows(v, scanner, false)
|
||||
}, v, args...)
|
||||
}
|
||||
|
||||
func (s statement) queryRows(ctx context.Context, scanFn func(any, rowsScanner) error,
|
||||
v any, args ...any) error {
|
||||
var scanFailed bool
|
||||
err := s.brk.DoWithAcceptable(func() error {
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
err := scanFn(v, rows)
|
||||
if err != nil {
|
||||
scanFailed = true
|
||||
}
|
||||
return err
|
||||
}, s.query, args...)
|
||||
}, func(err error) bool {
|
||||
return scanFailed || s.accept(err)
|
||||
})
|
||||
if errors.Is(err, breaker.ErrServiceUnavailable) {
|
||||
metricReqErr.Inc("stmt_queryRows", "breaker")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DisableLog disables logging of sql statements, includes info and slow logs.
|
||||
func DisableLog() {
|
||||
logSql.Set(false)
|
||||
|
||||
@@ -7,7 +7,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/stores/dbtest"
|
||||
)
|
||||
|
||||
var errMockedPlaceholder = errors.New("placeholder")
|
||||
@@ -219,6 +222,74 @@ func TestNilGuard(t *testing.T) {
|
||||
assert.Equal(t, nilGuard{}, guard)
|
||||
}
|
||||
|
||||
func TestStmtBreaker(t *testing.T) {
|
||||
dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
mock.ExpectPrepare("any")
|
||||
|
||||
conn := NewSqlConnFromDB(db)
|
||||
stmt, err := conn.Prepare("any")
|
||||
assert.NoError(t, err)
|
||||
|
||||
var val struct {
|
||||
Foo int
|
||||
Bar string
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
row := sqlmock.NewRows([]string{"foo"}).AddRow("bar")
|
||||
mock.ExpectQuery("any").WillReturnRows(row)
|
||||
err := stmt.QueryRow(&val)
|
||||
assert.Error(t, err)
|
||||
assert.NotErrorIs(t, err, breaker.ErrServiceUnavailable)
|
||||
}
|
||||
})
|
||||
|
||||
dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
mock.ExpectPrepare("any")
|
||||
conn := NewSqlConnFromDB(db)
|
||||
stmt, err := conn.Prepare("any")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
assert.Error(t, conn.Transact(func(session Session) error {
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
var breakerTriggered bool
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = stmt.Exec("any")
|
||||
if errors.Is(err, breaker.ErrServiceUnavailable) {
|
||||
breakerTriggered = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, breakerTriggered)
|
||||
})
|
||||
|
||||
dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
mock.ExpectPrepare("any")
|
||||
conn := NewSqlConnFromDB(db)
|
||||
stmt, err := conn.Prepare("any")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
assert.Error(t, conn.Transact(func(session Session) error {
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
var breakerTriggered bool
|
||||
for i := 0; i < 1000; i++ {
|
||||
err = stmt.QueryRows(&struct{}{}, "any")
|
||||
if errors.Is(err, breaker.ErrServiceUnavailable) {
|
||||
breakerTriggered = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, breakerTriggered)
|
||||
})
|
||||
}
|
||||
|
||||
type mockedSessionConn struct {
|
||||
lastInsertId int64
|
||||
rowsAffected int64
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -75,6 +77,7 @@ func (t txSession) PrepareCtx(ctx context.Context, q string) (stmtSession StmtSe
|
||||
return statement{
|
||||
query: q,
|
||||
stmt: stmt,
|
||||
brk: breaker.NopBreaker(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func FuzzNodeFind(f *testing.F) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
f.Add(10)
|
||||
f.Fuzz(func(t *testing.T, keys int) {
|
||||
|
||||
105
core/threading/stablerunner.go
Normal file
105
core/threading/stablerunner.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package threading
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
const factor = 10
|
||||
|
||||
var (
|
||||
ErrRunnerClosed = errors.New("runner closed")
|
||||
|
||||
bufSize = runtime.NumCPU() * factor
|
||||
)
|
||||
|
||||
// StableRunner is a runner that guarantees messages are taken out with the pushed order.
|
||||
// This runner is typically useful for Kafka consumers with parallel processing.
|
||||
type StableRunner[I, O any] struct {
|
||||
handle func(I) O
|
||||
consumedIndex uint64
|
||||
writtenIndex uint64
|
||||
ring []*struct {
|
||||
value chan O
|
||||
lock sync.Mutex
|
||||
}
|
||||
runner *TaskRunner
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
// NewStableRunner returns a new StableRunner with given message processor fn.
|
||||
func NewStableRunner[I, O any](fn func(I) O) *StableRunner[I, O] {
|
||||
ring := make([]*struct {
|
||||
value chan O
|
||||
lock sync.Mutex
|
||||
}, bufSize)
|
||||
for i := 0; i < bufSize; i++ {
|
||||
ring[i] = &struct {
|
||||
value chan O
|
||||
lock sync.Mutex
|
||||
}{
|
||||
value: make(chan O, 1),
|
||||
}
|
||||
}
|
||||
|
||||
return &StableRunner[I, O]{
|
||||
handle: fn,
|
||||
ring: ring,
|
||||
runner: NewTaskRunner(runtime.NumCPU()),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the next processed message in order.
|
||||
// This method should be called in one goroutine.
|
||||
func (r *StableRunner[I, O]) Get() (O, error) {
|
||||
defer atomic.AddUint64(&r.consumedIndex, 1)
|
||||
|
||||
index := atomic.LoadUint64(&r.consumedIndex)
|
||||
offset := index % uint64(bufSize)
|
||||
holder := r.ring[offset]
|
||||
|
||||
select {
|
||||
case o := <-holder.value:
|
||||
return o, nil
|
||||
case <-r.done:
|
||||
if atomic.LoadUint64(&r.consumedIndex) < atomic.LoadUint64(&r.writtenIndex) {
|
||||
return <-holder.value, nil
|
||||
}
|
||||
|
||||
var o O
|
||||
return o, ErrRunnerClosed
|
||||
}
|
||||
}
|
||||
|
||||
// Push pushes the message v into the runner and to be processed concurrently,
|
||||
// after processed, it will be cached to let caller take it in pushing order.
|
||||
func (r *StableRunner[I, O]) Push(v I) error {
|
||||
select {
|
||||
case <-r.done:
|
||||
return ErrRunnerClosed
|
||||
default:
|
||||
index := atomic.AddUint64(&r.writtenIndex, 1)
|
||||
offset := (index - 1) % uint64(bufSize)
|
||||
holder := r.ring[offset]
|
||||
holder.lock.Lock()
|
||||
r.runner.Schedule(func() {
|
||||
defer holder.lock.Unlock()
|
||||
o := r.handle(v)
|
||||
holder.value <- o
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Wait waits all the messages to be processed and taken from inner buffer.
|
||||
func (r *StableRunner[I, O]) Wait() {
|
||||
close(r.done)
|
||||
r.runner.Wait()
|
||||
for atomic.LoadUint64(&r.consumedIndex) < atomic.LoadUint64(&r.writtenIndex) {
|
||||
runtime.Gosched()
|
||||
}
|
||||
}
|
||||
97
core/threading/stablerunner_test.go
Normal file
97
core/threading/stablerunner_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package threading
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sort"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStableRunner(t *testing.T) {
|
||||
size := bufSize * 2
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
runner := NewStableRunner(func(v int) float64 {
|
||||
if v == 0 {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
} else {
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
|
||||
}
|
||||
return float64(v) + 0.5
|
||||
})
|
||||
|
||||
var waitGroup sync.WaitGroup
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
for i := 0; i < size; i++ {
|
||||
assert.NoError(t, runner.Push(i))
|
||||
}
|
||||
runner.Wait()
|
||||
waitGroup.Done()
|
||||
}()
|
||||
|
||||
values := make([]float64, size)
|
||||
for i := 0; i < size; i++ {
|
||||
var err error
|
||||
values[i], err = runner.Get()
|
||||
assert.NoError(t, err)
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
|
||||
assert.True(t, sort.Float64sAreSorted(values))
|
||||
waitGroup.Wait()
|
||||
|
||||
assert.Equal(t, ErrRunnerClosed, runner.Push(1))
|
||||
_, err := runner.Get()
|
||||
assert.Equal(t, ErrRunnerClosed, err)
|
||||
}
|
||||
|
||||
func FuzzStableRunner(f *testing.F) {
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
f.Add(uint64(bufSize))
|
||||
f.Fuzz(func(t *testing.T, n uint64) {
|
||||
runner := NewStableRunner(func(v int) float64 {
|
||||
if v == 0 {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
} else {
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
|
||||
}
|
||||
return float64(v) + 0.5
|
||||
})
|
||||
|
||||
go func() {
|
||||
for i := 0; i < int(n); i++ {
|
||||
assert.NoError(t, runner.Push(i))
|
||||
}
|
||||
}()
|
||||
|
||||
values := make([]float64, n)
|
||||
for i := 0; i < int(n); i++ {
|
||||
var err error
|
||||
values[i], err = runner.Get()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
runner.Wait()
|
||||
assert.True(t, sort.Float64sAreSorted(values))
|
||||
|
||||
// make sure returning errors after runner is closed
|
||||
assert.Equal(t, ErrRunnerClosed, runner.Push(1))
|
||||
_, err := runner.Get()
|
||||
assert.Equal(t, ErrRunnerClosed, err)
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkStableRunner(b *testing.B) {
|
||||
runner := NewStableRunner(func(v int) float64 {
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
|
||||
return float64(v) + 0.5
|
||||
})
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = runner.Push(i)
|
||||
_, _ = runner.Get()
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
package threading
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/lang"
|
||||
"github.com/zeromicro/go-zero/core/rescue"
|
||||
)
|
||||
|
||||
// ErrTaskRunnerBusy is the error that indicates the runner is busy.
|
||||
var ErrTaskRunnerBusy = errors.New("task runner is busy")
|
||||
|
||||
// A TaskRunner is used to control the concurrency of goroutines.
|
||||
type TaskRunner struct {
|
||||
limitChan chan lang.PlaceholderType
|
||||
waitGroup sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewTaskRunner returns a TaskRunner.
|
||||
@@ -19,13 +26,47 @@ func NewTaskRunner(concurrency int) *TaskRunner {
|
||||
|
||||
// Schedule schedules a task to run under concurrency control.
|
||||
func (rp *TaskRunner) Schedule(task func()) {
|
||||
// Why we add waitGroup first, in case of race condition on starting a task and wait returns.
|
||||
// For example, limitChan is full, and the task is scheduled to run, but the waitGroup is not added,
|
||||
// then the wait returns, and the task is then scheduled to run, but caller thinks all tasks are done.
|
||||
// the same reason for ScheduleImmediately.
|
||||
rp.waitGroup.Add(1)
|
||||
rp.limitChan <- lang.Placeholder
|
||||
|
||||
go func() {
|
||||
defer rescue.Recover(func() {
|
||||
<-rp.limitChan
|
||||
rp.waitGroup.Done()
|
||||
})
|
||||
|
||||
task()
|
||||
}()
|
||||
}
|
||||
|
||||
// ScheduleImmediately schedules a task to run immediately under concurrency control.
|
||||
// It returns ErrTaskRunnerBusy if the runner is busy.
|
||||
func (rp *TaskRunner) ScheduleImmediately(task func()) error {
|
||||
// Why we add waitGroup first, check the comment in Schedule.
|
||||
rp.waitGroup.Add(1)
|
||||
select {
|
||||
case rp.limitChan <- lang.Placeholder:
|
||||
default:
|
||||
rp.waitGroup.Done()
|
||||
return ErrTaskRunnerBusy
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer rescue.Recover(func() {
|
||||
<-rp.limitChan
|
||||
rp.waitGroup.Done()
|
||||
})
|
||||
task()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Wait waits all running tasks to be done.
|
||||
func (rp *TaskRunner) Wait() {
|
||||
rp.waitGroup.Wait()
|
||||
}
|
||||
|
||||
@@ -2,32 +2,52 @@ package threading
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRoutinePool(t *testing.T) {
|
||||
func TestTaskRunner_Schedule(t *testing.T) {
|
||||
times := 100
|
||||
pool := NewTaskRunner(runtime.NumCPU())
|
||||
|
||||
var counter int32
|
||||
var waitGroup sync.WaitGroup
|
||||
for i := 0; i < times; i++ {
|
||||
waitGroup.Add(1)
|
||||
pool.Schedule(func() {
|
||||
atomic.AddInt32(&counter, 1)
|
||||
waitGroup.Done()
|
||||
})
|
||||
}
|
||||
|
||||
waitGroup.Wait()
|
||||
pool.Wait()
|
||||
|
||||
assert.Equal(t, times, int(counter))
|
||||
}
|
||||
|
||||
func TestTaskRunner_ScheduleImmediately(t *testing.T) {
|
||||
cpus := runtime.NumCPU()
|
||||
times := cpus * 2
|
||||
pool := NewTaskRunner(cpus)
|
||||
|
||||
var counter int32
|
||||
for i := 0; i < times; i++ {
|
||||
err := pool.ScheduleImmediately(func() {
|
||||
atomic.AddInt32(&counter, 1)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
})
|
||||
if i < cpus {
|
||||
assert.Nil(t, err)
|
||||
} else {
|
||||
assert.ErrorIs(t, err, ErrTaskRunnerBusy)
|
||||
}
|
||||
}
|
||||
|
||||
pool.Wait()
|
||||
|
||||
assert.Equal(t, cpus, int(counter))
|
||||
}
|
||||
|
||||
func BenchmarkRoutinePool(b *testing.B) {
|
||||
queue := NewTaskRunner(runtime.NumCPU())
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
70
go.mod
70
go.mod
@@ -3,25 +3,25 @@ module github.com/zeromicro/go-zero
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1
|
||||
github.com/alicebob/miniredis/v2 v2.31.0
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/alicebob/miniredis/v2 v2.31.1
|
||||
github.com/fatih/color v1.16.0
|
||||
github.com/fullstorydev/grpcurl v1.8.9
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/golang/protobuf v1.5.3
|
||||
github.com/google/uuid v1.4.0
|
||||
github.com/jackc/pgx/v5 v5.5.1
|
||||
github.com/jhump/protoreflect v1.15.4
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jackc/pgx/v5 v5.5.3
|
||||
github.com/jhump/protoreflect v1.15.6
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pelletier/go-toml/v2 v2.1.0
|
||||
github.com/prometheus/client_golang v1.17.0
|
||||
github.com/pelletier/go-toml/v2 v2.1.1
|
||||
github.com/prometheus/client_golang v1.18.0
|
||||
github.com/redis/go-redis/v9 v9.4.0
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go.etcd.io/etcd/api/v3 v3.5.11
|
||||
go.etcd.io/etcd/client/v3 v3.5.11
|
||||
github.com/stretchr/testify v1.9.0
|
||||
go.etcd.io/etcd/api/v3 v3.5.12
|
||||
go.etcd.io/etcd/client/v3 v3.5.12
|
||||
go.mongodb.org/mongo-driver v1.13.1
|
||||
go.opentelemetry.io/otel v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||
@@ -33,33 +33,33 @@ require (
|
||||
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.19.0
|
||||
golang.org/x/sys v0.15.0
|
||||
golang.org/x/net v0.21.0
|
||||
golang.org/x/sys v0.17.0
|
||||
golang.org/x/time v0.5.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b
|
||||
google.golang.org/grpc v1.60.0
|
||||
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80
|
||||
google.golang.org/grpc v1.62.0
|
||||
google.golang.org/protobuf v1.32.0
|
||||
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.28.4
|
||||
k8s.io/apimachinery v0.28.4
|
||||
k8s.io/client-go v0.28.4
|
||||
k8s.io/api v0.29.2
|
||||
k8s.io/apimachinery v0.29.2
|
||||
k8s.io/client-go v0.29.2
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bufbuild/protocompile v0.7.1 // indirect
|
||||
github.com/bufbuild/protocompile v0.8.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // 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
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // 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
|
||||
@@ -81,42 +81,42 @@ require (
|
||||
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 v1.0.4 // 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/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||
github.com/prometheus/common v0.44.0 // indirect
|
||||
github.com/prometheus/procfs v0.11.1 // 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/rivo/uniseg v0.2.0 // 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/yuin/gopher-lua v1.1.0 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // 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.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.16.0 // indirect
|
||||
golang.org/x/oauth2 v0.13.0 // indirect
|
||||
golang.org/x/sync v0.5.0 // indirect
|
||||
golang.org/x/term v0.15.0 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/oauth2 v0.16.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/term v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/klog/v2 v2.100.1 // indirect
|
||||
k8s.io/klog/v2 v2.110.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
)
|
||||
|
||||
159
go.sum
159
go.sum
@@ -1,16 +1,18 @@
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||
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/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0=
|
||||
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.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpSH4c22PU=
|
||||
github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
|
||||
github.com/alicebob/miniredis/v2 v2.31.1 h1:7XAt0uUg3DtwEKW5ZAGa+K7FZV2DdKQo5K/6TTnfX8Y=
|
||||
github.com/alicebob/miniredis/v2 v2.31.1/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
|
||||
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/bufbuild/protocompile v0.7.1 h1:Kd8fb6EshOHXNNRtYAmLAwy/PotlyFoN0iMbuwGNh0M=
|
||||
github.com/bufbuild/protocompile v0.7.1/go.mod h1:+Etjg4guZoAqzVk2czwEQP12yaxLJ8DxuqCJ9qHdH94=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bufbuild/protocompile v0.8.0 h1:9Kp1q6OkS9L4nM3FYbr8vlJnEwtbpDPQlQOVXfR+78s=
|
||||
github.com/bufbuild/protocompile v0.8.0/go.mod h1:+Etjg4guZoAqzVk2czwEQP12yaxLJ8DxuqCJ9qHdH94=
|
||||
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=
|
||||
@@ -28,17 +30,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
||||
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fullstorydev/grpcurl v1.8.9 h1:JMvZXK8lHDGyLmTQ0ZdGDnVVGuwjbpaumf8p42z0d+c=
|
||||
github.com/fullstorydev/grpcurl v1.8.9/go.mod h1:PNNKevV5VNAV2loscyLISrEnWQI61eqR0F8l3bVadAA=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/logr v1.2.4/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/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=
|
||||
@@ -48,8 +48,6 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
|
||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
||||
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||
@@ -58,11 +56,10 @@ 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.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
|
||||
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
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.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
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.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
@@ -74,14 +71,15 @@ github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvR
|
||||
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=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
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/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
@@ -90,12 +88,12 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/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.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI=
|
||||
github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
|
||||
github.com/jackc/pgx/v5 v5.5.3 h1:Ces6/M3wbDXYpM8JyyPD57ivTtJACFZJd885pdIaV2s=
|
||||
github.com/jackc/pgx/v5 v5.5.3/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
|
||||
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.15.4 h1:mrwJhfQGGljwvR/jPEocli8KA6G9afbQpH8NY2wORcI=
|
||||
github.com/jhump/protoreflect v1.15.4/go.mod h1:2B+zwrnMY3TTIqEK01OG/d3pyUycQBfDf+bx8fE2DNg=
|
||||
github.com/jhump/protoreflect v1.15.6 h1:WMYJbw2Wo+KOWwZFvgY0jMoVHM6i4XIvRs2RcBj5VmI=
|
||||
github.com/jhump/protoreflect v1.15.6/go.mod h1:jCHoyYQIJnaabEYnbGwyo9hUqfyUMTbJw/tAut5t97E=
|
||||
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=
|
||||
@@ -122,8 +120,8 @@ 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 v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
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=
|
||||
@@ -135,28 +133,28 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
|
||||
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=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
|
||||
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
|
||||
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/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
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.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
|
||||
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
|
||||
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
|
||||
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
|
||||
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
|
||||
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/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=
|
||||
@@ -165,15 +163,16 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
@@ -189,12 +188,12 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
|
||||
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||
go.etcd.io/etcd/api/v3 v3.5.11 h1:B54KwXbWDHyD3XYAwprxNzTe7vlhR69LuBgZnMVvS7E=
|
||||
go.etcd.io/etcd/api/v3 v3.5.11/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11 h1:bT2xVspdiCj2910T0V+/KHcVKjkUrCZVtk8J2JF2z1A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.11 h1:ajWtgoNSZJ1gmS8k+icvPtqsqEav+iUorF7b0qozgUU=
|
||||
go.etcd.io/etcd/client/v3 v3.5.11/go.mod h1:a6xQUEqFJ8vztO1agJh/KQKOMfFI8og52ZconzcDJwE=
|
||||
go.etcd.io/etcd/api/v3 v3.5.12 h1:W4sw5ZoU2Juc9gBWuLk5U6fHfNVyY1WC5g9uiXZio/c=
|
||||
go.etcd.io/etcd/api/v3 v3.5.12/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12 h1:EYDL6pWwyOsylrQyLp2w+HkQ46ATiOvoEdMarindU2A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.12 h1:v5lCPXn1pf1Uu3M4laUE2hp/geOTc5uPcYYsNe1lDxg=
|
||||
go.etcd.io/etcd/client/v3 v3.5.12/go.mod h1:tSbBCakoWmmddL+BKVAJHa9km+O/E+bumDe9mSbPiqw=
|
||||
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=
|
||||
@@ -235,8 +234,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
|
||||
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.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
|
||||
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
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=
|
||||
@@ -249,18 +248,17 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
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.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||
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.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
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/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=
|
||||
@@ -274,12 +272,12 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.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.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
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=
|
||||
@@ -296,25 +294,25 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
|
||||
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.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
|
||||
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
|
||||
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-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA=
|
||||
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
|
||||
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
|
||||
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
|
||||
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
|
||||
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
|
||||
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.31.1-0.20231027082548-f4a6c1f6e5c1 h1:fk72uXZyuZiTtW5tgd63jyVK6582lF61nRC/kGv6vCA=
|
||||
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
@@ -324,28 +322,27 @@ gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY=
|
||||
k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0=
|
||||
k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8=
|
||||
k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg=
|
||||
k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY=
|
||||
k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4=
|
||||
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
|
||||
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/api v0.29.2 h1:hBC7B9+MU+ptchxEqTNW2DkUosJpp1P+Wn6YncZ474A=
|
||||
k8s.io/api v0.29.2/go.mod h1:sdIaaKuU7P44aoyyLlikSLayT6Vb7bvJNCX105xZXY0=
|
||||
k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8=
|
||||
k8s.io/apimachinery v0.29.2/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU=
|
||||
k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg=
|
||||
k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA=
|
||||
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=
|
||||
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.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
|
||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||
|
||||
11
readme-cn.md
11
readme-cn.md
@@ -120,12 +120,12 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
|
||||
# docker for amd64 architecture
|
||||
docker pull kevinwan/goctl
|
||||
# run goctl like
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl goctl --help
|
||||
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 goctl --help
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 --help
|
||||
```
|
||||
|
||||
确保 goctl 可执行
|
||||
@@ -298,14 +298,17 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>94. 西安交通大学智慧能源与碳中和研究中心
|
||||
>95. 成都创软科技有限责任公司
|
||||
>96. Sonderbase Technologies
|
||||
>97. 上海荣时信息科技有限公司
|
||||
>98. 上海同犀智能科技有限公司
|
||||
>99. 新华三技术有限公司
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
## 10. CNCF 云原生技术全景图
|
||||
|
||||
<p float="left">
|
||||
<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>
|
||||
<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-landscape-logo.svg" width="150"/>
|
||||
</p>
|
||||
|
||||
go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape.cncf.io/?selected=go-zero)。
|
||||
|
||||
@@ -127,12 +127,12 @@ go get -u github.com/zeromicro/go-zero
|
||||
# docker for amd64 architecture
|
||||
docker pull kevinwan/goctl
|
||||
# run goctl like
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl goctl --help
|
||||
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 goctl --help
|
||||
docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 --help
|
||||
```
|
||||
|
||||
make sure goctl is executable.
|
||||
@@ -248,8 +248,8 @@ Join the chat via https://discord.gg/4JQvC5A4Fe
|
||||
## Cloud Native Landscape
|
||||
|
||||
<p float="left">
|
||||
<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>
|
||||
<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-landscape-logo.svg" width="150"/>
|
||||
</p>
|
||||
|
||||
go-zero enlisted in the [CNCF Cloud Native Landscape](https://landscape.cncf.io/?selected=go-zero).
|
||||
|
||||
@@ -53,7 +53,7 @@ type (
|
||||
MaxBytes int64 `json:",default=1048576"`
|
||||
// milliseconds
|
||||
Timeout int64 `json:",default=3000"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000)"`
|
||||
Signature SignatureConf `json:",optional"`
|
||||
// There are default values for all the items in Middlewares.
|
||||
Middlewares MiddlewaresConf
|
||||
|
||||
@@ -18,7 +18,7 @@ var (
|
||||
Name: "duration_ms",
|
||||
Help: "http server requests duration(ms).",
|
||||
Labels: []string{"path", "method"},
|
||||
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
|
||||
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 750, 1000},
|
||||
})
|
||||
|
||||
metricServerReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{
|
||||
|
||||
@@ -24,6 +24,8 @@ const (
|
||||
reason = "Request Timeout"
|
||||
headerUpgrade = "Upgrade"
|
||||
valueWebsocket = "websocket"
|
||||
headerAccept = "Accept"
|
||||
valueSSE = "text/event-stream"
|
||||
)
|
||||
|
||||
// TimeoutHandler returns the handler with given timeout.
|
||||
@@ -56,7 +58,9 @@ func (h *timeoutHandler) errorBody() string {
|
||||
}
|
||||
|
||||
func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get(headerUpgrade) == valueWebsocket {
|
||||
if r.Header.Get(headerUpgrade) == valueWebsocket ||
|
||||
// Server-Sent Event ignore timeout.
|
||||
r.Header.Get(headerAccept) == valueSSE {
|
||||
h.handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
@@ -110,7 +114,7 @@ func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}
|
||||
io.WriteString(w, h.errorBody())
|
||||
_, _ = io.WriteString(w, h.errorBody())
|
||||
})
|
||||
tw.timedOut = true
|
||||
}
|
||||
|
||||
@@ -156,6 +156,23 @@ func TestTimeoutPanic(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTimeoutSSE(t *testing.T) {
|
||||
timeoutHandler := TimeoutHandler(time.Millisecond)
|
||||
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
r.Header.Set("Content-Type", "text/event-stream")
|
||||
r.Header.Set("Cache-Control", "no-cache")
|
||||
r.Header.Set("Connection", "keep-alive")
|
||||
r.Header.Set("Transfer-Encoding", "chunked")
|
||||
}))
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||
req.Header.Set(headerAccept, valueSSE)
|
||||
resp := httptest.NewRecorder()
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusOK, resp.Code)
|
||||
}
|
||||
|
||||
func TestTimeoutWebsocket(t *testing.T) {
|
||||
timeoutHandler := TimeoutHandler(time.Millisecond)
|
||||
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -395,6 +395,33 @@ func TestParsePathWithDot(t *testing.T) {
|
||||
assert.Equal(t, 18, v.Age)
|
||||
}
|
||||
|
||||
func TestParseWithFloatPtr(t *testing.T) {
|
||||
t.Run("has float32 pointer", func(t *testing.T) {
|
||||
var v struct {
|
||||
WeightFloat32 *float32 `json:"weightFloat32,optional"`
|
||||
}
|
||||
body := `{"weightFloat32": 3.2}`
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
|
||||
r.Header.Set(ContentType, header.JsonContentType)
|
||||
|
||||
if assert.NoError(t, Parse(r, &v)) {
|
||||
assert.Equal(t, float32(3.2), *v.WeightFloat32)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseWithEscapedParams(t *testing.T) {
|
||||
t.Run("escaped", func(t *testing.T) {
|
||||
var v struct {
|
||||
Dev string `form:"dev"`
|
||||
}
|
||||
r := httptest.NewRequest(http.MethodGet, "http://127.0.0.1/api/v2/dev/test?dev=se205%5fy1205%5fj109%26verRelease=v01%26iid1=863494061186673%26iid2=863494061186681%26mcc=636%26mnc=1", http.NoBody)
|
||||
if assert.NoError(t, Parse(r, &v)) {
|
||||
assert.Equal(t, "se205_y1205_j109&verRelease=v01&iid1=863494061186673&iid2=863494061186681&mcc=636&mnc=1", v.Dev)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkParseRaw(b *testing.B) {
|
||||
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
|
||||
if err != nil {
|
||||
|
||||
8
tools/goctl/.dockerignore
Normal file
8
tools/goctl/.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
||||
test/
|
||||
.dockerignore
|
||||
.go-version
|
||||
Dockerfile
|
||||
goctl
|
||||
Makefile
|
||||
readme.md
|
||||
readme-cn.md
|
||||
@@ -8,13 +8,12 @@ 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
|
||||
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||
RUN addgroup -g 1000 -S app && adduser -u 1000 -S app -G app
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go mod download
|
||||
RUN go build -ldflags="-s -w" -o /app/goctl ./goctl.go
|
||||
|
||||
|
||||
@@ -22,13 +21,20 @@ FROM golang:alpine
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache protoc
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||
COPY --from=builder /go/bin/protoc-gen-go /usr/bin/protoc-gen-go
|
||||
COPY --from=builder /go/bin/protoc-gen-go-grpc /usr/bin/protoc-gen-go-grpc
|
||||
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
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/goctl /usr/bin/goctl
|
||||
USER app
|
||||
|
||||
CMD ["goctl"]
|
||||
LABEL org.opencontainers.image.authors="Kevin Wan"
|
||||
LABEL org.opencontainers.image.base.name="docker.io/library/golang:alpine"
|
||||
LABEL org.opencontainers.image.description="A cloud-native Go microservices framework with cli tool for productivity."
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.source="https://github.com/zeromicro/go-zero"
|
||||
LABEL org.opencontainers.image.title="goctl (cli)"
|
||||
LABEL org.opencontainers.image.version="v1.6.2"
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/goctl"]
|
||||
|
||||
@@ -17,9 +17,9 @@ type parser struct {
|
||||
spec *spec.ApiSpec
|
||||
}
|
||||
|
||||
// Parse parses the api file.
|
||||
// Depreacted: use tools/goctl/pkg/parser/api/parser/parser.go:18 instead,
|
||||
// it will be removed in the future.
|
||||
// Parse parses the api file.
|
||||
func Parse(filename string) (*spec.ApiSpec, error) {
|
||||
if env.UseExperimental() {
|
||||
return apiParser.Parse(filename, "")
|
||||
|
||||
@@ -3,27 +3,27 @@ module github.com/zeromicro/go-zero/tools/goctl
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1
|
||||
github.com/emicklei/proto v1.13.0
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/emicklei/proto v1.13.2
|
||||
github.com/fatih/structtag v1.2.0
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/gookit/color v1.5.4
|
||||
github.com/iancoleman/strcase v0.3.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
||||
github.com/zeromicro/antlr v0.0.1
|
||||
github.com/zeromicro/ddl-parser v1.0.5
|
||||
github.com/zeromicro/go-zero v1.6.1
|
||||
github.com/zeromicro/go-zero v1.6.2
|
||||
golang.org/x/text v0.14.0
|
||||
google.golang.org/grpc v1.60.0
|
||||
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1
|
||||
google.golang.org/grpc v1.62.0
|
||||
google.golang.org/protobuf v1.32.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
|
||||
github.com/alicebob/miniredis/v2 v2.31.0 // indirect
|
||||
github.com/alicebob/miniredis/v2 v2.31.1 // indirect
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||
@@ -32,27 +32,25 @@ require (
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // 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
|
||||
github.com/go-openapi/swag v0.22.4 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
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/google/uuid v1.4.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
github.com/jackc/pgx/v5 v5.5.1 // indirect
|
||||
github.com/jackc/pgx/v5 v5.5.2 // 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
|
||||
@@ -60,23 +58,24 @@ require (
|
||||
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/matttproud/golang_protobuf_extensions v1.0.4 // 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/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.17.0 // indirect
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||
github.com/prometheus/common v0.44.0 // indirect
|
||||
github.com/prometheus/procfs v0.11.1 // indirect
|
||||
github.com/prometheus/client_golang v1.18.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/redis/go-redis/v9 v9.4.0 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
github.com/yuin/gopher-lua v1.1.0 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.11 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.11 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.12 // indirect
|
||||
go.opentelemetry.io/otel v1.19.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
|
||||
@@ -92,27 +91,27 @@ require (
|
||||
go.uber.org/automaxprocs v1.5.3 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.16.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/oauth2 v0.13.0 // indirect
|
||||
golang.org/x/sync v0.5.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/term v0.15.0 // indirect
|
||||
golang.org/x/crypto v0.18.0 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/oauth2 v0.16.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
golang.org/x/term v0.16.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/api v0.28.4 // indirect
|
||||
k8s.io/apimachinery v0.28.4 // indirect
|
||||
k8s.io/client-go v0.28.4 // indirect
|
||||
k8s.io/klog/v2 v2.100.1 // indirect
|
||||
k8s.io/api v0.29.1 // indirect
|
||||
k8s.io/apimachinery v0.29.1 // indirect
|
||||
k8s.io/client-go v0.29.1 // indirect
|
||||
k8s.io/klog/v2 v2.110.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.1/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||
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/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0=
|
||||
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.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpSH4c22PU=
|
||||
github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
|
||||
github.com/alicebob/miniredis/v2 v2.31.1 h1:7XAt0uUg3DtwEKW5ZAGa+K7FZV2DdKQo5K/6TTnfX8Y=
|
||||
github.com/alicebob/miniredis/v2 v2.31.1/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
|
||||
github.com/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/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=
|
||||
@@ -29,20 +31,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||
github.com/emicklei/proto v1.13.0 h1:YtC/om6EdkJ0me1JPw4h2g10k+ELITjYFb7tpzm8i8k=
|
||||
github.com/emicklei/proto v1.13.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
|
||||
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
|
||||
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
|
||||
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/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
||||
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/logr v1.2.4/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/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=
|
||||
@@ -52,19 +51,16 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
|
||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
|
||||
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||
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/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
|
||||
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
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.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
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.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
@@ -72,14 +68,15 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
|
||||
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.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=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
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/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
|
||||
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
|
||||
@@ -93,8 +90,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/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.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI=
|
||||
github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
|
||||
github.com/jackc/pgx/v5 v5.5.2 h1:iLlpgp4Cp/gC9Xuscl7lFL1PhhW+ZLtXZcrfCt4C3tA=
|
||||
github.com/jackc/pgx/v5 v5.5.2/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
|
||||
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/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
@@ -119,8 +116,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
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=
|
||||
@@ -128,26 +125,26 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
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/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
|
||||
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
|
||||
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/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
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.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
|
||||
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
|
||||
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
|
||||
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
|
||||
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
|
||||
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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
@@ -158,15 +155,16 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1 h1:+dBg5k7nuTE38VVdoroRsT0Z88fmvdYrI2EjzJst35I=
|
||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1/go.mod h1:nmuySobZb4kFgFy6BptpXp/BBw+xFSyvVPP6auoJB4k=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
@@ -181,14 +179,14 @@ github.com/zeromicro/antlr v0.0.1 h1:CQpIn/dc0pUjgGQ81y98s/NGOm2Hfru2NNio2I9mQgk
|
||||
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
||||
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
||||
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/go-zero v1.6.1 h1:E8fRkMPiYODk8+jUIrxQQIEG+MTgWfXKiH7sjc9l6Vs=
|
||||
github.com/zeromicro/go-zero v1.6.1/go.mod h1:slLvzqPP/H/h9ABq9ykNOuX6pYLjA8Uy3Rb8adkXTGw=
|
||||
go.etcd.io/etcd/api/v3 v3.5.11 h1:B54KwXbWDHyD3XYAwprxNzTe7vlhR69LuBgZnMVvS7E=
|
||||
go.etcd.io/etcd/api/v3 v3.5.11/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11 h1:bT2xVspdiCj2910T0V+/KHcVKjkUrCZVtk8J2JF2z1A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.11 h1:ajWtgoNSZJ1gmS8k+icvPtqsqEav+iUorF7b0qozgUU=
|
||||
go.etcd.io/etcd/client/v3 v3.5.11/go.mod h1:a6xQUEqFJ8vztO1agJh/KQKOMfFI8og52ZconzcDJwE=
|
||||
github.com/zeromicro/go-zero v1.6.2 h1:c1gXp6JTO0e+dtfwNZRE7OZgzjipfW8i1iBMoBnDwBI=
|
||||
github.com/zeromicro/go-zero v1.6.2/go.mod h1:mQKK/c/er/sbIAo7DWyFBZX8oa0eOkc7QJdG15b2GBw=
|
||||
go.etcd.io/etcd/api/v3 v3.5.12 h1:W4sw5ZoU2Juc9gBWuLk5U6fHfNVyY1WC5g9uiXZio/c=
|
||||
go.etcd.io/etcd/api/v3 v3.5.12/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12 h1:EYDL6pWwyOsylrQyLp2w+HkQ46ATiOvoEdMarindU2A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.12/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.12 h1:v5lCPXn1pf1Uu3M4laUE2hp/geOTc5uPcYYsNe1lDxg=
|
||||
go.etcd.io/etcd/client/v3 v3.5.12/go.mod h1:tSbBCakoWmmddL+BKVAJHa9km+O/E+bumDe9mSbPiqw=
|
||||
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.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
||||
@@ -224,8 +222,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-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.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
|
||||
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
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=
|
||||
@@ -237,18 +235,17 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||
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.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
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/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=
|
||||
@@ -260,14 +257,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
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.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.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.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
@@ -282,53 +278,52 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
|
||||
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.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
|
||||
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
|
||||
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-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA=
|
||||
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
|
||||
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
|
||||
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
|
||||
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
|
||||
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
|
||||
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.31.1-0.20231027082548-f4a6c1f6e5c1 h1:fk72uXZyuZiTtW5tgd63jyVK6582lF61nRC/kGv6vCA=
|
||||
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY=
|
||||
k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0=
|
||||
k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8=
|
||||
k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg=
|
||||
k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY=
|
||||
k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4=
|
||||
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
|
||||
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/api v0.29.1 h1:DAjwWX/9YT7NQD4INu49ROJuZAAAP/Ijki48GUPzxqw=
|
||||
k8s.io/api v0.29.1/go.mod h1:7Kl10vBRUXhnQQI8YR/R327zXC8eJ7887/+Ybta+RoQ=
|
||||
k8s.io/apimachinery v0.29.1 h1:KY4/E6km/wLBguvCZv8cKTeOwwOBqFNjwJIdMkMbbRc=
|
||||
k8s.io/apimachinery v0.29.1/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU=
|
||||
k8s.io/client-go v0.29.1 h1:19B/+2NGEwnFLzt0uB5kNJnfTsbV8w6TgQRz9l7ti7A=
|
||||
k8s.io/client-go v0.29.1/go.mod h1:TDG/psL9hdet0TI9mGyHJSgRkW3H9JZk2dNEUS7bRks=
|
||||
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=
|
||||
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.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
|
||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildVersion is the version of goctl.
|
||||
const BuildVersion = "1.6.1"
|
||||
const BuildVersion = "1.6.2"
|
||||
|
||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||
|
||||
|
||||
@@ -192,7 +192,10 @@ func Test_genPublicModel(t *testing.T) {
|
||||
code, err := g.genModelCustom(*tables[0], false)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.Contains(code, "package model"))
|
||||
assert.True(t, strings.Contains(code, "TestUserModel interface {\n\t\ttestUserModel\n\t}\n"))
|
||||
assert.True(t, strings.Contains(code, ` TestUserModel interface {
|
||||
testUserModel
|
||||
withSession(session sqlx.Session) TestUserModel
|
||||
}`))
|
||||
assert.True(t, strings.Contains(code, "customTestUserModel struct {\n\t\t*defaultTestUserModel\n\t}\n"))
|
||||
assert.True(t, strings.Contains(code, "func NewTestUserModel(conn sqlx.SqlConn) TestUserModel {"))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx co
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
{{if .containsPQ}}"github.com/lib/pq"{{end}}
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
@@ -84,6 +84,20 @@ func (t *TokenNode) SetLeadingCommentGroup(cg CommentGroup) {
|
||||
t.LeadingCommentGroup = cg
|
||||
}
|
||||
|
||||
// RawText returns the node's raw text.
|
||||
func (t *TokenNode) RawText() string {
|
||||
text := t.Token.Text
|
||||
if strings.HasPrefix(text, "`") {
|
||||
text = strings.TrimPrefix(text, "`")
|
||||
text = strings.TrimSuffix(text, "`")
|
||||
} else if strings.HasPrefix(text, `"`) {
|
||||
text = strings.TrimPrefix(text, `"`)
|
||||
text = strings.TrimSuffix(text, `"`)
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
func (t *TokenNode) HasLeadingCommentGroup() bool {
|
||||
return t.LeadingCommentGroup.Valid() || t.leadingFlag
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ func (a *Analyzer) astTypeToSpec(in ast.DataType) (spec.Type, error) {
|
||||
}
|
||||
|
||||
func (a *Analyzer) convert2Spec() error {
|
||||
a.fillInfo()
|
||||
|
||||
if err := a.fillTypes(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -128,7 +130,7 @@ func (a *Analyzer) convert2Spec() error {
|
||||
groups = append(groups, v)
|
||||
}
|
||||
sort.SliceStable(groups, func(i, j int) bool {
|
||||
return groups[i].Annotation.Properties["group"] < groups[j].Annotation.Properties["group"]
|
||||
return groups[i].Annotation.Properties[groupKeyText] < groups[j].Annotation.Properties[groupKeyText]
|
||||
})
|
||||
a.spec.Service.Groups = groups
|
||||
|
||||
@@ -150,8 +152,13 @@ func (a *Analyzer) convertKV(kv []*ast.KVExpr) map[string]string {
|
||||
var ret = map[string]string{}
|
||||
for _, v := range kv {
|
||||
key := strings.TrimSuffix(v.Key.Token.Text, ":")
|
||||
ret[key] = v.Value.Token.Text
|
||||
if key == summaryKeyText {
|
||||
ret[key] = v.Value.RawText()
|
||||
} else {
|
||||
ret[key] = v.Value.Token.Text
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -270,6 +277,27 @@ func (a *Analyzer) fillService() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Analyzer) fillInfo() {
|
||||
properties := make(map[string]string)
|
||||
if a.api.info != nil {
|
||||
for _, kv := range a.api.info.Values {
|
||||
key := kv.Key.Token.Text
|
||||
properties[strings.TrimSuffix(key, ":")] = kv.Value.RawText()
|
||||
}
|
||||
}
|
||||
a.spec.Info.Properties = properties
|
||||
infoKeyValue := make(map[string]string)
|
||||
for key, value := range properties {
|
||||
titleKey := strings.Title(strings.TrimSuffix(key, ":"))
|
||||
infoKeyValue[titleKey] = value
|
||||
}
|
||||
a.spec.Info.Title = infoKeyValue[infoTitleKey]
|
||||
a.spec.Info.Desc = infoKeyValue[infoDescKey]
|
||||
a.spec.Info.Version = infoKeyValue[infoVersionKey]
|
||||
a.spec.Info.Author = infoKeyValue[infoAuthorKey]
|
||||
a.spec.Info.Email = infoKeyValue[infoEmailKey]
|
||||
}
|
||||
|
||||
func (a *Analyzer) fillTypes() error {
|
||||
for _, item := range a.api.TypeStmt {
|
||||
switch v := (item).(type) {
|
||||
@@ -403,6 +431,9 @@ func Parse(filename string, src interface{}) (*spec.ApiSpec, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := api.SelfCheck(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result = new(spec.ApiSpec)
|
||||
analyzer := Analyzer{
|
||||
|
||||
@@ -9,14 +9,40 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/assertx"
|
||||
)
|
||||
|
||||
func Test_Parse(t *testing.T) {
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/example.api", nil)
|
||||
apiSpec, err := Parse("./testdata/example.api", nil)
|
||||
assert.Nil(t, err)
|
||||
ast := assert.New(t)
|
||||
ast.Equal(spec.Info{
|
||||
Title: "type title here",
|
||||
Desc: "type desc here",
|
||||
Version: "type version here",
|
||||
Author: "type author here",
|
||||
Email: "type email here",
|
||||
Properties: map[string]string{
|
||||
"title": "type title here",
|
||||
"desc": "type desc here",
|
||||
"version": "type version here",
|
||||
"author": "type author here",
|
||||
"email": "type email here",
|
||||
},
|
||||
}, apiSpec.Info)
|
||||
ast.True(func() bool {
|
||||
for _, group := range apiSpec.Service.Groups {
|
||||
value, ok := group.Annotation.Properties["summary"]
|
||||
if ok {
|
||||
return value == "test"
|
||||
}
|
||||
}
|
||||
return false
|
||||
}())
|
||||
})
|
||||
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
data, err := os.ReadFile("./testdata/invalid.api")
|
||||
assert.NoError(t, err)
|
||||
@@ -38,8 +64,19 @@ func Test_Parse(t *testing.T) {
|
||||
assertx.Error(t, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("circleImport", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/base.api", nil)
|
||||
assertx.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("link_import", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/link_import.api", nil)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("duplicate_types", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/duplicate_type.api", nil)
|
||||
assertx.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
|
||||
)
|
||||
|
||||
const (
|
||||
atServerGroupKey = "group:"
|
||||
atServerPrefixKey = "prefix:"
|
||||
)
|
||||
|
||||
// API is the parsed api file.
|
||||
type API struct {
|
||||
Filename string
|
||||
@@ -80,15 +85,12 @@ func convert2API(a *ast.AST, importSet map[string]lang.PlaceholderType, is *impo
|
||||
}
|
||||
}
|
||||
|
||||
if err := api.SelfCheck(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return api, nil
|
||||
}
|
||||
|
||||
func (api *API) checkImportStmt() error {
|
||||
f := newFilter()
|
||||
b := f.addCheckItem("import value expression")
|
||||
b := f.addCheckItem(api.Filename, "import value expression")
|
||||
for _, v := range api.importStmt {
|
||||
switch val := v.(type) {
|
||||
case *ast.ImportLiteralStmt:
|
||||
@@ -105,7 +107,7 @@ func (api *API) checkInfoStmt() error {
|
||||
return nil
|
||||
}
|
||||
f := newFilter()
|
||||
b := f.addCheckItem("info key expression")
|
||||
b := f.addCheckItem(api.Filename, "info key expression")
|
||||
for _, v := range api.info.Values {
|
||||
b.check(v.Key)
|
||||
}
|
||||
@@ -114,9 +116,9 @@ func (api *API) checkInfoStmt() error {
|
||||
|
||||
func (api *API) checkServiceStmt() error {
|
||||
f := newFilter()
|
||||
serviceNameChecker := f.addCheckItem("service name expression")
|
||||
handlerChecker := f.addCheckItem("handler expression")
|
||||
pathChecker := f.addCheckItem("path expression")
|
||||
serviceNameChecker := f.addCheckItem(api.Filename, "service name expression")
|
||||
handlerChecker := f.addCheckItem(api.Filename, "handler expression")
|
||||
pathChecker := f.addCheckItem(api.Filename, "path expression")
|
||||
var serviceName = map[string]string{}
|
||||
for _, v := range api.ServiceStmts {
|
||||
name := strings.TrimSuffix(v.Name.Format(""), "-api")
|
||||
@@ -127,10 +129,13 @@ func (api *API) checkServiceStmt() error {
|
||||
} else {
|
||||
serviceName[name] = name
|
||||
}
|
||||
var group = api.getAtServerValue(v.AtServerStmt, "prefix")
|
||||
var (
|
||||
prefix = api.getAtServerValue(v.AtServerStmt, atServerPrefixKey)
|
||||
group = api.getAtServerValue(v.AtServerStmt, atServerGroupKey)
|
||||
)
|
||||
for _, item := range v.Routes {
|
||||
handlerChecker.check(item.AtHandler.Name)
|
||||
path := fmt.Sprintf("[%s]:%s", group, item.Route.Format(""))
|
||||
handlerChecker.checkNodeWithPrefix(group, item.AtHandler.Name)
|
||||
path := fmt.Sprintf("[%s]:%s", prefix, item.Route.Format(""))
|
||||
pathChecker.check(ast.NewTokenNode(token.Token{
|
||||
Text: path,
|
||||
Position: item.Route.Pos(),
|
||||
@@ -142,7 +147,7 @@ func (api *API) checkServiceStmt() error {
|
||||
|
||||
func (api *API) checkTypeStmt() error {
|
||||
f := newFilter()
|
||||
b := f.addCheckItem("type expression")
|
||||
b := f.addCheckItem(api.Filename, "type expression")
|
||||
for _, v := range api.TypeStmt {
|
||||
switch val := v.(type) {
|
||||
case *ast.TypeLiteralStmt:
|
||||
|
||||
@@ -1,22 +1,37 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/ast"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/placeholder"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
|
||||
)
|
||||
|
||||
type filterBuilder struct {
|
||||
m map[string]placeholder.Type
|
||||
filename string
|
||||
m map[string]token.Position
|
||||
checkExprName string
|
||||
errorManager *errorManager
|
||||
}
|
||||
|
||||
func (b *filterBuilder) check(nodes ...*ast.TokenNode) {
|
||||
for _, node := range nodes {
|
||||
if _, ok := b.m[node.Token.Text]; ok {
|
||||
fileNodeText := fmt.Sprintf("%s/%s", b.filename, node.Token.Text)
|
||||
if pos, ok := b.m[fileNodeText]; ok && pos != node.Token.Position {
|
||||
b.errorManager.add(ast.DuplicateStmtError(node.Pos(), "duplicate "+b.checkExprName))
|
||||
} else {
|
||||
b.m[node.Token.Text] = placeholder.PlaceHolder
|
||||
b.m[fileNodeText] = node.Token.Position
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *filterBuilder) checkNodeWithPrefix(prefix string, nodes ...*ast.TokenNode) {
|
||||
for _, node := range nodes {
|
||||
joinText := fmt.Sprintf("%s/%s", prefix, node.Token.Text)
|
||||
if pos, ok := b.m[joinText]; ok && pos != node.Token.Position {
|
||||
b.errorManager.add(ast.DuplicateStmtError(node.Pos(), "duplicate "+b.checkExprName))
|
||||
} else {
|
||||
b.m[joinText] = node.Token.Position
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +48,10 @@ func newFilter() *filter {
|
||||
return &filter{}
|
||||
}
|
||||
|
||||
func (f *filter) addCheckItem(checkExprName string) *filterBuilder {
|
||||
func (f *filter) addCheckItem(filename, checkExprName string) *filterBuilder {
|
||||
b := &filterBuilder{
|
||||
m: make(map[string]placeholder.Type),
|
||||
filename: filename,
|
||||
m: make(map[string]token.Position),
|
||||
checkExprName: checkExprName,
|
||||
errorManager: newErrorManager(),
|
||||
}
|
||||
|
||||
@@ -12,7 +12,17 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
|
||||
)
|
||||
|
||||
const idAPI = "api"
|
||||
const (
|
||||
idAPI = "api"
|
||||
summaryKeyExprText = "summary:"
|
||||
summaryKeyText = "summary"
|
||||
groupKeyText = "group"
|
||||
infoTitleKey = "Title"
|
||||
infoDescKey = "Desc"
|
||||
infoVersionKey = "Version"
|
||||
infoAuthorKey = "Author"
|
||||
infoEmailKey = "Email"
|
||||
)
|
||||
|
||||
// Parser is the parser for api file.
|
||||
type Parser struct {
|
||||
@@ -385,6 +395,9 @@ func (p *Parser) parsePathExpr() *ast.PathExpr {
|
||||
}
|
||||
|
||||
values = append(values, p.curTok)
|
||||
if p.peekTokenIs(token.LPAREN, token.Returns, token.AT_DOC, token.AT_HANDLER, token.SEMICOLON, token.RBRACE) {
|
||||
break
|
||||
}
|
||||
if p.notExpectPeekTokenGotComment(p.curTokenNode().PeekFirstLeadingComment(), token.COLON, token.IDENT, token.INT) {
|
||||
return nil
|
||||
}
|
||||
@@ -1131,7 +1144,7 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
|
||||
|
||||
var valueTok token.Token
|
||||
var leadingCommentGroup ast.CommentGroup
|
||||
if p.notExpectPeekToken(token.QUO, token.DURATION, token.IDENT, token.INT) {
|
||||
if p.notExpectPeekToken(token.QUO, token.DURATION, token.IDENT, token.INT, token.STRING) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1141,13 +1154,27 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
|
||||
}
|
||||
|
||||
slashTok := p.curTok
|
||||
var pathText = slashTok.Text
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
|
||||
idTok := p.curTok
|
||||
pathText += p.curTok.Text
|
||||
if p.peekTokenIs(token.SUB) { // parse abc-efg format
|
||||
if !p.nextToken() {
|
||||
return nil
|
||||
}
|
||||
|
||||
pathText += p.curTok.Text
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
|
||||
pathText += p.curTok.Text
|
||||
}
|
||||
|
||||
valueTok = token.Token{
|
||||
Text: slashTok.Text + idTok.Text,
|
||||
Text: pathText,
|
||||
Position: slashTok.Position,
|
||||
}
|
||||
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
|
||||
@@ -1167,6 +1194,23 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
|
||||
return nil
|
||||
}
|
||||
|
||||
valueTok = p.curTok
|
||||
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
|
||||
node := ast.NewTokenNode(valueTok)
|
||||
node.SetLeadingCommentGroup(leadingCommentGroup)
|
||||
expr.Value = node
|
||||
return expr
|
||||
} else if p.peekTokenIs(token.STRING) {
|
||||
if expr.Key.Token.Text != summaryKeyExprText {
|
||||
if p.notExpectPeekToken(token.QUO, token.DURATION, token.IDENT, token.INT) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if !p.nextToken() {
|
||||
return nil
|
||||
}
|
||||
|
||||
valueTok = p.curTok
|
||||
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
|
||||
node := ast.NewTokenNode(valueTok)
|
||||
@@ -1218,13 +1262,28 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
|
||||
}
|
||||
|
||||
slashTok := p.curTok
|
||||
var pathText = valueTok.Text
|
||||
pathText += slashTok.Text
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
|
||||
idTok := p.curTok
|
||||
pathText += p.curTok.Text
|
||||
if p.peekTokenIs(token.SUB) { // parse abc-efg format
|
||||
if !p.nextToken() {
|
||||
return nil
|
||||
}
|
||||
|
||||
pathText += p.curTok.Text
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
|
||||
pathText += p.curTok.Text
|
||||
}
|
||||
|
||||
valueTok = token.Token{
|
||||
Text: valueTok.Text + slashTok.Text + idTok.Text,
|
||||
Text: pathText,
|
||||
Position: valueTok.Position,
|
||||
}
|
||||
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
|
||||
|
||||
@@ -299,6 +299,11 @@ func TestParser_Parse_atServerStmt(t *testing.T) {
|
||||
"timeout6:": "10ns",
|
||||
"timeout7:": "1h10m10s10ms10µs10ns",
|
||||
"maxBytes:": `1024`,
|
||||
"prefix:": "/v1",
|
||||
"prefix1:": "/v1/v2_test/v2-beta",
|
||||
"prefix2:": "v1/v2_test/v2-beta",
|
||||
"prefix3:": "v1/v2_",
|
||||
"summary:": `"test"`,
|
||||
}
|
||||
|
||||
p := New("foo.api", atServerTestAPI)
|
||||
@@ -349,6 +354,8 @@ func TestParser_Parse_atServerStmt(t *testing.T) {
|
||||
`@server(foo:/v1/v2`,
|
||||
`@server(foo: m1,`,
|
||||
`@server(foo: m1,)`,
|
||||
`@server(foo: v1/v2-)`,
|
||||
`@server(foo:"test")`,
|
||||
}
|
||||
for _, v := range testData {
|
||||
p := New("foo.api", v)
|
||||
@@ -521,6 +528,19 @@ func TestParser_Parse_service(t *testing.T) {
|
||||
LBrace: ast.NewTokenNode(token.Token{Type: token.LBRACE, Text: "{"}),
|
||||
RBrace: ast.NewTokenNode(token.Token{Type: token.RBRACE, Text: "}"}),
|
||||
Routes: []*ast.ServiceItemStmt{
|
||||
{
|
||||
AtHandler: &ast.AtHandlerStmt{
|
||||
AtHandler: ast.NewTokenNode(token.Token{Type: token.AT_HANDLER, Text: "@handler"}),
|
||||
Name: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "root"}),
|
||||
},
|
||||
Route: &ast.RouteStmt{
|
||||
Method: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "get"}),
|
||||
Path: &ast.PathExpr{Value: ast.NewTokenNode(token.Token{
|
||||
Type: token.PATH,
|
||||
Text: "/",
|
||||
})},
|
||||
},
|
||||
},
|
||||
{
|
||||
AtHandler: &ast.AtHandlerStmt{
|
||||
AtHandler: ast.NewTokenNode(token.Token{Type: token.AT_HANDLER, Text: "@handler"}),
|
||||
@@ -557,6 +577,93 @@ func TestParser_Parse_service(t *testing.T) {
|
||||
LBrace: ast.NewTokenNode(token.Token{Type: token.LBRACE, Text: "{"}),
|
||||
RBrace: ast.NewTokenNode(token.Token{Type: token.RBRACE, Text: "}"}),
|
||||
Routes: []*ast.ServiceItemStmt{
|
||||
{
|
||||
AtDoc: &ast.AtDocLiteralStmt{
|
||||
AtDoc: ast.NewTokenNode(token.Token{Type: token.AT_DOC, Text: "@doc"}),
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.STRING, Text: `"bar"`}),
|
||||
},
|
||||
AtHandler: &ast.AtHandlerStmt{
|
||||
AtHandler: ast.NewTokenNode(token.Token{Type: token.AT_HANDLER, Text: "@handler"}),
|
||||
Name: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "root"}),
|
||||
},
|
||||
Route: &ast.RouteStmt{
|
||||
Method: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "get"}),
|
||||
Path: &ast.PathExpr{
|
||||
Value: ast.NewTokenNode(token.Token{
|
||||
Type: token.PATH,
|
||||
Text: "/",
|
||||
}),
|
||||
},
|
||||
Request: &ast.BodyStmt{
|
||||
LParen: ast.NewTokenNode(token.Token{Type: token.LPAREN, Text: "("}),
|
||||
Body: &ast.BodyExpr{
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "Foo"}),
|
||||
},
|
||||
RParen: ast.NewTokenNode(token.Token{Type: token.RPAREN, Text: ")"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
AtDoc: &ast.AtDocLiteralStmt{
|
||||
AtDoc: ast.NewTokenNode(token.Token{Type: token.AT_DOC, Text: "@doc"}),
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.STRING, Text: `"bar"`}),
|
||||
},
|
||||
AtHandler: &ast.AtHandlerStmt{
|
||||
AtHandler: ast.NewTokenNode(token.Token{Type: token.AT_HANDLER, Text: "@handler"}),
|
||||
Name: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "root2"}),
|
||||
},
|
||||
Route: &ast.RouteStmt{
|
||||
Method: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "get"}),
|
||||
Path: &ast.PathExpr{
|
||||
Value: ast.NewTokenNode(token.Token{
|
||||
Type: token.PATH,
|
||||
Text: "/",
|
||||
}),
|
||||
},
|
||||
Returns: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "returns"}),
|
||||
Response: &ast.BodyStmt{
|
||||
LParen: ast.NewTokenNode(token.Token{Type: token.LPAREN, Text: "("}),
|
||||
Body: &ast.BodyExpr{
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "Foo"}),
|
||||
},
|
||||
RParen: ast.NewTokenNode(token.Token{Type: token.RPAREN, Text: ")"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
AtDoc: &ast.AtDocLiteralStmt{
|
||||
AtDoc: ast.NewTokenNode(token.Token{Type: token.AT_DOC, Text: "@doc"}),
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.STRING, Text: `"bar"`}),
|
||||
},
|
||||
AtHandler: &ast.AtHandlerStmt{
|
||||
AtHandler: ast.NewTokenNode(token.Token{Type: token.AT_HANDLER, Text: "@handler"}),
|
||||
Name: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "root3"}),
|
||||
},
|
||||
Route: &ast.RouteStmt{
|
||||
Method: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "get"}),
|
||||
Path: &ast.PathExpr{
|
||||
Value: ast.NewTokenNode(token.Token{
|
||||
Type: token.PATH,
|
||||
Text: "/",
|
||||
}),
|
||||
},
|
||||
Request: &ast.BodyStmt{
|
||||
LParen: ast.NewTokenNode(token.Token{Type: token.LPAREN, Text: "("}),
|
||||
Body: &ast.BodyExpr{
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "Foo"}),
|
||||
},
|
||||
RParen: ast.NewTokenNode(token.Token{Type: token.RPAREN, Text: ")"}),
|
||||
},
|
||||
Returns: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "returns"}),
|
||||
Response: &ast.BodyStmt{
|
||||
LParen: ast.NewTokenNode(token.Token{Type: token.LPAREN, Text: "("}),
|
||||
Body: &ast.BodyExpr{
|
||||
Value: ast.NewTokenNode(token.Token{Type: token.IDENT, Text: "Bar"}),
|
||||
},
|
||||
RParen: ast.NewTokenNode(token.Token{Type: token.RPAREN, Text: ")"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
AtDoc: &ast.AtDocLiteralStmt{
|
||||
AtDoc: ast.NewTokenNode(token.Token{Type: token.AT_DOC, Text: "@doc"}),
|
||||
|
||||
@@ -13,4 +13,9 @@
|
||||
timeout6: 10ns
|
||||
timeout7: 1h10m10s10ms10µs10ns
|
||||
maxBytes: 1024
|
||||
)
|
||||
prefix: /v1
|
||||
prefix1: /v1/v2_test/v2-beta
|
||||
prefix2: v1/v2_test/v2-beta
|
||||
prefix3: v1/v2_
|
||||
summary:"test"
|
||||
)
|
||||
|
||||
6
tools/goctl/pkg/parser/api/parser/testdata/base/request.api
vendored
Normal file
6
tools/goctl/pkg/parser/api/parser/testdata/base/request.api
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
syntax = "v1"
|
||||
|
||||
type Baz {
|
||||
Foo string `json:"foo"`
|
||||
Baz bool `json:"bar"`
|
||||
}
|
||||
10
tools/goctl/pkg/parser/api/parser/testdata/base/response.api
vendored
Normal file
10
tools/goctl/pkg/parser/api/parser/testdata/base/response.api
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
syntax = "v1"
|
||||
|
||||
import "request.api"
|
||||
type Bar {
|
||||
Foo int `json:"foo"`
|
||||
Bar bool `json:"bar"`
|
||||
Baz
|
||||
Qux map[string]string `json:"qux"`
|
||||
}
|
||||
|
||||
8
tools/goctl/pkg/parser/api/parser/testdata/duplicate_type.api
vendored
Normal file
8
tools/goctl/pkg/parser/api/parser/testdata/duplicate_type.api
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
syntax = "v1"
|
||||
|
||||
type Example{
|
||||
A string
|
||||
}
|
||||
type Example{
|
||||
B string
|
||||
}
|
||||
@@ -93,6 +93,12 @@ type (
|
||||
NestDemoResp2 {
|
||||
*Nest `json:"nest"`
|
||||
}
|
||||
RootReq{
|
||||
|
||||
}
|
||||
RootResp{
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
@@ -124,6 +130,23 @@ service example {
|
||||
prefix: /v1/v2
|
||||
timeout: 100ms
|
||||
)
|
||||
service example {
|
||||
@doc (
|
||||
desc: "path demo"
|
||||
)
|
||||
@handler postPath
|
||||
post /example/path (PostPathReq) returns (PostPathResp)
|
||||
|
||||
@handler root
|
||||
post / (RootReq) returns (RootResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: path2
|
||||
middleware: Path
|
||||
prefix: /v1/v3
|
||||
timeout: 100ms
|
||||
)
|
||||
service example {
|
||||
@doc (
|
||||
desc: "path demo"
|
||||
@@ -165,3 +188,17 @@ service example {
|
||||
post /example/nest2 (NestDemoReq2) returns (NestDemoResp2)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: /g1/g2_test/g2_beta
|
||||
prefix: /v1/v2_test/v2-beta
|
||||
summary: "test"
|
||||
)
|
||||
service example {
|
||||
@handler nestDemo1
|
||||
post /a/b_c/d-e/:f/123/g (NestDemoReq1) returns (NestDemoResp1)
|
||||
|
||||
@handler nestDemo2
|
||||
post /example/nest2 (NestDemoReq2) returns (NestDemoResp2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
tools/goctl/pkg/parser/api/parser/testdata/example_base.api
vendored
Normal file
3
tools/goctl/pkg/parser/api/parser/testdata/example_base.api
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
syntax = "v1"
|
||||
|
||||
type Base{}
|
||||
@@ -1,5 +1,7 @@
|
||||
syntax = "v1"
|
||||
|
||||
import "example_base.api"
|
||||
|
||||
info(
|
||||
title: "type title here"
|
||||
desc: "type desc here"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
syntax = "v1"
|
||||
|
||||
import "example_base.api"
|
||||
|
||||
info(
|
||||
title: "type title here"
|
||||
desc: "type desc here"
|
||||
|
||||
12
tools/goctl/pkg/parser/api/parser/testdata/link_import.api
vendored
Normal file
12
tools/goctl/pkg/parser/api/parser/testdata/link_import.api
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
syntax = "v1"
|
||||
|
||||
import "base/request.api"
|
||||
import "base/response.api"
|
||||
|
||||
type Foo {}
|
||||
|
||||
service demo {
|
||||
@handler handlerName
|
||||
get /users/id/:userId (Baz) returns (Bar)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
service foo {
|
||||
@handler root
|
||||
get /
|
||||
|
||||
@handler bar
|
||||
get /ping
|
||||
|
||||
@@ -7,6 +10,18 @@ service foo {
|
||||
}
|
||||
|
||||
service bar {
|
||||
@doc "bar"
|
||||
@handler root
|
||||
get / (Foo)
|
||||
|
||||
@doc "bar"
|
||||
@handler root2
|
||||
get / returns (Foo)
|
||||
|
||||
@doc "bar"
|
||||
@handler root3
|
||||
get / (Foo) returns (Bar)
|
||||
|
||||
@doc "bar"
|
||||
@handler foo
|
||||
get /foo/:bar (Foo)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -650,7 +651,7 @@ func NewScanner(filename string, src interface{}) (*Scanner, error) {
|
||||
}
|
||||
|
||||
func readData(filename string, src interface{}) ([]byte, error) {
|
||||
if strings.HasSuffix(filename, ".api") {
|
||||
if strings.HasSuffix(filename, ".api") && pathx.FileExists(filename) {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"go/build"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -51,12 +50,7 @@ func TestRpcGenerate(t *testing.T) {
|
||||
err = g.Generate(ctx)
|
||||
assert.Nil(t, err)
|
||||
_, err = execx.Run("go test "+projectName, projectDir)
|
||||
if err != nil {
|
||||
assert.True(t, func() bool {
|
||||
return strings.Contains(err.Error(),
|
||||
"not in GOROOT") || strings.Contains(err.Error(), "cannot find package")
|
||||
}())
|
||||
}
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
// case go mod
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
FROM golang:1.19
|
||||
FROM golang:1.22-alpine
|
||||
|
||||
ENV TZ Asia/Shanghai
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
WORKDIR /app
|
||||
ADD goctl /usr/bin/goctl
|
||||
ADD cmd.sh .
|
||||
COPY goctl /usr/bin/
|
||||
COPY cmd.sh .
|
||||
|
||||
RUN chmod +x /usr/bin/goctl
|
||||
RUN chmod +x cmd.sh
|
||||
RUN chmod +x /usr/bin/goctl cmd.sh
|
||||
CMD ["/bin/bash", "cmd.sh"]
|
||||
|
||||
@@ -25,7 +25,7 @@ fi
|
||||
|
||||
# run docker image
|
||||
console_step "docker running"
|
||||
docker run $image
|
||||
docker run --rm $image
|
||||
if [ $? -ne 0 ]; then
|
||||
rm -f $buildFile
|
||||
console_red "docker run failed"
|
||||
|
||||
@@ -43,7 +43,7 @@ type (
|
||||
StrictControl bool `json:",optional"`
|
||||
// setting 0 means no timeout
|
||||
Timeout int64 `json:",default=2000"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
||||
CpuThreshold int64 `json:",default=900,range=[0:1000)"`
|
||||
// grpc health check switch
|
||||
Health bool `json:",default=true"`
|
||||
Middlewares ServerMiddlewaresConf
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -27,3 +28,12 @@ func TestUnaryBreakerInterceptor(t *testing.T) {
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestUnaryBreakerInterceptor_Unavailable(t *testing.T) {
|
||||
_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
|
||||
FullMethod: "any",
|
||||
}, func(_ context.Context, _ any) (any, error) {
|
||||
return nil, breaker.ErrServiceUnavailable
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user