mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 08:50:00 +08:00
Compare commits
40 Commits
v1.3.1
...
tools/goct
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
448029aa4b | ||
|
|
17e0afeac0 | ||
|
|
18916b5189 | ||
|
|
c11a09be23 | ||
|
|
56e1ecf2f3 | ||
|
|
f9e6013a6c | ||
|
|
b5d1d8b0d1 | ||
|
|
09e6d94f9e | ||
|
|
2a5717d7fb | ||
|
|
85cf662c6f | ||
|
|
3279a7ef0f | ||
|
|
fec908a19b | ||
|
|
f5ed0cda58 | ||
|
|
cc9d16f505 | ||
|
|
c05d74b44c | ||
|
|
32c88b6352 | ||
|
|
7dabec260f | ||
|
|
4feb88f9b5 | ||
|
|
2776caed0e | ||
|
|
c55694d957 | ||
|
|
209ffb934b | ||
|
|
26a33932cd | ||
|
|
d6a692971f | ||
|
|
4624390e54 | ||
|
|
63b7d292c1 | ||
|
|
365c569d7c | ||
|
|
68a81fea8a | ||
|
|
08a8bd7ef7 | ||
|
|
b939ce75ba | ||
|
|
3b7ca86e4f | ||
|
|
60760b52ab | ||
|
|
96c128c58a | ||
|
|
0c35f39a7d | ||
|
|
6a66dde0a1 | ||
|
|
36b9fcba44 | ||
|
|
bf99dda620 | ||
|
|
511dfcb409 | ||
|
|
900bc96420 | ||
|
|
be277a7376 | ||
|
|
f15a4f9188 |
@@ -23,6 +23,6 @@ We hope that the items listed below will inspire further engagement from the com
|
||||
- [x] Support `context` in redis related methods for timeout and tracing
|
||||
- [x] Support `context` in sql related methods for timeout and tracing
|
||||
- [ ] Support `context` in mongodb related methods for timeout and tracing
|
||||
- [ ] Add `httpx.Client` with governance, like circuit breaker etc.
|
||||
- [x] Add `httpc.Do` with HTTP call governance, like circuit breaker etc.
|
||||
- [ ] Support `goctl doctor` command to report potential issues for given service
|
||||
- [ ] Support `goctl mock` command to start a mocking server with given `.api` file
|
||||
|
||||
@@ -171,7 +171,7 @@ func (lt loggedThrottle) allow() (Promise, error) {
|
||||
func (lt loggedThrottle) doReq(req func() error, fallback func(err error) error, acceptable Acceptable) error {
|
||||
return lt.logError(lt.internalThrottle.doReq(req, fallback, func(err error) bool {
|
||||
accept := acceptable(err)
|
||||
if !accept {
|
||||
if !accept && err != nil {
|
||||
lt.errWin.add(err.Error())
|
||||
}
|
||||
return accept
|
||||
|
||||
@@ -14,8 +14,8 @@ local window = tonumber(ARGV[2])
|
||||
local current = redis.call("INCRBY", KEYS[1], 1)
|
||||
if current == 1 then
|
||||
redis.call("expire", KEYS[1], window)
|
||||
return 1
|
||||
elseif current < limit then
|
||||
end
|
||||
if current < limit then
|
||||
return 1
|
||||
elseif current == limit then
|
||||
return 2
|
||||
|
||||
@@ -65,3 +65,13 @@ func testPeriodLimit(t *testing.T, opts ...PeriodOption) {
|
||||
assert.Equal(t, 1, hitQuota)
|
||||
assert.Equal(t, total-quota, overQuota)
|
||||
}
|
||||
|
||||
func TestQuotaFull(t *testing.T) {
|
||||
s, err := miniredis.Run()
|
||||
assert.Nil(t, err)
|
||||
|
||||
l := NewPeriodLimit(1, 1, redis.New(s.Addr()), "periodlimit")
|
||||
val, err := l.Take("first")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, HitQuota, val)
|
||||
}
|
||||
|
||||
@@ -1,78 +1,129 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/iox"
|
||||
"github.com/zeromicro/go-zero/core/lang"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const cgroupDir = "/sys/fs/cgroup"
|
||||
const (
|
||||
cgroupDir = "/sys/fs/cgroup"
|
||||
cpuStatFile = cgroupDir + "/cpu.stat"
|
||||
cpusetFile = cgroupDir + "/cpuset.cpus.effective"
|
||||
)
|
||||
|
||||
type cgroup struct {
|
||||
var (
|
||||
isUnifiedOnce sync.Once
|
||||
isUnified bool
|
||||
inUserNS bool
|
||||
nsOnce sync.Once
|
||||
)
|
||||
|
||||
type cgroup interface {
|
||||
cpuQuotaUs() (int64, error)
|
||||
cpuPeriodUs() (uint64, error)
|
||||
cpus() ([]uint64, error)
|
||||
usageAllCpus() (uint64, error)
|
||||
}
|
||||
|
||||
func currentCgroup() (cgroup, error) {
|
||||
if isCgroup2UnifiedMode() {
|
||||
return currentCgroupV2()
|
||||
}
|
||||
|
||||
return currentCgroupV1()
|
||||
}
|
||||
|
||||
type cgroupV1 struct {
|
||||
cgroups map[string]string
|
||||
}
|
||||
|
||||
func (c *cgroup) acctUsageAllCpus() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuacct"], "cpuacct.usage"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUint(string(data))
|
||||
}
|
||||
|
||||
func (c *cgroup) acctUsagePerCpu() ([]uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuacct"], "cpuacct.usage_percpu"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var usage []uint64
|
||||
for _, v := range strings.Fields(string(data)) {
|
||||
u, err := parseUint(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
usage = append(usage, u)
|
||||
}
|
||||
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
func (c *cgroup) cpuQuotaUs() (int64, error) {
|
||||
func (c *cgroupV1) cpuQuotaUs() (int64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpu"], "cpu.cfs_quota_us"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(string(data), 10, 64)
|
||||
return strconv.ParseInt(data, 10, 64)
|
||||
}
|
||||
|
||||
func (c *cgroup) cpuPeriodUs() (uint64, error) {
|
||||
func (c *cgroupV1) cpuPeriodUs() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpu"], "cpu.cfs_period_us"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUint(string(data))
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
func (c *cgroup) cpus() ([]uint64, error) {
|
||||
func (c *cgroupV1) cpus() ([]uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuset"], "cpuset.cpus"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseUints(string(data))
|
||||
return parseUints(data)
|
||||
}
|
||||
|
||||
func currentCgroup() (*cgroup, error) {
|
||||
func (c *cgroupV1) usageAllCpus() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(c.cgroups["cpuacct"], "cpuacct.usage"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
type cgroupV2 struct {
|
||||
cgroups map[string]string
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpuQuotaUs() (int64, error) {
|
||||
data, err := iox.ReadText(path.Join(cgroupDir, "cpu.cfs_quota_us"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(data, 10, 64)
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpuPeriodUs() (uint64, error) {
|
||||
data, err := iox.ReadText(path.Join(cgroupDir, "cpu.cfs_period_us"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return parseUint(data)
|
||||
}
|
||||
|
||||
func (c *cgroupV2) cpus() ([]uint64, error) {
|
||||
data, err := iox.ReadText(cpusetFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseUints(data)
|
||||
}
|
||||
|
||||
func (c *cgroupV2) usageAllCpus() (uint64, error) {
|
||||
usec, err := parseUint(c.cgroups["usage_usec"])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return usec * uint64(time.Microsecond), nil
|
||||
}
|
||||
|
||||
func currentCgroupV1() (cgroup, error) {
|
||||
cgroupFile := fmt.Sprintf("/proc/%d/cgroup", os.Getpid())
|
||||
lines, err := iox.ReadTextLines(cgroupFile, iox.WithoutBlank())
|
||||
if err != nil {
|
||||
@@ -100,11 +151,51 @@ func currentCgroup() (*cgroup, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return &cgroup{
|
||||
return &cgroupV1{
|
||||
cgroups: cgroups,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func currentCgroupV2() (cgroup, error) {
|
||||
lines, err := iox.ReadTextLines(cpuStatFile, iox.WithoutBlank())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cgroups := make(map[string]string)
|
||||
for _, line := range lines {
|
||||
cols := strings.Fields(line)
|
||||
if len(cols) != 2 {
|
||||
return nil, fmt.Errorf("invalid cgroupV2 line: %s", line)
|
||||
}
|
||||
|
||||
cgroups[cols[0]] = cols[1]
|
||||
}
|
||||
|
||||
return &cgroupV2{
|
||||
cgroups: cgroups,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// isCgroup2UnifiedMode returns whether we are running in cgroup v2 unified mode.
|
||||
func isCgroup2UnifiedMode() bool {
|
||||
isUnifiedOnce.Do(func() {
|
||||
var st unix.Statfs_t
|
||||
err := unix.Statfs(cgroupDir, &st)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) && runningInUserNS() {
|
||||
// ignore the "not found" error if running in userns
|
||||
isUnified = false
|
||||
return
|
||||
}
|
||||
panic(fmt.Sprintf("cannot statfs cgroup root: %s", err))
|
||||
}
|
||||
isUnified = st.Type == unix.CGROUP2_SUPER_MAGIC
|
||||
})
|
||||
|
||||
return isUnified
|
||||
}
|
||||
|
||||
func parseUint(s string) (uint64, error) {
|
||||
v, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
@@ -166,3 +257,36 @@ func parseUints(val string) ([]uint64, error) {
|
||||
|
||||
return sets, nil
|
||||
}
|
||||
|
||||
// runningInUserNS detects whether we are currently running in a user namespace.
|
||||
func runningInUserNS() bool {
|
||||
nsOnce.Do(func() {
|
||||
file, err := os.Open("/proc/self/uid_map")
|
||||
if err != nil {
|
||||
// This kernel-provided file only exists if user namespaces are supported
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
buf := bufio.NewReader(file)
|
||||
l, _, err := buf.ReadLine()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
line := string(l)
|
||||
var a, b, c int64
|
||||
fmt.Sscanf(line, "%d %d %d", &a, &b, &c)
|
||||
|
||||
/*
|
||||
* We assume we are in the initial user namespace if we have a full
|
||||
* range - 4294967295 uids starting at uid 0.
|
||||
*/
|
||||
if a == 0 && b == 0 && c == 4294967295 {
|
||||
return
|
||||
}
|
||||
inUserNS = true
|
||||
})
|
||||
|
||||
return inUserNS
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
|
||||
// if /proc not present, ignore the cpu calculation, like wsl linux
|
||||
func init() {
|
||||
cpus, err := perCpuUsage()
|
||||
cpus, err := cpuSets()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
@@ -117,15 +117,6 @@ func cpuSets() ([]uint64, error) {
|
||||
return cg.cpus()
|
||||
}
|
||||
|
||||
func perCpuUsage() ([]uint64, error) {
|
||||
cg, err := currentCgroup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cg.acctUsagePerCpu()
|
||||
}
|
||||
|
||||
func systemCpuUsage() (uint64, error) {
|
||||
lines, err := iox.ReadTextLines("/proc/stat", iox.WithoutBlank())
|
||||
if err != nil {
|
||||
@@ -157,10 +148,10 @@ func systemCpuUsage() (uint64, error) {
|
||||
}
|
||||
|
||||
func totalCpuUsage() (usage uint64, err error) {
|
||||
var cg *cgroup
|
||||
var cg cgroup
|
||||
if cg, err = currentCgroup(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return cg.acctUsageAllCpus()
|
||||
return cg.usageAllCpus()
|
||||
}
|
||||
|
||||
@@ -30,18 +30,22 @@ func RawFieldNames(in interface{}, postgresSql ...bool) []string {
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// gets us a StructField
|
||||
fi := typ.Field(i)
|
||||
if tagv := fi.Tag.Get(dbTag); tagv != "" {
|
||||
if pg {
|
||||
out = append(out, tagv)
|
||||
} else {
|
||||
out = append(out, fmt.Sprintf("`%s`", tagv))
|
||||
}
|
||||
} else {
|
||||
tagv := fi.Tag.Get(dbTag)
|
||||
switch tagv {
|
||||
case "-":
|
||||
continue
|
||||
case "":
|
||||
if pg {
|
||||
out = append(out, fi.Name)
|
||||
} else {
|
||||
out = append(out, fmt.Sprintf("`%s`", fi.Name))
|
||||
}
|
||||
default:
|
||||
if pg {
|
||||
out = append(out, tagv)
|
||||
} else {
|
||||
out = append(out, fmt.Sprintf("`%s`", tagv))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ var (
|
||||
ErrNotFound = mgo.ErrNotFound
|
||||
|
||||
// can't use one SingleFlight per conn, because multiple conns may share the same cache key.
|
||||
sharedCalls = syncx.NewSingleFlight()
|
||||
stats = cache.NewStat("mongoc")
|
||||
singleFlight = syncx.NewSingleFlight()
|
||||
stats = cache.NewStat("mongoc")
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestCollection_Count(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer clean()
|
||||
|
||||
cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound)
|
||||
cach := cache.NewNode(r, singleFlight, stats, mgo.ErrNotFound)
|
||||
c := newCollection(dummyConn{}, cach)
|
||||
val, err := c.Count("any")
|
||||
assert.Nil(t, err)
|
||||
@@ -98,7 +98,7 @@ func TestStat(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer clean()
|
||||
|
||||
cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound)
|
||||
cach := cache.NewNode(r, singleFlight, stats, mgo.ErrNotFound)
|
||||
c := newCollection(dummyConn{}, cach).(*cachedCollection)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
@@ -121,7 +121,7 @@ func TestStatCacheFails(t *testing.T) {
|
||||
defer log.SetOutput(os.Stdout)
|
||||
|
||||
r := redis.New("localhost:59999")
|
||||
cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound)
|
||||
cach := cache.NewNode(r, singleFlight, stats, mgo.ErrNotFound)
|
||||
c := newCollection(dummyConn{}, cach)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
@@ -142,7 +142,7 @@ func TestStatDbFails(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer clean()
|
||||
|
||||
cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound)
|
||||
cach := cache.NewNode(r, singleFlight, stats, mgo.ErrNotFound)
|
||||
c := newCollection(dummyConn{}, cach).(*cachedCollection)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
@@ -164,7 +164,7 @@ func TestStatFromMemory(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer clean()
|
||||
|
||||
cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound)
|
||||
cach := cache.NewNode(r, singleFlight, stats, mgo.ErrNotFound)
|
||||
c := newCollection(dummyConn{}, cach).(*cachedCollection)
|
||||
|
||||
var all sync.WaitGroup
|
||||
|
||||
@@ -38,7 +38,7 @@ func MustNewModel(url, collection string, c cache.CacheConf, opts ...cache.Optio
|
||||
|
||||
// NewModel returns a Model with a cache cluster.
|
||||
func NewModel(url, collection string, conf cache.CacheConf, opts ...cache.Option) (*Model, error) {
|
||||
c := cache.New(conf, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
||||
c := cache.New(conf, singleFlight, stats, mgo.ErrNotFound, opts...)
|
||||
return NewModelWithCache(url, collection, c)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewModelWithCache(url, collection string, c cache.Cache) (*Model, error) {
|
||||
|
||||
// NewNodeModel returns a Model with a cache node.
|
||||
func NewNodeModel(url, collection string, rds *redis.Redis, opts ...cache.Option) (*Model, error) {
|
||||
c := cache.NewNode(rds, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
||||
c := cache.NewNode(rds, singleFlight, stats, mgo.ErrNotFound, opts...)
|
||||
return NewModelWithCache(url, collection, c)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ type (
|
||||
|
||||
// A BulkInserter is used to batch insert records.
|
||||
// Postgresql is not supported yet, because of the sql is formated with symbol `$`.
|
||||
// Oracle is not supported yet, because of the sql is formated with symbol `:`.
|
||||
BulkInserter struct {
|
||||
executor *executors.PeriodicalExecutor
|
||||
inserter *dbInserter
|
||||
|
||||
@@ -67,7 +67,7 @@ func format(query string, args ...interface{}) (string, error) {
|
||||
|
||||
writeValue(&b, args[argIndex])
|
||||
argIndex++
|
||||
case '$':
|
||||
case ':', '$':
|
||||
var j int
|
||||
for j = i + 1; j < bytes; j++ {
|
||||
char := query[j]
|
||||
@@ -81,10 +81,11 @@ func format(query string, args ...interface{}) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// index starts from 1 for pg
|
||||
// index starts from 1 for pg or oracle
|
||||
if index > argIndex {
|
||||
argIndex = index
|
||||
}
|
||||
|
||||
index--
|
||||
if index < 0 || numArgs <= index {
|
||||
return "", fmt.Errorf("error: wrong index %d in sql", index)
|
||||
|
||||
@@ -73,6 +73,30 @@ func TestFormat(t *testing.T) {
|
||||
args: []interface{}{"133", false},
|
||||
hasErr: true,
|
||||
},
|
||||
{
|
||||
name: "oracle normal",
|
||||
query: "select name, age from users where bool=:1 and phone=:2",
|
||||
args: []interface{}{true, "133"},
|
||||
expect: "select name, age from users where bool=1 and phone='133'",
|
||||
},
|
||||
{
|
||||
name: "oracle normal reverse",
|
||||
query: "select name, age from users where bool=:2 and phone=:1",
|
||||
args: []interface{}{"133", false},
|
||||
expect: "select name, age from users where bool=0 and phone='133'",
|
||||
},
|
||||
{
|
||||
name: "oracle error not number",
|
||||
query: "select name, age from users where bool=:a and phone=:1",
|
||||
args: []interface{}{"133", false},
|
||||
hasErr: true,
|
||||
},
|
||||
{
|
||||
name: "oracle error more args",
|
||||
query: "select name, age from users where bool=:2 and phone=:1 and nickname=:3",
|
||||
args: []interface{}{"133", false},
|
||||
hasErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
@@ -90,14 +90,14 @@ func TestParseFullMethod(t *testing.T) {
|
||||
semconv.RPCMethodKey.String("theMethod"),
|
||||
},
|
||||
}, {
|
||||
fullMethod: "/pkg.srv",
|
||||
name: "pkg.srv",
|
||||
fullMethod: "/pkg.svr",
|
||||
name: "pkg.svr",
|
||||
attr: []attribute.KeyValue(nil),
|
||||
}, {
|
||||
fullMethod: "/pkg.srv/",
|
||||
name: "pkg.srv/",
|
||||
fullMethod: "/pkg.svr/",
|
||||
name: "pkg.svr/",
|
||||
attr: []attribute.KeyValue{
|
||||
semconv.RPCServiceKey.String("pkg.srv"),
|
||||
semconv.RPCServiceKey.String("pkg.svr"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
9
go.mod
9
go.mod
@@ -42,13 +42,20 @@ require (
|
||||
github.com/fatih/color v1.10.0 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.4
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.0 // indirect
|
||||
github.com/prometheus/common v0.30.0 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7 // indirect
|
||||
k8s.io/klog/v2 v2.40.1 // indirect
|
||||
)
|
||||
|
||||
110
go.sum
110
go.sum
@@ -9,17 +9,27 @@ cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6T
|
||||
cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
|
||||
cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
|
||||
cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
|
||||
cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk=
|
||||
cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
|
||||
cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
|
||||
cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
|
||||
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
|
||||
cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
|
||||
cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
|
||||
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
|
||||
cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
|
||||
cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
|
||||
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
|
||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
|
||||
github.com/Azure/go-autorest/autorest v0.11.1/go.mod h1:JFgpikqFJ/MleTTxwepExTKnFUKKszPS8UavbQYUMuw=
|
||||
@@ -52,6 +62,7 @@ github.com/alicebob/miniredis/v2 v2.17.0 h1:EwLdrIS50uczw71Jc7iVSxZluTKj5nfSP8n7
|
||||
github.com/alicebob/miniredis/v2 v2.17.0/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
@@ -164,6 +175,8 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
||||
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=
|
||||
@@ -171,6 +184,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
@@ -189,21 +203,27 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/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.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
|
||||
github.com/google/gofuzz v1.1.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/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
@@ -238,8 +258,9 @@ github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhB
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
|
||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
@@ -274,15 +295,17 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
@@ -332,13 +355,15 @@ github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2
|
||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||
github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ=
|
||||
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
|
||||
github.com/prometheus/common v0.30.0 h1:JEkYlQnpzrzQFxi6gnukFPdQ+ac82oRhzMcIduJu/Ug=
|
||||
github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
|
||||
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
@@ -372,27 +397,24 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
|
||||
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/api/v3 v3.5.2 h1:tXok5yLlKyuQ/SXSjtqHc4uzNaMqZi2XsoSPr/LlJXI=
|
||||
go.etcd.io/etcd/api/v3 v3.5.2/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.2 h1:4hzqQ6hIb3blLyQ8usCU4h3NghkqcsohEQ3o3VetYxE=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.2/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
go.etcd.io/etcd/client/v3 v3.5.2 h1:WdnejrUtQC4nCxK0/dLTMqKOB+U5TP/2Ya0BJL+1otA=
|
||||
go.etcd.io/etcd/client/v3 v3.5.2/go.mod h1:kOOaWFFgHygyT0WlSmL8TJiXmMysO/nNUlEsSsN6W4o=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y=
|
||||
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
|
||||
@@ -404,7 +426,6 @@ go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1t
|
||||
go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
@@ -413,11 +434,9 @@ go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhW
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
|
||||
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
@@ -479,6 +498,7 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@@ -488,31 +508,39 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f h1:Qmd2pbz05z7z6lm0DrgQVVPuBm92jqujBKMHMOlOQEw=
|
||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/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-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -547,8 +575,14 @@ golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -562,8 +596,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
@@ -614,8 +646,18 @@ golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapK
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
@@ -636,13 +678,21 @@ google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsb
|
||||
google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
||||
google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
||||
google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
|
||||
google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
@@ -660,12 +710,20 @@ google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvx
|
||||
google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
|
||||
google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
|
||||
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||
google.golang.org/genproto v0.0.0-20220211171837-173942840c17 h1:2X+CNIheCutWRyKRte8szGxrE5ggtV4U+NKAbh/oLhg=
|
||||
google.golang.org/genproto v0.0.0-20220211171837-173942840c17/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
|
||||
google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7 h1:ntPPoHzFW6Xp09ueznmahONZufyoSakK/piXnr2BU3I=
|
||||
google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
@@ -676,6 +734,10 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
@@ -690,6 +752,7 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
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=
|
||||
@@ -729,6 +792,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.20.12 h1:LfRpmRkJLwPP8eaYehsVVmIIfg1yCBIIUHaSsdqCgHA=
|
||||
k8s.io/api v0.20.12/go.mod h1:A2brwyEkVLM3wQGNnzoAa5JsQRzHK0uoOQ+bsnv7V68=
|
||||
k8s.io/apimachinery v0.20.12 h1:2c0LIVNMvB8k2Ozstmhl2zGeCEcPazznuLYEwxFdNjM=
|
||||
|
||||
18
readme-cn.md
18
readme-cn.md
@@ -2,6 +2,8 @@
|
||||
|
||||
# go-zero
|
||||
|
||||
***缩短从需求到上线的距离***
|
||||
|
||||
[English](readme.md) | 简体中文
|
||||
|
||||
[](https://github.com/zeromicro/go-zero/actions)
|
||||
@@ -11,17 +13,13 @@
|
||||
[](https://github.com/zeromicro/go-zero)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
> ***缩短从需求到上线的距离***
|
||||
|
||||
**为了满足开源基金会要求,go-zero 从好未来(tal-tech)组织下迁移至中立的 GitHub 组织(zeromicro)。**
|
||||
|
||||
> ***注意:***
|
||||
>
|
||||
> 从 v1.3.0 之前版本升级请执行以下命令:
|
||||
>
|
||||
> GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
|
||||
> `GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
>
|
||||
> goctl migrate —verbose —version v1.3.0
|
||||
> `goctl migrate —verbose —version v1.3.1`
|
||||
|
||||
## 0. go-zero 介绍
|
||||
|
||||
@@ -252,6 +250,8 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>56. 时代脉搏网络科技(云浮市)有限公司
|
||||
>57. 店有帮
|
||||
>58. 七牛云
|
||||
>59. 费芮网络
|
||||
>60. 51CTO
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
@@ -281,3 +281,9 @@ go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape
|
||||
加群之前有劳点一下 ***star***,一个小小的 ***star*** 是作者们回答海量问题的动力!🤝
|
||||
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" />
|
||||
|
||||
## 12. 赞助一下👍
|
||||
|
||||
如果觉得项目有帮助,可以请作者喝杯咖啡 🍹
|
||||
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/sponsor.png" alt="wechat" width="300" />
|
||||
|
||||
@@ -12,15 +12,13 @@ English | [简体中文](readme-cn.md)
|
||||
[](https://discord.gg/4JQvC5A4Fe)
|
||||
<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go-zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go-zero - A web & rpc framework written in Go. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
||||
|
||||
**Note: To meet the requirements of Open Source Foundation, we moved go-zero from tal-tech to zeromicro (a neutral GitHub organization).**
|
||||
|
||||
> ***Important!***
|
||||
>
|
||||
> To upgrade from previous versions, run the following commands.
|
||||
> To upgrade from versions eariler than v1.3.0, run the following commands.
|
||||
>
|
||||
> `go install github.com/zeromicro/go-zero/tools/goctl@latest`
|
||||
>
|
||||
> `goctl migrate —verbose —version v1.3.0`
|
||||
> `goctl migrate —verbose —version v1.3.1`
|
||||
|
||||
## 0. what is go-zero
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ type engine struct {
|
||||
}
|
||||
|
||||
func newEngine(c RestConf) *engine {
|
||||
srv := &engine{
|
||||
svr := &engine{
|
||||
conf: c,
|
||||
}
|
||||
if c.CpuThreshold > 0 {
|
||||
srv.shedder = load.NewAdaptiveShedder(load.WithCpuThreshold(c.CpuThreshold))
|
||||
srv.priorityShedder = load.NewAdaptiveShedder(load.WithCpuThreshold(
|
||||
svr.shedder = load.NewAdaptiveShedder(load.WithCpuThreshold(c.CpuThreshold))
|
||||
svr.priorityShedder = load.NewAdaptiveShedder(load.WithCpuThreshold(
|
||||
(c.CpuThreshold + topCpuUsage) >> 1))
|
||||
}
|
||||
|
||||
return srv
|
||||
return svr
|
||||
}
|
||||
|
||||
func (ng *engine) addRoutes(r featuredRoutes) {
|
||||
@@ -238,9 +238,9 @@ func (ng *engine) start(router httpx.Router) error {
|
||||
}
|
||||
|
||||
return internal.StartHttps(ng.conf.Host, ng.conf.Port, ng.conf.CertFile,
|
||||
ng.conf.KeyFile, router, func(srv *http.Server) {
|
||||
ng.conf.KeyFile, router, func(svr *http.Server) {
|
||||
if ng.tlsConfig != nil {
|
||||
srv.TLSConfig = ng.tlsConfig
|
||||
svr.TLSConfig = ng.tlsConfig
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,11 +32,7 @@ func TracingHandler(serviceName, path string) func(http.Handler) http.Handler {
|
||||
defer span.End()
|
||||
|
||||
// convenient for tracking error messages
|
||||
sc := span.SpanContext()
|
||||
if sc.HasTraceID() {
|
||||
w.Header().Set(trace.TraceIdKey, sc.TraceID().String())
|
||||
}
|
||||
|
||||
propagator.Inject(spanCtx, propagation.HeaderCarrier(w.Header()))
|
||||
next.ServeHTTP(w, r.WithContext(spanCtx))
|
||||
})
|
||||
}
|
||||
|
||||
8
rest/httpc/internal/interceptor.go
Normal file
8
rest/httpc/internal/interceptor.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package internal
|
||||
|
||||
import "net/http"
|
||||
|
||||
type (
|
||||
Interceptor func(r *http.Request) (*http.Request, ResponseHandler)
|
||||
ResponseHandler func(*http.Response)
|
||||
)
|
||||
28
rest/httpc/internal/loginterceptor.go
Normal file
28
rest/httpc/internal/loginterceptor.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
func LogInterceptor(r *http.Request) (*http.Request, ResponseHandler) {
|
||||
start := timex.Now()
|
||||
return r, func(resp *http.Response) {
|
||||
duration := timex.Since(start)
|
||||
var tc propagation.TraceContext
|
||||
ctx := tc.Extract(r.Context(), propagation.HeaderCarrier(resp.Header))
|
||||
logger := logx.WithContext(ctx).WithDuration(duration)
|
||||
if isOkResponse(resp.StatusCode) {
|
||||
logger.Infof("[HTTP] %d - %s %s/%s", resp.StatusCode, r.Method, r.Host, r.RequestURI)
|
||||
} else {
|
||||
logger.Errorf("[HTTP] %d - %s %s/%s", resp.StatusCode, r.Method, r.Host, r.RequestURI)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isOkResponse(code int) bool {
|
||||
return code < http.StatusBadRequest
|
||||
}
|
||||
34
rest/httpc/internal/loginterceptor_test.go
Normal file
34
rest/httpc/internal/loginterceptor_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLogInterceptor(t *testing.T) {
|
||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
}))
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
req, handler := LogInterceptor(req)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
assert.Nil(t, err)
|
||||
handler(resp)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}
|
||||
|
||||
func TestLogInterceptorServerError(t *testing.T) {
|
||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}))
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
req, handler := LogInterceptor(req)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
assert.Nil(t, err)
|
||||
handler(resp)
|
||||
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
||||
}
|
||||
21
rest/httpc/requests.go
Normal file
21
rest/httpc/requests.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Do sends an HTTP request to the service assocated with the given key.
|
||||
func Do(key string, r *http.Request) (*http.Response, error) {
|
||||
return NewService(key).Do(r)
|
||||
}
|
||||
|
||||
// Get sends an HTTP GET request to the service assocated with the given key.
|
||||
func Get(key, url string) (*http.Response, error) {
|
||||
return NewService(key).Get(url)
|
||||
}
|
||||
|
||||
// Post sends an HTTP POST request to the service assocated with the given key.
|
||||
func Post(key, url, contentType string, body io.Reader) (*http.Response, error) {
|
||||
return NewService(key).Post(url, contentType, body)
|
||||
}
|
||||
37
rest/httpc/requests_test.go
Normal file
37
rest/httpc/requests_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDo(t *testing.T) {
|
||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
}))
|
||||
_, err := Get("foo", "tcp://bad request")
|
||||
assert.NotNil(t, err)
|
||||
resp, err := Get("foo", svr.URL)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}
|
||||
|
||||
func TestDoNotFound(t *testing.T) {
|
||||
svr := httptest.NewServer(http.NotFoundHandler())
|
||||
_, err := Post("foo", "tcp://bad request", "application/json", nil)
|
||||
assert.NotNil(t, err)
|
||||
resp, err := Post("foo", svr.URL, "application/json", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
}
|
||||
|
||||
func TestDoMoved(t *testing.T) {
|
||||
svr := httptest.NewServer(http.RedirectHandler("/foo", http.StatusMovedPermanently))
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
_, err = Do("foo", req)
|
||||
// too many redirects
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
113
rest/httpc/service.go
Normal file
113
rest/httpc/service.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpc/internal"
|
||||
)
|
||||
|
||||
// ContentType means Content-Type.
|
||||
const ContentType = "Content-Type"
|
||||
|
||||
var interceptors = []internal.Interceptor{
|
||||
internal.LogInterceptor,
|
||||
}
|
||||
|
||||
type (
|
||||
// Option is used to customize the *http.Client.
|
||||
Option func(r *http.Request) *http.Request
|
||||
|
||||
// Service represents a remote HTTP service.
|
||||
Service interface {
|
||||
// Do sends an HTTP request to the service.
|
||||
Do(r *http.Request) (*http.Response, error)
|
||||
// Get sends an HTTP GET request to the service.
|
||||
Get(url string) (*http.Response, error)
|
||||
// Post sends an HTTP POST request to the service.
|
||||
Post(url, contentType string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
|
||||
namedService struct {
|
||||
name string
|
||||
cli *http.Client
|
||||
opts []Option
|
||||
}
|
||||
)
|
||||
|
||||
// NewService returns a remote service with the given name.
|
||||
// opts are used to customize the *http.Client.
|
||||
func NewService(name string, opts ...Option) Service {
|
||||
return NewServiceWithClient(name, http.DefaultClient, opts...)
|
||||
}
|
||||
|
||||
// NewServiceWithClient returns a remote service with the given name.
|
||||
// opts are used to customize the *http.Client.
|
||||
func NewServiceWithClient(name string, cli *http.Client, opts ...Option) Service {
|
||||
return namedService{
|
||||
name: name,
|
||||
cli: cli,
|
||||
opts: opts,
|
||||
}
|
||||
}
|
||||
|
||||
// Do sends an HTTP request to the service.
|
||||
func (s namedService) Do(r *http.Request) (resp *http.Response, err error) {
|
||||
var respHandlers []internal.ResponseHandler
|
||||
for _, interceptor := range interceptors {
|
||||
var h internal.ResponseHandler
|
||||
r, h = interceptor(r)
|
||||
respHandlers = append(respHandlers, h)
|
||||
}
|
||||
|
||||
resp, err = s.doRequest(r)
|
||||
if err != nil {
|
||||
logx.Errorf("[HTTP] %s %s/%s - %v", r.Method, r.Host, r.RequestURI, err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := len(respHandlers) - 1; i >= 0; i-- {
|
||||
respHandlers[i](resp)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get sends an HTTP GET request to the service.
|
||||
func (s namedService) Get(url string) (*http.Response, error) {
|
||||
r, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.Do(r)
|
||||
}
|
||||
|
||||
// Post sends an HTTP POST request to the service.
|
||||
func (s namedService) Post(url, contentType string, body io.Reader) (*http.Response, error) {
|
||||
r, err := http.NewRequest(http.MethodPost, url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Header.Set(ContentType, contentType)
|
||||
return s.Do(r)
|
||||
}
|
||||
|
||||
func (s namedService) doRequest(r *http.Request) (resp *http.Response, err error) {
|
||||
for _, opt := range s.opts {
|
||||
r = opt(r)
|
||||
}
|
||||
|
||||
brk := breaker.GetBreaker(s.name)
|
||||
err = brk.DoWithAcceptable(func() error {
|
||||
resp, err = s.cli.Do(r)
|
||||
return err
|
||||
}, func(err error) bool {
|
||||
return err == nil && resp.StatusCode < http.StatusInternalServerError
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
43
rest/httpc/service_test.go
Normal file
43
rest/httpc/service_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNamedService_Do(t *testing.T) {
|
||||
svr := httptest.NewServer(http.RedirectHandler("/foo", http.StatusMovedPermanently))
|
||||
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
|
||||
assert.Nil(t, err)
|
||||
service := NewService("foo")
|
||||
_, err = service.Do(req)
|
||||
// too many redirects
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestNamedService_Get(t *testing.T) {
|
||||
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("foo", r.Header.Get("foo"))
|
||||
}))
|
||||
service := NewService("foo", func(r *http.Request) *http.Request {
|
||||
r.Header.Set("foo", "bar")
|
||||
return r
|
||||
})
|
||||
resp, err := service.Get(svr.URL)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
assert.Equal(t, "bar", resp.Header.Get("foo"))
|
||||
}
|
||||
|
||||
func TestNamedService_Post(t *testing.T) {
|
||||
svr := httptest.NewServer(http.NotFoundHandler())
|
||||
service := NewService("foo")
|
||||
_, err := service.Post("tcp://bad request", "application/json", nil)
|
||||
assert.NotNil(t, err)
|
||||
resp, err := service.Post(svr.URL, "application/json", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
}
|
||||
@@ -36,3 +36,8 @@ func TestError(t *testing.T) {
|
||||
assert.True(t, strings.Contains(val, "third"))
|
||||
assert.True(t, strings.Contains(val, "\n"))
|
||||
}
|
||||
|
||||
func TestContextKey_String(t *testing.T) {
|
||||
val := contextKey("foo")
|
||||
assert.True(t, strings.Contains(val.String(), "foo"))
|
||||
}
|
||||
|
||||
@@ -151,6 +151,8 @@ func TestContentSecurity(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
encrypted := test.mode != "0"
|
||||
assert.Equal(t, encrypted, header.Encrypted())
|
||||
assert.Equal(t, test.code, VerifySignature(r, header, time.Minute))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,25 +10,25 @@ import (
|
||||
)
|
||||
|
||||
// StartOption defines the method to customize http.Server.
|
||||
type StartOption func(srv *http.Server)
|
||||
type StartOption func(svr *http.Server)
|
||||
|
||||
// StartHttp starts a http server.
|
||||
func StartHttp(host string, port int, handler http.Handler, opts ...StartOption) error {
|
||||
return start(host, port, handler, func(srv *http.Server) error {
|
||||
return srv.ListenAndServe()
|
||||
return start(host, port, handler, func(svr *http.Server) error {
|
||||
return svr.ListenAndServe()
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
// StartHttps starts a https server.
|
||||
func StartHttps(host string, port int, certFile, keyFile string, handler http.Handler,
|
||||
opts ...StartOption) error {
|
||||
return start(host, port, handler, func(srv *http.Server) error {
|
||||
return start(host, port, handler, func(svr *http.Server) error {
|
||||
// certFile and keyFile are set in buildHttpsServer
|
||||
return srv.ListenAndServeTLS(certFile, keyFile)
|
||||
return svr.ListenAndServeTLS(certFile, keyFile)
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
func start(host string, port int, handler http.Handler, run func(srv *http.Server) error,
|
||||
func start(host string, port int, handler http.Handler, run func(svr *http.Server) error,
|
||||
opts ...StartOption) (err error) {
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", host, port),
|
||||
|
||||
33
rest/internal/starter_test.go
Normal file
33
rest/internal/starter_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStartHttp(t *testing.T) {
|
||||
svr := httptest.NewUnstartedServer(http.NotFoundHandler())
|
||||
fields := strings.Split(svr.Listener.Addr().String(), ":")
|
||||
port, err := strconv.Atoi(fields[1])
|
||||
assert.Nil(t, err)
|
||||
err = StartHttp(fields[0], port, http.NotFoundHandler(), func(svr *http.Server) {
|
||||
svr.IdleTimeout = 0
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestStartHttps(t *testing.T) {
|
||||
svr := httptest.NewTLSServer(http.NotFoundHandler())
|
||||
fields := strings.Split(svr.Listener.Addr().String(), ":")
|
||||
port, err := strconv.Atoi(fields[1])
|
||||
assert.Nil(t, err)
|
||||
err = StartHttps(fields[0], port, "", "", http.NotFoundHandler(), func(svr *http.Server) {
|
||||
svr.IdleTimeout = 0
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
@@ -225,22 +225,22 @@ func WithTimeout(timeout time.Duration) RouteOption {
|
||||
|
||||
// WithTLSConfig returns a RunOption that with given tls config.
|
||||
func WithTLSConfig(cfg *tls.Config) RunOption {
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setTlsConfig(cfg)
|
||||
return func(svr *Server) {
|
||||
svr.ngin.setTlsConfig(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnauthorizedCallback returns a RunOption that with given unauthorized callback set.
|
||||
func WithUnauthorizedCallback(callback handler.UnauthorizedCallback) RunOption {
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setUnauthorizedCallback(callback)
|
||||
return func(svr *Server) {
|
||||
svr.ngin.setUnauthorizedCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnsignedCallback returns a RunOption that with given unsigned callback set.
|
||||
func WithUnsignedCallback(callback handler.UnsignedCallback) RunOption {
|
||||
return func(srv *Server) {
|
||||
srv.ngin.setUnsignedCallback(callback)
|
||||
return func(svr *Server) {
|
||||
svr.ngin.setUnsignedCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,22 +56,22 @@ Port: 54321
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
var srv *Server
|
||||
var svr *Server
|
||||
var err error
|
||||
if test.fail {
|
||||
_, err = NewServer(test.c, test.opts...)
|
||||
assert.NotNil(t, err)
|
||||
continue
|
||||
} else {
|
||||
srv = MustNewServer(test.c, test.opts...)
|
||||
svr = MustNewServer(test.c, test.opts...)
|
||||
}
|
||||
|
||||
srv.Use(ToMiddleware(func(next http.Handler) http.Handler {
|
||||
svr.Use(ToMiddleware(func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}))
|
||||
srv.AddRoute(Route{
|
||||
svr.AddRoute(Route{
|
||||
Method: http.MethodGet,
|
||||
Path: "/",
|
||||
Handler: nil,
|
||||
@@ -89,8 +89,8 @@ Port: 54321
|
||||
}
|
||||
}()
|
||||
|
||||
srv.Start()
|
||||
srv.Stop()
|
||||
svr.Start()
|
||||
svr.Stop()
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -290,9 +290,9 @@ Port: 54321
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
srv, err := NewServer(testCase.c, testCase.opts...)
|
||||
svr, err := NewServer(testCase.c, testCase.opts...)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, srv.ngin.tlsConfig, testCase.res)
|
||||
assert.Equal(t, svr.ngin.tlsConfig, testCase.res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +304,11 @@ Port: 54321
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
rt := router.NewRouter()
|
||||
srv, err := NewServer(cnf, WithRouter(rt))
|
||||
svr, err := NewServer(cnf, WithRouter(rt))
|
||||
assert.Nil(t, err)
|
||||
|
||||
opt := WithCors("local")
|
||||
opt(srv)
|
||||
opt(svr)
|
||||
}
|
||||
|
||||
func TestWithCustomCors(t *testing.T) {
|
||||
@@ -319,7 +319,7 @@ Port: 54321
|
||||
var cnf RestConf
|
||||
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||
rt := router.NewRouter()
|
||||
srv, err := NewServer(cnf, WithRouter(rt))
|
||||
svr, err := NewServer(cnf, WithRouter(rt))
|
||||
assert.Nil(t, err)
|
||||
|
||||
opt := WithCustomCors(func(header http.Header) {
|
||||
@@ -327,5 +327,5 @@ Port: 54321
|
||||
}, func(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}, "local")
|
||||
opt(srv)
|
||||
opt(svr)
|
||||
}
|
||||
|
||||
1
tools/goctl/.gitignore
vendored
Normal file
1
tools/goctl/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.vscode
|
||||
@@ -55,8 +55,9 @@ func ApiCommand(c *cli.Context) error {
|
||||
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
40
tools/goctl/api/dartgen/format.go
Normal file
40
tools/goctl/api/dartgen/format.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package dartgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const dartExec = "dart"
|
||||
|
||||
func formatDir(dir string) error {
|
||||
ok, err := dirctoryExists(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return fmt.Errorf("format failed, directory %q does not exist", dir)
|
||||
}
|
||||
|
||||
_, err = exec.LookPath(dartExec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.Command(dartExec, "format", dir)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func dirctoryExists(dir string) (bool, error) {
|
||||
_, err := os.Stat(dir)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package dartgen
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
@@ -13,12 +14,18 @@ import (
|
||||
func DartCommand(c *cli.Context) error {
|
||||
apiFile := c.String("api")
|
||||
dir := c.String("dir")
|
||||
isLegacy := c.Bool("legacy")
|
||||
hostname := c.String("hostname")
|
||||
if len(apiFile) == 0 {
|
||||
return errors.New("missing -api")
|
||||
}
|
||||
if len(dir) == 0 {
|
||||
return errors.New("missing -dir")
|
||||
}
|
||||
if len(hostname) == 0 {
|
||||
fmt.Println("you could use '-hostname' flag to specify your server hostname")
|
||||
hostname = "go-zero.dev"
|
||||
}
|
||||
|
||||
api, err := parser.Parse(apiFile)
|
||||
if err != nil {
|
||||
@@ -30,8 +37,11 @@ func DartCommand(c *cli.Context) error {
|
||||
dir = dir + "/"
|
||||
}
|
||||
api.Info.Title = strings.Replace(apiFile, ".api", "", -1)
|
||||
logx.Must(genData(dir+"data/", api))
|
||||
logx.Must(genApi(dir+"api/", api))
|
||||
logx.Must(genVars(dir + "vars/"))
|
||||
logx.Must(genData(dir+"data/", api, isLegacy))
|
||||
logx.Must(genApi(dir+"api/", api, isLegacy))
|
||||
logx.Must(genVars(dir+"vars/", isLegacy, hostname))
|
||||
if err := formatDir(dir); err != nil {
|
||||
logx.Errorf("failed to format, %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package dartgen
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
)
|
||||
|
||||
const apiTemplate = `import 'api.dart';
|
||||
import '../data/{{with .Info}}{{.Title}}{{end}}.dart';
|
||||
import '../data/{{with .Info}}{{getBaseName .Title}}{{end}}.dart';
|
||||
{{with .Service}}
|
||||
/// {{.Name}}
|
||||
{{range .Routes}}
|
||||
@@ -22,24 +23,45 @@ Future {{pathToFuncName .Path}}( {{if ne .Method "get"}}{{with .RequestType}}{{.
|
||||
Function eventually}) async {
|
||||
await api{{if eq .Method "get"}}Get{{else}}Post{{end}}('{{.Path}}',{{if ne .Method "get"}}request,{{end}}
|
||||
ok: (data) {
|
||||
if (ok != null) ok({{with .ResponseType}}{{.Name}}{{end}}.fromJson(data));
|
||||
if (ok != null) ok({{with .ResponseType}}{{.Name}}.fromJson(data){{end}});
|
||||
}, fail: fail, eventually: eventually);
|
||||
}
|
||||
{{end}}
|
||||
{{end}}`
|
||||
|
||||
func genApi(dir string, api *spec.ApiSpec) error {
|
||||
const apiTemplateV2 = `import 'api.dart';
|
||||
import '../data/{{with .Info}}{{getBaseName .Title}}{{end}}.dart';
|
||||
{{with .Service}}
|
||||
/// {{.Name}}
|
||||
{{range .Routes}}
|
||||
/// --{{.Path}}--
|
||||
///
|
||||
/// request: {{with .RequestType}}{{.Name}}{{end}}
|
||||
/// response: {{with .ResponseType}}{{.Name}}{{end}}
|
||||
Future {{pathToFuncName .Path}}( {{if ne .Method "get"}}{{with .RequestType}}{{.Name}} request,{{end}}{{end}}
|
||||
{Function({{with .ResponseType}}{{.Name}}{{end}})? ok,
|
||||
Function(String)? fail,
|
||||
Function? eventually}) async {
|
||||
await api{{if eq .Method "get"}}Get{{else}}Post{{end}}('{{.Path}}',{{if ne .Method "get"}}request,{{end}}
|
||||
ok: (data) {
|
||||
if (ok != null) ok({{with .ResponseType}}{{.Name}}.fromJson(data){{end}});
|
||||
}, fail: fail, eventually: eventually);
|
||||
}
|
||||
{{end}}
|
||||
{{end}}`
|
||||
|
||||
func genApi(dir string, api *spec.ApiSpec, isLegacy bool) error {
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = genApiFile(dir)
|
||||
err = genApiFile(dir, isLegacy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
file, err := os.OpenFile(dir+strings.ToLower(api.Service.Name+".dart"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -47,7 +69,11 @@ func genApi(dir string, api *spec.ApiSpec) error {
|
||||
defer file.Close()
|
||||
t := template.New("apiTemplate")
|
||||
t = t.Funcs(funcMap)
|
||||
t, err = t.Parse(apiTemplate)
|
||||
tpl := apiTemplateV2
|
||||
if isLegacy {
|
||||
tpl = apiTemplate
|
||||
}
|
||||
t, err = t.Parse(tpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +81,7 @@ func genApi(dir string, api *spec.ApiSpec) error {
|
||||
return t.Execute(file, api)
|
||||
}
|
||||
|
||||
func genApiFile(dir string) error {
|
||||
func genApiFile(dir string, isLegacy bool) error {
|
||||
path := dir + "api.dart"
|
||||
if fileExists(path) {
|
||||
return nil
|
||||
@@ -66,6 +92,10 @@ func genApiFile(dir string) error {
|
||||
}
|
||||
|
||||
defer apiFile.Close()
|
||||
_, err = apiFile.WriteString(apiFileContent)
|
||||
tpl := apiFileContentV2
|
||||
if isLegacy {
|
||||
tpl = apiFileContent
|
||||
}
|
||||
_, err = apiFile.WriteString(tpl)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dartgen
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
@@ -31,18 +32,42 @@ class {{.Name}}{
|
||||
{{end}}
|
||||
`
|
||||
|
||||
func genData(dir string, api *spec.ApiSpec) error {
|
||||
const dataTemplateV2 = `// --{{with .Info}}{{.Title}}{{end}}--
|
||||
{{ range .Types}}
|
||||
class {{.Name}} {
|
||||
{{range .Members}}
|
||||
{{if .Comment}}{{.Comment}}{{end}}
|
||||
final {{.Type.Name}} {{lowCamelCase .Name}};
|
||||
{{end}}{{.Name}}({{if .Members}}{
|
||||
{{range .Members}} required this.{{lowCamelCase .Name}},
|
||||
{{end}}}{{end}});
|
||||
factory {{.Name}}.fromJson(Map<String,dynamic> m) {
|
||||
return {{.Name}}({{range .Members}}
|
||||
{{lowCamelCase .Name}}: {{if isDirectType .Type.Name}}m['{{getPropertyFromMember .}}']
|
||||
{{else if isClassListType .Type.Name}}(m['{{getPropertyFromMember .}}'] as List<dynamic>).map((i) => {{getCoreType .Type.Name}}.fromJson(i)).toList()
|
||||
{{else}}{{.Type.Name}}.fromJson(m['{{getPropertyFromMember .}}']){{end}},{{end}}
|
||||
);
|
||||
}
|
||||
Map<String,dynamic> toJson() {
|
||||
return { {{range .Members}}
|
||||
'{{getPropertyFromMember .}}': {{if isDirectType .Type.Name}}{{lowCamelCase .Name}}{{else if isClassListType .Type.Name}}{{lowCamelCase .Name}}.map((i) => i.toJson()){{else}}{{lowCamelCase .Name}}.toJson(){{end}},{{end}}
|
||||
};
|
||||
}
|
||||
}
|
||||
{{end}}`
|
||||
|
||||
func genData(dir string, api *spec.ApiSpec, isLegacy bool) error {
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = genTokens(dir)
|
||||
err = genTokens(dir, isLegacy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
file, err := os.OpenFile(dir+strings.ToLower(api.Service.Name+".dart"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -50,7 +75,11 @@ func genData(dir string, api *spec.ApiSpec) error {
|
||||
|
||||
t := template.New("dataTemplate")
|
||||
t = t.Funcs(funcMap)
|
||||
t, err = t.Parse(dataTemplate)
|
||||
tpl := dataTemplateV2
|
||||
if isLegacy {
|
||||
tpl = dataTemplate
|
||||
}
|
||||
t, err = t.Parse(tpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -63,7 +92,7 @@ func genData(dir string, api *spec.ApiSpec) error {
|
||||
return t.Execute(file, api)
|
||||
}
|
||||
|
||||
func genTokens(dir string) error {
|
||||
func genTokens(dir string, isLeagcy bool) error {
|
||||
path := dir + "tokens.dart"
|
||||
if fileExists(path) {
|
||||
return nil
|
||||
@@ -75,7 +104,11 @@ func genTokens(dir string) error {
|
||||
}
|
||||
|
||||
defer tokensFile.Close()
|
||||
_, err = tokensFile.WriteString(tokensFileContent)
|
||||
tpl := tokensFileContentV2
|
||||
if isLeagcy {
|
||||
tpl = tokensFileContent
|
||||
}
|
||||
_, err = tokensFile.WriteString(tpl)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package dartgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
const varTemplate = `import 'dart:convert';
|
||||
const (
|
||||
varTemplate = `import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../data/tokens.dart';
|
||||
|
||||
@@ -40,21 +42,59 @@ Future<Tokens> getTokens() async {
|
||||
}
|
||||
`
|
||||
|
||||
func genVars(dir string) error {
|
||||
varTemplateV2 = `import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../data/tokens.dart';
|
||||
|
||||
const String _tokenKey = 'tokens';
|
||||
|
||||
/// Saves tokens
|
||||
Future<bool> setTokens(Tokens tokens) async {
|
||||
var sp = await SharedPreferences.getInstance();
|
||||
return await sp.setString(_tokenKey, jsonEncode(tokens.toJson()));
|
||||
}
|
||||
|
||||
/// remove tokens
|
||||
Future<bool> removeTokens() async {
|
||||
var sp = await SharedPreferences.getInstance();
|
||||
return sp.remove(_tokenKey);
|
||||
}
|
||||
|
||||
/// Reads tokens
|
||||
Future<Tokens?> getTokens() async {
|
||||
try {
|
||||
var sp = await SharedPreferences.getInstance();
|
||||
var str = sp.getString('tokens');
|
||||
if (str.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Tokens.fromJson(jsonDecode(str));
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return null;
|
||||
}
|
||||
}`
|
||||
)
|
||||
|
||||
func genVars(dir string, isLegacy bool, hostname string) error {
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !fileExists(dir + "vars.dart") {
|
||||
err = ioutil.WriteFile(dir+"vars.dart", []byte(`const serverHost='demo-crm.xiaoheiban.cn';`), 0o644)
|
||||
err = ioutil.WriteFile(dir+"vars.dart", []byte(fmt.Sprintf(`const serverHost='%s';`, hostname)), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !fileExists(dir + "kv.dart") {
|
||||
err = ioutil.WriteFile(dir+"kv.dart", []byte(varTemplate), 0o644)
|
||||
tpl := varTemplateV2
|
||||
if isLegacy {
|
||||
tpl = varTemplate
|
||||
}
|
||||
err = ioutil.WriteFile(dir+"kv.dart", []byte(tpl), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
@@ -34,6 +35,10 @@ func pathToFuncName(path string) string {
|
||||
return util.ToLower(camel[:1]) + camel[1:]
|
||||
}
|
||||
|
||||
func getBaseName(str string) string {
|
||||
return path.Base(str)
|
||||
}
|
||||
|
||||
func getPropertyFromMember(member spec.Member) string {
|
||||
name, err := member.GetPropertyName()
|
||||
if err != nil {
|
||||
@@ -123,11 +128,10 @@ func specTypeToDart(tp spec.Type) (string, error) {
|
||||
}
|
||||
|
||||
s := getBaseType(valueType)
|
||||
if len(s) == 0 {
|
||||
return s, errors.New("unsupported primitive type " + tp.Name())
|
||||
if len(s) != 0 {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
return s, nil
|
||||
return fmt.Sprintf("List<%s>", valueType), nil
|
||||
case spec.InterfaceType:
|
||||
return "Object", nil
|
||||
case spec.PointerType:
|
||||
|
||||
@@ -37,3 +37,35 @@ func Test_getPropertyFromMember(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_specTypeToDart(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
specType spec.Type
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "[]string should return List<String>",
|
||||
specType: spec.ArrayType{RawName: "[]string", Value: spec.PrimitiveType{RawName: "string"}},
|
||||
want: "List<String>",
|
||||
},
|
||||
{
|
||||
name: "[]Foo should return List<Foo>",
|
||||
specType: spec.ArrayType{RawName: "[]Foo", Value: spec.DefineStruct{RawName: "Foo"}},
|
||||
want: "List<Foo>",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := specTypeToDart(tt.specType)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("specTypeToDart() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("specTypeToDart() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dartgen
|
||||
import "text/template"
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"getBaseName": getBaseName,
|
||||
"getPropertyFromMember": getPropertyFromMember,
|
||||
"isDirectType": isDirectType,
|
||||
"isClassListType": isClassListType,
|
||||
@@ -99,6 +100,96 @@ Future _apiRequest(String method, String path, dynamic data,
|
||||
}
|
||||
`
|
||||
|
||||
apiFileContentV2 = `import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import '../vars/kv.dart';
|
||||
import '../vars/vars.dart';
|
||||
|
||||
/// send request with post method
|
||||
///
|
||||
/// data: any request class that will be converted to json automatically
|
||||
/// ok: is called when request succeeds
|
||||
/// fail: is called when request fails
|
||||
/// eventually: is always called until the nearby functions returns
|
||||
Future apiPost(String path, dynamic data,
|
||||
{Map<String, String>? header,
|
||||
Function(Map<String, dynamic>)? ok,
|
||||
Function(String)? fail,
|
||||
Function? eventually}) async {
|
||||
await _apiRequest('POST', path, data,
|
||||
header: header, ok: ok, fail: fail, eventually: eventually);
|
||||
}
|
||||
|
||||
/// send request with get method
|
||||
///
|
||||
/// ok: is called when request succeeds
|
||||
/// fail: is called when request fails
|
||||
/// eventually: is always called until the nearby functions returns
|
||||
Future apiGet(String path,
|
||||
{Map<String, String>? header,
|
||||
Function(Map<String, dynamic>)? ok,
|
||||
Function(String)? fail,
|
||||
Function? eventually}) async {
|
||||
await _apiRequest('GET', path, null,
|
||||
header: header, ok: ok, fail: fail, eventually: eventually);
|
||||
}
|
||||
|
||||
Future _apiRequest(String method, String path, dynamic data,
|
||||
{Map<String, String>? header,
|
||||
Function(Map<String, dynamic>)? ok,
|
||||
Function(String)? fail,
|
||||
Function? eventually}) async {
|
||||
var tokens = await getTokens();
|
||||
try {
|
||||
var client = HttpClient();
|
||||
HttpClientRequest r;
|
||||
if (method == 'POST') {
|
||||
r = await client.postUrl(Uri.parse('https://' + serverHost + path));
|
||||
} else {
|
||||
r = await client.getUrl(Uri.parse('https://' + serverHost + path));
|
||||
}
|
||||
|
||||
r.headers.set('Content-Type', 'application/json');
|
||||
if (tokens != null) {
|
||||
r.headers.set('Authorization', tokens.accessToken);
|
||||
}
|
||||
if (header != null) {
|
||||
header.forEach((k, v) {
|
||||
r.headers.set(k, v);
|
||||
});
|
||||
}
|
||||
var strData = '';
|
||||
if (data != null) {
|
||||
strData = jsonEncode(data);
|
||||
}
|
||||
r.write(strData);
|
||||
var rp = await r.close();
|
||||
var body = await rp.transform(utf8.decoder).join();
|
||||
print('${rp.statusCode} - $path');
|
||||
print('-- request --');
|
||||
print(strData);
|
||||
print('-- response --');
|
||||
print('$body \n');
|
||||
if (rp.statusCode == 404) {
|
||||
if (fail != null) fail('404 not found');
|
||||
} else {
|
||||
Map<String, dynamic> base = jsonDecode(body);
|
||||
if (rp.statusCode == 200) {
|
||||
if (base['code'] != 0) {
|
||||
if (fail != null) fail(base['desc']);
|
||||
} else {
|
||||
if (ok != null) ok(base['data']);
|
||||
}
|
||||
} else if (base['code'] != 0) {
|
||||
if (fail != null) fail(base['desc']);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (fail != null) fail(e.toString());
|
||||
}
|
||||
if (eventually != null) eventually();
|
||||
}`
|
||||
|
||||
tokensFileContent = `class Tokens {
|
||||
/// 用于访问的token, 每次请求都必须带在Header里面
|
||||
final String accessToken;
|
||||
@@ -132,5 +223,41 @@ Future _apiRequest(String method, String path, dynamic data,
|
||||
};
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
tokensFileContentV2 = `class Tokens {
|
||||
/// 用于访问的token, 每次请求都必须带在Header里面
|
||||
final String accessToken;
|
||||
final int accessExpire;
|
||||
|
||||
/// 用于刷新token
|
||||
final String refreshToken;
|
||||
final int refreshExpire;
|
||||
final int refreshAfter;
|
||||
Tokens({
|
||||
required this.accessToken,
|
||||
required this.accessExpire,
|
||||
required this.refreshToken,
|
||||
required this.refreshExpire,
|
||||
required this.refreshAfter
|
||||
});
|
||||
factory Tokens.fromJson(Map<String, dynamic> m) {
|
||||
return Tokens(
|
||||
accessToken: m['access_token'],
|
||||
accessExpire: m['access_expire'],
|
||||
refreshToken: m['refresh_token'],
|
||||
refreshExpire: m['refresh_expire'],
|
||||
refreshAfter: m['refresh_after']);
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'access_token': accessToken,
|
||||
'access_expire': accessExpire,
|
||||
'refresh_token': refreshToken,
|
||||
'refresh_expire': refreshExpire,
|
||||
'refresh_after': refreshAfter,
|
||||
};
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
@@ -28,10 +28,11 @@ const (
|
||||
// GoFormatApi format api file
|
||||
func GoFormatApi(c *cli.Context) error {
|
||||
useStdin := c.Bool("stdin")
|
||||
skipCheckDeclare := c.Bool("declare")
|
||||
|
||||
var be errorx.BatchError
|
||||
if useStdin {
|
||||
if err := apiFormatByStdin(); err != nil {
|
||||
if err := apiFormatByStdin(skipCheckDeclare); err != nil {
|
||||
be.Add(err)
|
||||
}
|
||||
} else {
|
||||
@@ -47,7 +48,7 @@ func GoFormatApi(c *cli.Context) error {
|
||||
|
||||
err = filepath.Walk(dir, func(path string, fi os.FileInfo, errBack error) (err error) {
|
||||
if strings.HasSuffix(path, ".api") {
|
||||
if err := ApiFormatByPath(path); err != nil {
|
||||
if err := ApiFormatByPath(path, skipCheckDeclare); err != nil {
|
||||
be.Add(util.WrapErr(err, fi.Name()))
|
||||
}
|
||||
}
|
||||
@@ -64,13 +65,13 @@ func GoFormatApi(c *cli.Context) error {
|
||||
return be.Err()
|
||||
}
|
||||
|
||||
func apiFormatByStdin() error {
|
||||
func apiFormatByStdin(skipCheckDeclare bool) error {
|
||||
data, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := apiFormat(string(data))
|
||||
result, err := apiFormat(string(data), skipCheckDeclare)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,7 +81,7 @@ func apiFormatByStdin() error {
|
||||
}
|
||||
|
||||
// ApiFormatByPath format api from file path
|
||||
func ApiFormatByPath(apiFilePath string) error {
|
||||
func ApiFormatByPath(apiFilePath string, skipCheckDeclare bool) error {
|
||||
data, err := ioutil.ReadFile(apiFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -91,12 +92,12 @@ func ApiFormatByPath(apiFilePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := apiFormat(string(data), abs)
|
||||
result, err := apiFormat(string(data), skipCheckDeclare, abs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = parser.ParseContent(result, abs)
|
||||
_, err = parser.ParseContentWithParserSkipCheckTypeDeclaration(result, abs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,8 +105,13 @@ func ApiFormatByPath(apiFilePath string) error {
|
||||
return ioutil.WriteFile(apiFilePath, []byte(result), os.ModePerm)
|
||||
}
|
||||
|
||||
func apiFormat(data string, filename ...string) (string, error) {
|
||||
_, err := parser.ParseContent(data, filename...)
|
||||
func apiFormat(data string, skipCheckDeclare bool, filename ...string) (string, error) {
|
||||
var err error
|
||||
if skipCheckDeclare {
|
||||
_, err = parser.ParseContentWithParserSkipCheckTypeDeclaration(data, filename...)
|
||||
} else {
|
||||
_, err = parser.ParseContent(data, filename...)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type Request struct {
|
||||
}
|
||||
type Response struct {
|
||||
Message string ` + "`" + `json:"message"` + "`" + `
|
||||
Students []Student ` + "`" + `json:"students"` + "`" + `
|
||||
}
|
||||
service A-api {
|
||||
@server(
|
||||
@@ -26,7 +27,8 @@ handler: GreetHandler
|
||||
Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
|
||||
}
|
||||
type Response {
|
||||
Message string ` + "`" + `json:"message"` + "`" + `
|
||||
Message string ` + "`" + `json:"message"` + "`" + `
|
||||
Students []Student ` + "`" + `json:"students"` + "`" + `
|
||||
}
|
||||
service A-api {
|
||||
@server(
|
||||
@@ -37,7 +39,9 @@ service A-api {
|
||||
)
|
||||
|
||||
func TestFormat(t *testing.T) {
|
||||
r, err := apiFormat(notFormattedStr)
|
||||
r, err := apiFormat(notFormattedStr, true)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, formattedStr, r)
|
||||
_, err = apiFormat(notFormattedStr, false)
|
||||
assert.Errorf(t, err, " line 7:13 can not found declaration 'Student' in context")
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@ func GoCommand(c *cli.Context) error {
|
||||
namingStyle := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -85,7 +86,7 @@ func DoGenProject(apiFile, dir, style string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := apiformat.ApiFormatByPath(apiFile); err != nil {
|
||||
if err := apiformat.ApiFormatByPath(apiFile, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ import com.google.gson.Gson
|
||||
object {{with .Info}}{{.Title}}{{end}}{
|
||||
{{range .Types}}
|
||||
data class {{.Name}}({{$length := (len .Members)}}{{range $i,$item := .Members}}
|
||||
val {{with $item}}{{lowCamelCase .Name}}: {{parseType .Type}}{{end}}{{if ne $i (add $length -1)}},{{end}}{{end}}
|
||||
val {{with $item}}{{lowCamelCase .Name}}: {{parseType .Type.Name}}{{end}}{{if ne $i (add $length -1)}},{{end}}{{end}}
|
||||
){{end}}
|
||||
{{with .Service}}
|
||||
{{range .Routes}}suspend fun {{routeToFuncName .Method .Path}}({{with .RequestType}}{{if ne .Name ""}}
|
||||
|
||||
@@ -67,8 +67,9 @@ func CreateServiceCommand(c *cli.Context) error {
|
||||
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ type (
|
||||
debug bool
|
||||
log console.Console
|
||||
antlr.DefaultErrorListener
|
||||
src string
|
||||
src string
|
||||
skipCheckTypeDeclaration bool
|
||||
}
|
||||
|
||||
// ParserOption defines an function with argument Parser
|
||||
@@ -136,9 +137,11 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
||||
apiAstList = append(apiAstList, nestedApi)
|
||||
}
|
||||
|
||||
err = p.checkTypeDeclaration(apiAstList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if !p.skipCheckTypeDeclaration {
|
||||
err = p.checkTypeDeclaration(apiAstList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
allApi := p.memberFill(apiAstList)
|
||||
@@ -483,3 +486,9 @@ func WithParserPrefix(prefix string) ParserOption {
|
||||
p.linePrefix = prefix
|
||||
}
|
||||
}
|
||||
|
||||
func WithParserSkipCheckTypeDeclaration() ParserOption {
|
||||
return func(p *Parser) {
|
||||
p.skipCheckTypeDeclaration = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,19 +648,19 @@ func (s *TypeStruct) Equal(dt interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var expected, acual []*TypeField
|
||||
var expected, actual []*TypeField
|
||||
expected = append(expected, s.Fields...)
|
||||
acual = append(acual, v.Fields...)
|
||||
actual = append(actual, v.Fields...)
|
||||
|
||||
sort.Slice(expected, func(i, j int) bool {
|
||||
return expected[i].DataType.Expr().Line() < expected[j].DataType.Expr().Line()
|
||||
})
|
||||
sort.Slice(acual, func(i, j int) bool {
|
||||
return acual[i].DataType.Expr().Line() < acual[j].DataType.Expr().Line()
|
||||
sort.Slice(actual, func(i, j int) bool {
|
||||
return actual[i].DataType.Expr().Line() < actual[j].DataType.Expr().Line()
|
||||
})
|
||||
|
||||
for index, each := range expected {
|
||||
ac := acual[index]
|
||||
ac := actual[index]
|
||||
if !each.Equal(ac) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
const (
|
||||
versionRegex = `(?m)"v[1-9][0-9]*"`
|
||||
importValueRegex = `(?m)"\/?(([a-zA-Z0-9.]+)+(\/?){1})+([a-zA-Z0-9]+)+\.api"`
|
||||
importValueRegex = `(?m)"\/?(?:[^/]+\/)*[^/]+.api"`
|
||||
tagRegex = `(?m)\x60[a-z]+:".+"\x60`
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ func TestImportRegex(t *testing.T) {
|
||||
|
||||
{`"bar..api"`, false},
|
||||
{`"//bar.api"`, false},
|
||||
{`"/foo/foo_bar.api"`, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.value, func(t *testing.T) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@@ -61,7 +62,12 @@ import "github.com/zeromicro/antlr"
|
||||
}
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(fp, buffer.Bytes(), os.ModePerm)
|
||||
src, err := format.Source(buffer.Bytes())
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
break
|
||||
}
|
||||
err = ioutil.WriteFile(fp, src, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("%+v\n", err)
|
||||
}
|
||||
|
||||
@@ -33,9 +33,13 @@ func Parse(filename string) (*spec.ApiSpec, error) {
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
// ParseContent parses the api content
|
||||
func ParseContent(content string, filename ...string) (*spec.ApiSpec, error) {
|
||||
astParser := ast.NewParser()
|
||||
func parseContent(content string, skipCheckTypeDeclaration bool, filename ...string) (*spec.ApiSpec, error) {
|
||||
var astParser *ast.Parser
|
||||
if skipCheckTypeDeclaration {
|
||||
astParser = ast.NewParser(ast.WithParserSkipCheckTypeDeclaration())
|
||||
} else {
|
||||
astParser = ast.NewParser()
|
||||
}
|
||||
ast, err := astParser.ParseContent(content, filename...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -51,6 +55,16 @@ func ParseContent(content string, filename ...string) (*spec.ApiSpec, error) {
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
// ParseContent parses the api content
|
||||
func ParseContent(content string, filename ...string) (*spec.ApiSpec, error) {
|
||||
return parseContent(content, false, filename...)
|
||||
}
|
||||
|
||||
// ParseContentWithParserSkipCheckTypeDeclaration parses the api content with skip check type declaration
|
||||
func ParseContentWithParserSkipCheckTypeDeclaration(content string, filename ...string) (*spec.ApiSpec, error) {
|
||||
return parseContent(content, true, filename...)
|
||||
}
|
||||
|
||||
func (p parser) convert2Spec() error {
|
||||
p.fillInfo()
|
||||
p.fillSyntax()
|
||||
|
||||
@@ -557,7 +557,7 @@ service foo-api{
|
||||
|
||||
## 隐藏通道
|
||||
|
||||
隐藏通道目前主要为空百符号,换行符号以及注释,这里我们只说注释,因为空白符号和换行符号我们目前拿来也无用。
|
||||
隐藏通道目前主要为空白符号,换行符号以及注释,这里我们只说注释,因为空白符号和换行符号我们目前拿来也无用。
|
||||
|
||||
### 单行注释
|
||||
|
||||
@@ -679,4 +679,4 @@ service foo-api{
|
||||
*/
|
||||
post /foo (Foo) returns (Foo) // route comment
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
@@ -24,14 +24,17 @@ const (
|
||||
|
||||
// Docker describes a dockerfile
|
||||
type Docker struct {
|
||||
Chinese bool
|
||||
GoRelPath string
|
||||
GoFile string
|
||||
ExeFile string
|
||||
HasPort bool
|
||||
Port int
|
||||
Argument string
|
||||
Version string
|
||||
Chinese bool
|
||||
GoRelPath string
|
||||
GoFile string
|
||||
ExeFile string
|
||||
Scratch bool
|
||||
HasPort bool
|
||||
Port int
|
||||
Argument string
|
||||
Version string
|
||||
HasTimezone bool
|
||||
Timezone string
|
||||
}
|
||||
|
||||
// DockerCommand provides the entry for goctl docker
|
||||
@@ -46,8 +49,10 @@ func DockerCommand(c *cli.Context) (err error) {
|
||||
home := c.String("home")
|
||||
version := c.String("version")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
timezone := c.String("tz")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -69,9 +74,10 @@ func DockerCommand(c *cli.Context) (err error) {
|
||||
return fmt.Errorf("file %q not found", goFile)
|
||||
}
|
||||
|
||||
scratch := c.Bool("scratch")
|
||||
port := c.Int("port")
|
||||
if _, err := os.Stat(etcDir); os.IsNotExist(err) {
|
||||
return generateDockerfile(goFile, port, version)
|
||||
return generateDockerfile(goFile, scratch, port, version, timezone)
|
||||
}
|
||||
|
||||
cfg, err := findConfig(goFile, etcDir)
|
||||
@@ -79,7 +85,7 @@ func DockerCommand(c *cli.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := generateDockerfile(goFile, port, version, "-f", "etc/"+cfg); err != nil {
|
||||
if err := generateDockerfile(goFile, scratch, port, version, timezone, "-f", "etc/"+cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -120,7 +126,7 @@ func findConfig(file, dir string) (string, error) {
|
||||
return files[0], nil
|
||||
}
|
||||
|
||||
func generateDockerfile(goFile string, port int, version string, args ...string) error {
|
||||
func generateDockerfile(goFile string, scratch bool, port int, version, timezone string, args ...string) error {
|
||||
projPath, err := getFilePath(filepath.Dir(goFile))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -149,14 +155,17 @@ func generateDockerfile(goFile string, port int, version string, args ...string)
|
||||
_, offset := time.Now().Zone()
|
||||
t := template.Must(template.New("dockerfile").Parse(text))
|
||||
return t.Execute(out, Docker{
|
||||
Chinese: offset == cstOffset,
|
||||
GoRelPath: projPath,
|
||||
GoFile: goFile,
|
||||
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
||||
HasPort: port > 0,
|
||||
Port: port,
|
||||
Argument: builder.String(),
|
||||
Version: version,
|
||||
Chinese: offset == cstOffset,
|
||||
GoRelPath: projPath,
|
||||
GoFile: goFile,
|
||||
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
||||
Scratch: scratch,
|
||||
HasPort: port > 0,
|
||||
Port: port,
|
||||
Argument: builder.String(),
|
||||
Version: version,
|
||||
HasTimezone: len(timezone) > 0,
|
||||
Timezone: timezone,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ const (
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOOS linux
|
||||
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct
|
||||
{{end}}{{if .HasTimezone}}
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
{{end}}
|
||||
WORKDIR /build/zero
|
||||
WORKDIR /build
|
||||
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
@@ -26,11 +27,12 @@ COPY . .
|
||||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}/{{.GoFile}}
|
||||
|
||||
|
||||
FROM alpine
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata
|
||||
ENV TZ Asia/Shanghai
|
||||
FROM {{if .Scratch}}scratch{{else}}alpine{{end}}
|
||||
|
||||
{{if .Scratch}}COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt{{else}}RUN apk update --no-cache && apk add --no-cache ca-certificates{{end}}
|
||||
{{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}}
|
||||
ENV TZ {{.Timezone}}
|
||||
{{end}}
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}}
|
||||
COPY --from=builder /app/etc /app/etc{{end}}
|
||||
|
||||
8
tools/goctl/env/check.go
vendored
8
tools/goctl/env/check.go
vendored
@@ -40,10 +40,10 @@ var bins = []bin{
|
||||
func Check(ctx *cli.Context) error {
|
||||
install := ctx.Bool("install")
|
||||
force := ctx.Bool("force")
|
||||
return check(install, force)
|
||||
return Prepare(install, force)
|
||||
}
|
||||
|
||||
func check(install, force bool) error {
|
||||
func Prepare(install, force bool) error {
|
||||
pending := true
|
||||
console.Info("[goctl-env]: preparing to check env")
|
||||
defer func() {
|
||||
@@ -56,8 +56,8 @@ func check(install, force bool) error {
|
||||
} else {
|
||||
console.Error(`
|
||||
[goctl-env]: check env finish, some dependencies is not found in PATH, you can execute
|
||||
command 'goctl env check --install' or 'goctl env install' to install it, for details,
|
||||
please see 'goctl env check --help' or 'goctl env install --help'`)
|
||||
command 'goctl env check --install' to install it, for details, please execute command
|
||||
'goctl env check --help'`)
|
||||
}
|
||||
}()
|
||||
for _, e := range bins {
|
||||
|
||||
@@ -13,5 +13,5 @@ require (
|
||||
github.com/urfave/cli v1.22.5
|
||||
github.com/zeromicro/antlr v0.0.1
|
||||
github.com/zeromicro/ddl-parser v1.0.3
|
||||
github.com/zeromicro/go-zero v1.3.0
|
||||
github.com/zeromicro/go-zero v1.3.1
|
||||
)
|
||||
|
||||
@@ -36,7 +36,6 @@ github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHg
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
|
||||
@@ -54,13 +53,15 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
|
||||
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/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
@@ -69,7 +70,6 @@ github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
@@ -82,6 +82,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
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/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
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/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
@@ -97,7 +99,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
@@ -138,8 +139,8 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9
|
||||
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
|
||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
|
||||
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
@@ -327,7 +328,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||
@@ -358,11 +358,11 @@ 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.3 h1:hFecpbt0oPQMhHAbqG1tz78MUepHUnOkFJp1dvRBFyc=
|
||||
github.com/zeromicro/ddl-parser v1.0.3/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/go-zero v1.3.0 h1:Eyn36yBtR043sm4YKmxR6eS3UA/GtZDktQ+UqIJ3Lm0=
|
||||
github.com/zeromicro/go-zero v1.3.0/go.mod h1:Hy4o1VFAt32lXaQMbaBhoFeZjA/rJqJ4PTGNdGsURcc=
|
||||
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
|
||||
github.com/zeromicro/go-zero v1.3.1 h1:uVkELq9kosgRZBSERb+eG7+oY2E+BEpOJW5vZZ354Cs=
|
||||
github.com/zeromicro/go-zero v1.3.1/go.mod h1:JsgCzJSUcjZl487xtqWHzYFa7Wl4f5Gi3lcteOWgNRA=
|
||||
go.etcd.io/etcd/api/v3 v3.5.2/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.2/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v3 v3.5.2/go.mod h1:kOOaWFFgHygyT0WlSmL8TJiXmMysO/nNUlEsSsN6W4o=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
@@ -377,11 +377,15 @@ go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0=
|
||||
go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@@ -455,8 +459,8 @@ 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-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d h1:1n1fc535VhN8SYtD4cDUyNlfpAF2ROMM9+11equK3hs=
|
||||
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -516,9 +520,11 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY=
|
||||
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
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/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -610,7 +616,7 @@ google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfG
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||
google.golang.org/genproto v0.0.0-20220112215332-a9c7c0acf9f2/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
|
||||
google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
@@ -622,9 +628,8 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
|
||||
google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
|
||||
@@ -111,6 +111,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: apigen.ApiCommand,
|
||||
Subcommands: []cli.Command{
|
||||
@@ -130,6 +134,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "style",
|
||||
Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md]",
|
||||
@@ -152,6 +160,10 @@ var commands = []cli.Command{
|
||||
Name: "stdin",
|
||||
Usage: "use stdin to input api doc content, press \"ctrl + d\" to send EOF",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "declare",
|
||||
Usage: "use to skip check api types already declare",
|
||||
},
|
||||
},
|
||||
Action: format.GoFormatApi,
|
||||
},
|
||||
@@ -209,6 +221,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: gogen.GoCommand,
|
||||
},
|
||||
@@ -266,6 +282,14 @@ var commands = []cli.Command{
|
||||
Name: "api",
|
||||
Usage: "the api file",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "legacy",
|
||||
Usage: "legacy generator for flutter v1",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "hostname",
|
||||
Usage: "hostname of the server",
|
||||
},
|
||||
},
|
||||
Action: dartgen.DartCommand,
|
||||
},
|
||||
@@ -321,6 +345,10 @@ var commands = []cli.Command{
|
||||
Name: "go",
|
||||
Usage: "the file that contains main function",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "scratch",
|
||||
Usage: "use scratch for the base docker image",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "port",
|
||||
Usage: "the port to expose, default none",
|
||||
@@ -337,10 +365,19 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "version",
|
||||
Usage: "the goctl builder golang image version",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tz",
|
||||
Usage: "the timezone of the container",
|
||||
Value: "Asia/Shanghai",
|
||||
},
|
||||
},
|
||||
Action: docker.DockerCommand,
|
||||
},
|
||||
@@ -437,6 +474,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "serviceAccount",
|
||||
Usage: "the ServiceAccount for the deployment",
|
||||
@@ -474,6 +515,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPCNew,
|
||||
},
|
||||
@@ -496,6 +541,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPCTemplate,
|
||||
},
|
||||
@@ -506,22 +555,30 @@ var commands = []cli.Command{
|
||||
Description: "for details, see https://go-zero.dev/cn/goctl-rpc.html",
|
||||
Action: rpc.ZRPC,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "go_out",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "go-grpc_out",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "go_opt",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "go-grpc_opt",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "plugin",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "proto_path,I",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "zrpc_out",
|
||||
Usage: "the zrpc output directory",
|
||||
@@ -540,6 +597,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -582,6 +643,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPC,
|
||||
},
|
||||
@@ -634,6 +699,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.MysqlDDL,
|
||||
},
|
||||
@@ -676,6 +745,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.MySqlDataSource,
|
||||
},
|
||||
@@ -728,6 +801,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.PostgreSqlDataSource,
|
||||
},
|
||||
@@ -764,6 +841,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: mongo.Action,
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildVersion is the version of goctl.
|
||||
const BuildVersion = "1.3.2"
|
||||
const BuildVersion = "1.3.3"
|
||||
|
||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ func DeploymentCommand(c *cli.Context) error {
|
||||
nodePort := c.Int("nodePort")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ func Action(ctx *cli.Context) error {
|
||||
s := ctx.String("style")
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
branch := ctx.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ const (
|
||||
flagDatabase = "database"
|
||||
flagSchema = "schema"
|
||||
flagHome = "home"
|
||||
flagRemote = "remote"
|
||||
flagBranch = "branch"
|
||||
)
|
||||
|
||||
var errNotMatched = errors.New("sql not matched")
|
||||
@@ -43,9 +45,10 @@ func MysqlDDL(ctx *cli.Context) error {
|
||||
style := ctx.String(flagStyle)
|
||||
database := ctx.String(flagDatabase)
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String("remote")
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -68,10 +71,11 @@ func MySqlDataSource(ctx *cli.Context) error {
|
||||
cache := ctx.Bool(flagCache)
|
||||
idea := ctx.Bool(flagIdea)
|
||||
style := ctx.String(flagStyle)
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -97,10 +101,11 @@ func PostgreSqlDataSource(ctx *cli.Context) error {
|
||||
idea := ctx.Bool(flagIdea)
|
||||
style := ctx.String(flagStyle)
|
||||
schema := ctx.String(flagSchema)
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package template
|
||||
// Delete defines a delete template
|
||||
var Delete = `
|
||||
func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
|
||||
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOneCtx(ctx, {{.lowerStartCamelPrimaryKey}})
|
||||
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne(ctx, {{.lowerStartCamelPrimaryKey}})
|
||||
if err!=nil{
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{
|
||||
|
||||
// FindOneByField defines find row by field.
|
||||
var FindOneByField = `
|
||||
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}({{.in}}) (*{{.upperStartCamelObject}}, error) {
|
||||
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
|
||||
{{if .withCache}}{{.cacheKey}}
|
||||
var resp {{.upperStartCamelObject}}
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package mocksql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
@@ -29,12 +30,22 @@ func (conn *MockConn) Exec(query string, args ...interface{}) (sql.Result, error
|
||||
return exec(conn.db, query, args...)
|
||||
}
|
||||
|
||||
// ExecCtx executes sql and returns the result
|
||||
func (conn *MockConn) ExecCtx(_ context.Context, query string, args ...interface{}) (sql.Result, error) {
|
||||
return exec(conn.db, query, args...)
|
||||
}
|
||||
|
||||
// Prepare executes sql by sql.DB
|
||||
func (conn *MockConn) Prepare(query string) (sqlx.StmtSession, error) {
|
||||
st, err := conn.db.Prepare(query)
|
||||
return statement{stmt: st}, err
|
||||
}
|
||||
|
||||
// PrepareCtx executes sql by sql.DB
|
||||
func (conn *MockConn) PrepareCtx(_ context.Context, query string) (sqlx.StmtSession, error) {
|
||||
return conn.Prepare(query)
|
||||
}
|
||||
|
||||
// QueryRow executes sql and returns a query row
|
||||
func (conn *MockConn) QueryRow(v interface{}, q string, args ...interface{}) error {
|
||||
return query(conn.db, func(rows *sql.Rows) error {
|
||||
@@ -42,6 +53,11 @@ func (conn *MockConn) QueryRow(v interface{}, q string, args ...interface{}) err
|
||||
}, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowCtx executes sql and returns a query row
|
||||
func (conn *MockConn) QueryRowCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
|
||||
return conn.QueryRow(v, query, args...)
|
||||
}
|
||||
|
||||
// QueryRowPartial executes sql and returns a partial query row
|
||||
func (conn *MockConn) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
|
||||
return query(conn.db, func(rows *sql.Rows) error {
|
||||
@@ -49,6 +65,11 @@ func (conn *MockConn) QueryRowPartial(v interface{}, q string, args ...interface
|
||||
}, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowPartialCtx executes sql and returns a partial query row
|
||||
func (conn *MockConn) QueryRowPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
|
||||
return conn.QueryRowPartial(v, query, args...)
|
||||
}
|
||||
|
||||
// QueryRows executes sql and returns query rows
|
||||
func (conn *MockConn) QueryRows(v interface{}, q string, args ...interface{}) error {
|
||||
return query(conn.db, func(rows *sql.Rows) error {
|
||||
@@ -56,6 +77,11 @@ func (conn *MockConn) QueryRows(v interface{}, q string, args ...interface{}) er
|
||||
}, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowsCtx executes sql and returns query rows
|
||||
func (conn *MockConn) QueryRowsCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
|
||||
return conn.QueryRows(v, query, args...)
|
||||
}
|
||||
|
||||
// QueryRowsPartial executes sql and returns partial query rows
|
||||
func (conn *MockConn) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
|
||||
return query(conn.db, func(rows *sql.Rows) error {
|
||||
@@ -63,6 +89,11 @@ func (conn *MockConn) QueryRowsPartial(v interface{}, q string, args ...interfac
|
||||
}, q, args...)
|
||||
}
|
||||
|
||||
// QueryRowsPartialCtx executes sql and returns partial query rows
|
||||
func (conn *MockConn) QueryRowsPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
|
||||
return conn.QueryRowsPartial(v, query, args...)
|
||||
}
|
||||
|
||||
// RawDB returns the underlying sql.DB.
|
||||
func (conn *MockConn) RawDB() (*sql.DB, error) {
|
||||
return conn.db, nil
|
||||
@@ -73,6 +104,11 @@ func (conn *MockConn) Transact(func(session sqlx.Session) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TransactCtx is the implemention of sqlx.SqlConn, nothing to do
|
||||
func (conn *MockConn) TransactCtx(ctx context.Context, fn func(context.Context, sqlx.Session) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s statement) Close() error {
|
||||
return s.stmt.Close()
|
||||
}
|
||||
@@ -81,26 +117,46 @@ func (s statement) Exec(args ...interface{}) (sql.Result, error) {
|
||||
return execStmt(s.stmt, args...)
|
||||
}
|
||||
|
||||
func (s statement) ExecCtx(_ context.Context, args ...interface{}) (sql.Result, error) {
|
||||
return s.Exec(args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRow(v interface{}, args ...interface{}) error {
|
||||
return queryStmt(s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRow(v, rows, true)
|
||||
}, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowCtx(_ context.Context, v interface{}, args ...interface{}) error {
|
||||
return s.QueryRow(v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartial(v interface{}, args ...interface{}) error {
|
||||
return queryStmt(s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRow(v, rows, false)
|
||||
}, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
|
||||
return s.QueryRowPartial(v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRows(v interface{}, args ...interface{}) error {
|
||||
return queryStmt(s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRows(v, rows, true)
|
||||
}, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsCtx(_ context.Context, v interface{}, args ...interface{}) error {
|
||||
return s.QueryRows(v, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartial(v interface{}, args ...interface{}) error {
|
||||
return queryStmt(s.stmt, func(rows *sql.Rows) error {
|
||||
return unmarshalRows(v, rows, false)
|
||||
}, args...)
|
||||
}
|
||||
|
||||
func (s statement) QueryRowsPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
|
||||
return s.QueryRowsPartial(v, args...)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
// GoBin returns a path of GOBIN.
|
||||
func GoBin() string {
|
||||
def := build.Default
|
||||
goroot := os.Getenv("GOROOT")
|
||||
goroot := os.Getenv("GOPATH")
|
||||
bin := filepath.Join(goroot, "bin")
|
||||
if !pathx.FileExists(bin) {
|
||||
gopath := os.Getenv("GOPATH")
|
||||
gopath := os.Getenv("GOROOT")
|
||||
bin = filepath.Join(gopath, "bin")
|
||||
}
|
||||
if !pathx.FileExists(bin) {
|
||||
|
||||
@@ -23,8 +23,11 @@ func Install(cacheDir string) (string, error) {
|
||||
}
|
||||
|
||||
func Exists() bool {
|
||||
_, err := env.LookUpProtocGenGo()
|
||||
return err == nil
|
||||
ver, err := Version()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return len(ver) > 0
|
||||
}
|
||||
|
||||
// Version is used to get the version of the protoc-gen-go plugin. For older versions, protoc-gen-go does not support
|
||||
|
||||
@@ -33,8 +33,9 @@ func RPC(c *cli.Context) error {
|
||||
goOptions := c.StringSlice("go_opt")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -89,8 +90,9 @@ func RPCNew(c *cli.Context) error {
|
||||
style := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -124,8 +126,9 @@ func RPCTemplate(c *cli.Context) error {
|
||||
protoFile := c.String("o")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/emicklei/proto"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/generator"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
@@ -15,17 +13,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidGrpcOutput = errors.New("ZRPC: missing grpc output")
|
||||
errInvalidGrpcOutput = errors.New("ZRPC: missing --go-grpc_out")
|
||||
errInvalidGoOutput = errors.New("ZRPC: missing --go_out")
|
||||
errInvalidZrpcOutput = errors.New("ZRPC: missing zrpc output, please use --zrpc_out to specify the output")
|
||||
errInvalidInput = errors.New("ZRPC: missing source")
|
||||
errMultiInput = errors.New("ZRPC: only one source is expected")
|
||||
)
|
||||
|
||||
const (
|
||||
optImport = "import"
|
||||
optSourceRelative = "source_relative"
|
||||
)
|
||||
|
||||
// ZRPC generates grpc code directly by protoc and generates
|
||||
// zrpc code by goctl.
|
||||
func ZRPC(c *cli.Context) error {
|
||||
@@ -40,22 +34,46 @@ func ZRPC(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
src := filepath.Dir(source)
|
||||
goPackage, protoPkg, err := getGoPackage(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
grpcOut := c.String("go-grpc_out")
|
||||
goOut := c.String("go_out")
|
||||
goOpt := c.String("go_opt")
|
||||
grpcOpt := c.String("go-grpc_opt")
|
||||
grpcOutList := c.StringSlice("go-grpc_out")
|
||||
goOutList := c.StringSlice("go_out")
|
||||
zrpcOut := c.String("zrpc_out")
|
||||
style := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(grpcOutList) == 0 {
|
||||
return errInvalidGrpcOutput
|
||||
}
|
||||
if len(goOutList) == 0 {
|
||||
return errInvalidGoOutput
|
||||
}
|
||||
goOut := goOutList[len(goOutList)-1]
|
||||
grpcOut := grpcOutList[len(grpcOutList)-1]
|
||||
if len(goOut) == 0 {
|
||||
return errInvalidGrpcOutput
|
||||
}
|
||||
if len(zrpcOut) == 0 {
|
||||
return errInvalidZrpcOutput
|
||||
}
|
||||
goOutAbs, err := filepath.Abs(goOut)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
grpcOutAbs, err := filepath.Abs(grpcOut)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = pathx.MkdirIfNotExist(goOutAbs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = pathx.MkdirIfNotExist(grpcOutAbs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -64,38 +82,11 @@ func ZRPC(c *cli.Context) error {
|
||||
if len(home) > 0 {
|
||||
pathx.RegisterGoctlHome(home)
|
||||
}
|
||||
if len(goOut) == 0 {
|
||||
return errInvalidGrpcOutput
|
||||
}
|
||||
if len(zrpcOut) == 0 {
|
||||
return errInvalidZrpcOutput
|
||||
}
|
||||
if !filepath.IsAbs(zrpcOut) {
|
||||
zrpcOut = filepath.Join(pwd, zrpcOut)
|
||||
}
|
||||
|
||||
goOut = removePluginFlag(goOut)
|
||||
goOut, err = parseOut(src, goOut, goOpt, goPackage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isGooglePlugin := len(grpcOut) > 0
|
||||
// If grpcOut is not empty means that user generates grpc code by
|
||||
// https://google.golang.org/protobuf/cmd/protoc-gen-go and
|
||||
// https://google.golang.org/grpc/cmd/protoc-gen-go-grpc,
|
||||
// for details please see https://grpc.io/docs/languages/go/quickstart/
|
||||
if isGooglePlugin {
|
||||
grpcOut, err = parseOut(src, grpcOut, grpcOpt, goPackage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Else it means that user generates grpc code by
|
||||
// https://github.com/golang/protobuf/tree/master/protoc-gen-go
|
||||
grpcOut = goOut
|
||||
}
|
||||
|
||||
goOut, err = filepath.Abs(goOut)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -109,23 +100,11 @@ func ZRPC(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if isGooglePlugin && grpcOut != goOut {
|
||||
return fmt.Errorf("the --go_out and --go-grpc_out must be the same")
|
||||
}
|
||||
|
||||
if goOut == zrpcOut || grpcOut == zrpcOut {
|
||||
recommendName := goPackage
|
||||
if len(recommendName) == 0 {
|
||||
recommendName = protoPkg
|
||||
}
|
||||
return fmt.Errorf("the zrpc and grpc output can not be the same, it is recommended to output grpc to the %q",
|
||||
filepath.Join(goOut, recommendName))
|
||||
}
|
||||
|
||||
var ctx generator.ZRpcContext
|
||||
ctx.Src = source
|
||||
ctx.ProtoGenGoDir = goOut
|
||||
ctx.ProtoGenGrpcDir = grpcOut
|
||||
ctx.GoOutput = goOut
|
||||
ctx.GrpcOutput = grpcOut
|
||||
ctx.IsGooglePlugin = isGooglePlugin
|
||||
ctx.Output = zrpcOut
|
||||
ctx.ProtocCmd = strings.Join(protocArgs, " ")
|
||||
g, err := generator.NewDefaultRPCGenerator(style, generator.WithZRpcContext(&ctx))
|
||||
@@ -136,52 +115,6 @@ func ZRPC(c *cli.Context) error {
|
||||
return g.Generate(source, zrpcOut, nil)
|
||||
}
|
||||
|
||||
// parseOut calculates the output place to grpc code, about to calculate logic for details
|
||||
// please see https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation.
|
||||
func parseOut(sourceDir, grpcOut, grpcOpt, goPackage string) (string, error) {
|
||||
if !filepath.IsAbs(grpcOut) {
|
||||
grpcOut = filepath.Join(sourceDir, grpcOut)
|
||||
}
|
||||
switch grpcOpt {
|
||||
case "", optImport:
|
||||
grpcOut = filepath.Join(grpcOut, goPackage)
|
||||
case optSourceRelative:
|
||||
grpcOut = filepath.Join(grpcOut)
|
||||
default:
|
||||
return "", fmt.Errorf("parseAndSetGrpcOut: unknown path type %q: want %q or %q",
|
||||
grpcOpt, optImport, optSourceRelative)
|
||||
}
|
||||
|
||||
return grpcOut, nil
|
||||
}
|
||||
|
||||
func getGoPackage(source string) (string, string, error) {
|
||||
r, err := os.Open(source)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
defer func() {
|
||||
_ = r.Close()
|
||||
}()
|
||||
|
||||
parser := proto.NewParser(r)
|
||||
set, err := parser.Parse()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
var goPackage, protoPkg string
|
||||
proto.Walk(set, proto.WithOption(func(option *proto.Option) {
|
||||
if option.Name == "go_package" {
|
||||
goPackage = option.Constant.Source
|
||||
}
|
||||
}), proto.WithPackage(func(p *proto.Package) {
|
||||
protoPkg = p.Name
|
||||
}))
|
||||
|
||||
return goPackage, protoPkg, nil
|
||||
}
|
||||
|
||||
func removeGoctlFlag(args []string) []string {
|
||||
var ret []string
|
||||
var step int
|
||||
|
||||
@@ -79,6 +79,10 @@ func Test_RemoveGoctlFlag(t *testing.T) {
|
||||
source: strings.Fields(`protoc foo.proto --go_opt=. --zrpc_out="bar" --style=goZero --home=bar`),
|
||||
expected: "protoc foo.proto --go_opt=.",
|
||||
},
|
||||
{
|
||||
source: strings.Fields(`protoc --go_opt=. --go-grpc_out=. --zrpc_out=. foo.proto`),
|
||||
expected: "protoc --go_opt=. --go-grpc_out=. foo.proto",
|
||||
},
|
||||
}
|
||||
for _, e := range testData {
|
||||
cmd := strings.Join(removeGoctlFlag(e.source), " ")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/env"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/console"
|
||||
)
|
||||
|
||||
@@ -25,17 +24,5 @@ func NewDefaultGenerator() Generator {
|
||||
// Prepare provides environment detection generated by rpc service,
|
||||
// including go environment, protoc, whether protoc-gen-go is installed or not
|
||||
func (g *DefaultGenerator) Prepare() error {
|
||||
_, err := exec.LookPath("go")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = exec.LookPath("protoc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = exec.LookPath("protoc-gen-go")
|
||||
|
||||
return err
|
||||
return env.Prepare(true, true)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ type ZRpcContext struct {
|
||||
ProtocCmd string
|
||||
ProtoGenGrpcDir string
|
||||
ProtoGenGoDir string
|
||||
IsGooglePlugin bool
|
||||
GoOutput string
|
||||
GrpcOutput string
|
||||
Output string
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ func main() {
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
srv := server.New{{.serviceNew}}Server(ctx)
|
||||
svr := server.New{{.serviceNew}}Server(ctx)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
{{.pkg}}.Register{{.service}}Server(grpcServer, srv)
|
||||
{{.pkg}}.Register{{.service}}Server(grpcServer, svr)
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
|
||||
@@ -3,6 +3,8 @@ package generator
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -19,7 +21,7 @@ const googleProtocGenGoErr = `--go_out: protoc-gen-go: plugins are not supported
|
||||
// but the commands and flags in protoc are not completely joined in goctl. At present, proto_path(-I) is introduced
|
||||
func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, _ *conf.Config, c *ZRpcContext, goOptions ...string) error {
|
||||
if c != nil {
|
||||
return g.genPbDirect(c)
|
||||
return g.genPbDirect(ctx, c)
|
||||
}
|
||||
|
||||
// deprecated: use genPbDirect instead.
|
||||
@@ -110,13 +112,74 @@ go get -u github.com/golang/protobuf/protoc-gen-go`)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *DefaultGenerator) genPbDirect(c *ZRpcContext) error {
|
||||
g.log.Debug(c.ProtocCmd)
|
||||
func (g *DefaultGenerator) genPbDirect(ctx DirContext, c *ZRpcContext) error {
|
||||
g.log.Debug("[command]: %s", c.ProtocCmd)
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = execx.Run(c.ProtocCmd, pwd)
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return g.setPbDir(ctx, c)
|
||||
}
|
||||
|
||||
func (g *DefaultGenerator) setPbDir(ctx DirContext, c *ZRpcContext) error {
|
||||
pbDir, err := findPbFile(c.GoOutput, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(pbDir) == 0 {
|
||||
return fmt.Errorf("pg.go is not found under %q", c.GoOutput)
|
||||
}
|
||||
grpcDir, err := findPbFile(c.GrpcOutput, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(grpcDir) == 0 {
|
||||
return fmt.Errorf("_grpc.pb.go is not found in %q", c.GrpcOutput)
|
||||
}
|
||||
if pbDir != grpcDir {
|
||||
return fmt.Errorf("the pb.go and _grpc.pb.go must under the same dir: "+
|
||||
"\n pb.go: %s\n_grpc.pb.go: %s", pbDir, grpcDir)
|
||||
}
|
||||
if pbDir == c.Output {
|
||||
return fmt.Errorf("the output of pb.go and _grpc.pb.go must not be the same "+
|
||||
"with --zrpc_out:\npb output: %s\nzrpc out: %s", pbDir, c.Output)
|
||||
}
|
||||
ctx.SetPbDir(pbDir, grpcDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
pbSuffix = "pb.go"
|
||||
grpcSuffix = "_grpc.pb.go"
|
||||
)
|
||||
|
||||
func findPbFile(current string, grpc bool) (string, error) {
|
||||
fileSystem := os.DirFS(current)
|
||||
var ret string
|
||||
err := fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if strings.HasSuffix(path, pbSuffix) {
|
||||
if grpc {
|
||||
if strings.HasSuffix(path, grpcSuffix) {
|
||||
ret = path
|
||||
return os.ErrExist
|
||||
}
|
||||
} else if !strings.HasSuffix(path, grpcSuffix) {
|
||||
ret = path
|
||||
return os.ErrExist
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err == os.ErrExist {
|
||||
return filepath.Dir(filepath.Join(current, ret)), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
197
tools/goctl/rpc/generator/genpb_test.go
Normal file
197
tools/goctl/rpc/generator/genpb_test.go
Normal file
@@ -0,0 +1,197 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
func Test_findPbFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
protoFile := filepath.Join(dir, "greet.proto")
|
||||
err := ioutil.WriteFile(protoFile, []byte(`
|
||||
syntax = "proto3";
|
||||
|
||||
package greet;
|
||||
option go_package="./greet";
|
||||
|
||||
message Req{}
|
||||
message Resp{}
|
||||
service Greeter {
|
||||
rpc greet(Req) returns (Resp);
|
||||
}
|
||||
`), 0666)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
t.Run("", func(t *testing.T) {
|
||||
output := t.TempDir()
|
||||
grpc := filepath.Join(output, "grpc")
|
||||
err := pathx.MkdirIfNotExist(grpc)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("protoc", "-I="+filepath.Dir(protoFile), "--go_out="+output, "--go-grpc_out="+grpc, filepath.Base(protoFile))
|
||||
cmd.Dir = output
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
pbDir, err := findPbFile(output, false)
|
||||
assert.Nil(t, err)
|
||||
pbGo := filepath.Join(pbDir, "greet.pb.go")
|
||||
assert.True(t, pathx.FileExists(pbGo))
|
||||
|
||||
grpcDir, err := findPbFile(output, true)
|
||||
assert.Nil(t, err)
|
||||
grpcGo := filepath.Join(grpcDir, "greet_grpc.pb.go")
|
||||
assert.True(t, pathx.FileExists(grpcGo))
|
||||
})
|
||||
|
||||
t.Run("", func(t *testing.T) {
|
||||
output := t.TempDir()
|
||||
redirect := filepath.Join(output, "pb")
|
||||
grpc := filepath.Join(output, "grpc")
|
||||
err := pathx.MkdirIfNotExist(grpc)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("protoc", "-I="+filepath.Dir(protoFile), "--go_out="+output,
|
||||
"--go-grpc_out="+grpc, filepath.Base(protoFile), "--go_opt=M"+filepath.Base(protoFile)+"="+redirect)
|
||||
cmd.Dir = output
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
pbDir, err := findPbFile(output, false)
|
||||
assert.Nil(t, err)
|
||||
pbGo := filepath.Join(pbDir, "greet.pb.go")
|
||||
assert.True(t, pathx.FileExists(pbGo))
|
||||
|
||||
grpcDir, err := findPbFile(output, true)
|
||||
assert.Nil(t, err)
|
||||
grpcGo := filepath.Join(grpcDir, "greet_grpc.pb.go")
|
||||
assert.True(t, pathx.FileExists(grpcGo))
|
||||
})
|
||||
|
||||
t.Run("", func(t *testing.T) {
|
||||
output := t.TempDir()
|
||||
pbeRedirect := filepath.Join(output, "redirect")
|
||||
grpc := filepath.Join(output, "grpc")
|
||||
grpcRedirect := filepath.Join(grpc, "redirect")
|
||||
err := pathx.MkdirIfNotExist(grpc)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("protoc", "-I="+filepath.Dir(protoFile), "--go_out="+output,
|
||||
"--go-grpc_out="+grpc, filepath.Base(protoFile), "--go_opt=M"+filepath.Base(protoFile)+"="+pbeRedirect,
|
||||
"--go-grpc_opt=M"+filepath.Base(protoFile)+"="+grpcRedirect)
|
||||
cmd.Dir = output
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
pbDir, err := findPbFile(output, false)
|
||||
assert.Nil(t, err)
|
||||
pbGo := filepath.Join(pbDir, "greet.pb.go")
|
||||
assert.True(t, pathx.FileExists(pbGo))
|
||||
|
||||
grpcDir, err := findPbFile(output, true)
|
||||
assert.Nil(t, err)
|
||||
grpcGo := filepath.Join(grpcDir, "greet_grpc.pb.go")
|
||||
assert.True(t, pathx.FileExists(grpcGo))
|
||||
})
|
||||
|
||||
t.Run("", func(t *testing.T) {
|
||||
output := t.TempDir()
|
||||
pbeRedirect := filepath.Join(output, "redirect")
|
||||
grpc := filepath.Join(output, "grpc")
|
||||
grpcRedirect := filepath.Join(grpc, "redirect")
|
||||
err := pathx.MkdirIfNotExist(grpc)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("protoc", "-I="+filepath.Dir(protoFile), "--go_out="+output,
|
||||
"--go-grpc_out="+grpc, filepath.Base(protoFile), "--go_opt=M"+filepath.Base(protoFile)+"="+pbeRedirect,
|
||||
"--go-grpc_opt=M"+filepath.Base(protoFile)+"="+grpcRedirect, "--go_opt=paths=import", "--go-grpc_opt=paths=source_relative")
|
||||
cmd.Dir = output
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
pbDir, err := findPbFile(output, false)
|
||||
assert.Nil(t, err)
|
||||
pbGo := filepath.Join(pbDir, "greet.pb.go")
|
||||
assert.True(t, pathx.FileExists(pbGo))
|
||||
|
||||
grpcDir, err := findPbFile(output, true)
|
||||
assert.Nil(t, err)
|
||||
grpcGo := filepath.Join(grpcDir, "greet_grpc.pb.go")
|
||||
assert.True(t, pathx.FileExists(grpcGo))
|
||||
})
|
||||
|
||||
t.Run("", func(t *testing.T) {
|
||||
output := t.TempDir()
|
||||
pbeRedirect := filepath.Join(output, "redirect")
|
||||
grpc := filepath.Join(output, "grpc")
|
||||
grpcRedirect := filepath.Join(grpc, "redirect")
|
||||
err := pathx.MkdirIfNotExist(grpc)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
err = pathx.MkdirIfNotExist(pbeRedirect)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
err = pathx.MkdirIfNotExist(grpcRedirect)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("protoc", "-I="+filepath.Dir(protoFile), "--go_out="+output,
|
||||
"--go-grpc_out="+grpc, filepath.Base(protoFile), "--go_opt=M"+filepath.Base(protoFile)+"="+pbeRedirect,
|
||||
"--go-grpc_opt=M"+filepath.Base(protoFile)+"="+grpcRedirect, "--go_opt=paths=import", "--go-grpc_opt=paths=source_relative",
|
||||
"--go_out="+pbeRedirect, "--go-grpc_out="+grpcRedirect)
|
||||
cmd.Dir = output
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
pbDir, err := findPbFile(output, false)
|
||||
assert.Nil(t, err)
|
||||
pbGo := filepath.Join(pbDir, "greet.pb.go")
|
||||
assert.True(t, pathx.FileExists(pbGo))
|
||||
|
||||
grpcDir, err := findPbFile(output, true)
|
||||
assert.Nil(t, err)
|
||||
grpcGo := filepath.Join(grpcDir, "greet_grpc.pb.go")
|
||||
assert.True(t, pathx.FileExists(grpcGo))
|
||||
})
|
||||
}
|
||||
@@ -38,6 +38,7 @@ type (
|
||||
GetProtoGo() Dir
|
||||
GetMain() Dir
|
||||
GetServiceName() stringx.String
|
||||
SetPbDir(pbDir, grpcDir string)
|
||||
}
|
||||
|
||||
// Dir defines a directory
|
||||
@@ -50,6 +51,7 @@ type (
|
||||
defaultDirContext struct {
|
||||
inner map[string]Dir
|
||||
serviceName stringx.String
|
||||
ctx *ctx.ProjectContext
|
||||
}
|
||||
)
|
||||
|
||||
@@ -134,11 +136,26 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto, _ *conf.Config, c *ZRpcC
|
||||
}
|
||||
serviceName := strings.TrimSuffix(proto.Name, filepath.Ext(proto.Name))
|
||||
return &defaultDirContext{
|
||||
ctx: ctx,
|
||||
inner: inner,
|
||||
serviceName: stringx.From(strings.ReplaceAll(serviceName, "-", "")),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *defaultDirContext) SetPbDir(pbDir, grpcDir string) {
|
||||
d.inner[pb] = Dir{
|
||||
Filename: pbDir,
|
||||
Package: filepath.ToSlash(filepath.Join(d.ctx.Path, strings.TrimPrefix(pbDir, d.ctx.Dir))),
|
||||
Base: filepath.Base(pbDir),
|
||||
}
|
||||
|
||||
d.inner[protoGo] = Dir{
|
||||
Filename: grpcDir,
|
||||
Package: filepath.ToSlash(filepath.Join(d.ctx.Path, strings.TrimPrefix(grpcDir, d.ctx.Dir))),
|
||||
Base: filepath.Base(grpcDir),
|
||||
}
|
||||
}
|
||||
|
||||
func (d *defaultDirContext) GetCall() Dir {
|
||||
return d.inner[call]
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
func CloneIntoGitHome(url string, branch string) (dir string, err error) {
|
||||
gitHome, err := pathx.GetGitHome()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -21,6 +21,9 @@ func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
ext := filepath.Ext(url)
|
||||
repo := strings.TrimSuffix(filepath.Base(url), ext)
|
||||
dir = filepath.Join(gitHome, repo)
|
||||
if pathx.FileExists(dir) {
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
path, err := env.LookPath("git")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -28,7 +31,12 @@ func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
if !env.CanExec() {
|
||||
return "", fmt.Errorf("os %q can not call 'exec' command", runtime.GOOS)
|
||||
}
|
||||
cmd := exec.Command(path, "clone", url, dir)
|
||||
args := []string{"clone"}
|
||||
if len(branch) > 0 {
|
||||
args = append(args, "-b", branch)
|
||||
}
|
||||
args = append(args, url, dir)
|
||||
cmd := exec.Command(path, args...)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -75,12 +75,23 @@ func FileNameWithoutExt(file string) string {
|
||||
|
||||
// GetGoctlHome returns the path value of the goctl, the default path is ~/.goctl, if the path has
|
||||
// been set by calling the RegisterGoctlHome method, the user-defined path refers to.
|
||||
func GetGoctlHome() (string, error) {
|
||||
func GetGoctlHome() (home string, err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
info, err := os.Stat(home)
|
||||
if err == nil && !info.IsDir() {
|
||||
os.Rename(home, home+".old")
|
||||
MkdirIfNotExist(home)
|
||||
}
|
||||
}()
|
||||
if len(goctlHome) != 0 {
|
||||
return goctlHome, nil
|
||||
home = goctlHome
|
||||
return
|
||||
}
|
||||
|
||||
return GetDefaultGoctlHome()
|
||||
home, err = GetDefaultGoctlHome()
|
||||
return
|
||||
}
|
||||
|
||||
// GetDefaultGoctlHome returns the path value of the goctl home where Join $HOME with .goctl.
|
||||
|
||||
@@ -74,3 +74,35 @@ func TestGetGitHome(t *testing.T) {
|
||||
expected := filepath.Join(homeDir, goctlDir, gitDir)
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestGetGoctlHome(t *testing.T) {
|
||||
t.Run("goctl_is_file", func(t *testing.T) {
|
||||
tmpFile := filepath.Join(t.TempDir(), "a.tmp")
|
||||
backupTempFile := tmpFile + ".old"
|
||||
err := ioutil.WriteFile(tmpFile, nil, 0666)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
RegisterGoctlHome(tmpFile)
|
||||
home, err := GetGoctlHome()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
info, err := os.Stat(home)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, info.IsDir())
|
||||
|
||||
_, err = os.Stat(backupTempFile)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("goctl_is_dir", func(t *testing.T) {
|
||||
RegisterGoctlHome("")
|
||||
dir := t.TempDir()
|
||||
RegisterGoctlHome(dir)
|
||||
home, err := GetGoctlHome()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, dir, home)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestBaseRpcServer_AddStreamInterceptors(t *testing.T) {
|
||||
server := newBaseRpcServer("foo", &rpcServerOptions{metrics: metrics})
|
||||
server.SetName("bar")
|
||||
var vals []int
|
||||
f := func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
f := func(_ interface{}, _ grpc.ServerStream, _ *grpc.StreamServerInfo, _ grpc.StreamHandler) error {
|
||||
vals = append(vals, 1)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
|
||||
// StreamAuthorizeInterceptor returns a func that uses given authenticator in processing stream requests.
|
||||
func StreamAuthorizeInterceptor(authenticator *auth.Authenticator) grpc.StreamServerInterceptor {
|
||||
return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
return func(svr interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
if err := authenticator.Authenticate(stream.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return handler(srv, stream)
|
||||
return handler(svr, stream)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestStreamAuthorizeInterceptor(t *testing.T) {
|
||||
})
|
||||
ctx := metadata.NewIncomingContext(context.Background(), md)
|
||||
stream := mockedStream{ctx: ctx}
|
||||
err = interceptor(nil, stream, nil, func(srv interface{}, stream grpc.ServerStream) error {
|
||||
err = interceptor(nil, stream, nil, func(_ interface{}, _ grpc.ServerStream) error {
|
||||
return nil
|
||||
})
|
||||
if test.hasError {
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
)
|
||||
|
||||
// StreamBreakerInterceptor is an interceptor that acts as a circuit breaker.
|
||||
func StreamBreakerInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
func StreamBreakerInterceptor(svr interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) (err error) {
|
||||
breakerName := info.FullMethod
|
||||
return breaker.DoWithAcceptable(breakerName, func() error {
|
||||
return handler(srv, stream)
|
||||
return handler(svr, stream)
|
||||
}, codes.Acceptable)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ import (
|
||||
func TestStreamBreakerInterceptor(t *testing.T) {
|
||||
err := StreamBreakerInterceptor(nil, nil, &grpc.StreamServerInfo{
|
||||
FullMethod: "any",
|
||||
}, func(
|
||||
srv interface{}, stream grpc.ServerStream) error {
|
||||
}, func(_ interface{}, _ grpc.ServerStream) error {
|
||||
return status.New(codes.DeadlineExceeded, "any").Err()
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
@@ -23,7 +22,7 @@ func TestStreamBreakerInterceptor(t *testing.T) {
|
||||
func TestUnaryBreakerInterceptor(t *testing.T) {
|
||||
_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
|
||||
FullMethod: "any",
|
||||
}, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
}, func(_ context.Context, _ interface{}) (interface{}, error) {
|
||||
return nil, status.New(codes.DeadlineExceeded, "any").Err()
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
|
||||
@@ -11,17 +11,17 @@ import (
|
||||
)
|
||||
|
||||
// StreamCrashInterceptor catches panics in processing stream requests and recovers.
|
||||
func StreamCrashInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
func StreamCrashInterceptor(svr interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) (err error) {
|
||||
defer handleCrash(func(r interface{}) {
|
||||
err = toPanicError(r)
|
||||
})
|
||||
|
||||
return handler(srv, stream)
|
||||
return handler(svr, stream)
|
||||
}
|
||||
|
||||
// UnaryCrashInterceptor catches panics in processing unary requests and recovers.
|
||||
func UnaryCrashInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
func UnaryCrashInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
defer handleCrash(func(r interface{}) {
|
||||
err = toPanicError(r)
|
||||
|
||||
@@ -15,7 +15,7 @@ func init() {
|
||||
|
||||
func TestStreamCrashInterceptor(t *testing.T) {
|
||||
err := StreamCrashInterceptor(nil, nil, nil, func(
|
||||
srv interface{}, stream grpc.ServerStream) error {
|
||||
svr interface{}, stream grpc.ServerStream) error {
|
||||
panic("mock panic")
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
|
||||
@@ -41,12 +41,12 @@ func UnaryTracingInterceptor(ctx context.Context, req interface{}, info *grpc.Un
|
||||
}
|
||||
|
||||
// StreamTracingInterceptor returns a grpc.StreamServerInterceptor for opentelemetry.
|
||||
func StreamTracingInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
func StreamTracingInterceptor(svr interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
ctx, span := startSpan(ss.Context(), info.FullMethod)
|
||||
defer span.End()
|
||||
|
||||
if err := handler(srv, wrapServerStream(ctx, ss)); err != nil {
|
||||
if err := handler(svr, wrapServerStream(ctx, ss)); err != nil {
|
||||
s, ok := status.FromError(err)
|
||||
if ok {
|
||||
span.SetStatus(codes.Error, s.Message())
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestStreamTracingInterceptor_GrpcFormat(t *testing.T) {
|
||||
stream := mockedServerStream{ctx: ctx}
|
||||
err := StreamTracingInterceptor(nil, &stream, &grpc.StreamServerInfo{
|
||||
FullMethod: "/foo",
|
||||
}, func(srv interface{}, stream grpc.ServerStream) error {
|
||||
}, func(svr interface{}, stream grpc.ServerStream) error {
|
||||
defer wg.Done()
|
||||
atomic.AddInt32(&run, 1)
|
||||
return nil
|
||||
@@ -138,7 +138,7 @@ func TestStreamTracingInterceptor_FinishWithGrpcError(t *testing.T) {
|
||||
stream := mockedServerStream{ctx: ctx}
|
||||
err := StreamTracingInterceptor(nil, &stream, &grpc.StreamServerInfo{
|
||||
FullMethod: "/foo",
|
||||
}, func(srv interface{}, stream grpc.ServerStream) error {
|
||||
}, func(svr interface{}, stream grpc.ServerStream) error {
|
||||
defer wg.Done()
|
||||
return test.err
|
||||
})
|
||||
@@ -175,7 +175,7 @@ func TestStreamTracingInterceptor_WithError(t *testing.T) {
|
||||
stream := mockedServerStream{ctx: ctx}
|
||||
err := StreamTracingInterceptor(nil, &stream, &grpc.StreamServerInfo{
|
||||
FullMethod: "/foo",
|
||||
}, func(srv interface{}, stream grpc.ServerStream) error {
|
||||
}, func(svr interface{}, stream grpc.ServerStream) error {
|
||||
defer wg.Done()
|
||||
return test.err
|
||||
})
|
||||
|
||||
@@ -12,20 +12,20 @@ import (
|
||||
|
||||
// A RpcProxy is a rpc proxy.
|
||||
type RpcProxy struct {
|
||||
backend string
|
||||
clients map[string]Client
|
||||
options []internal.ClientOption
|
||||
sharedCalls syncx.SingleFlight
|
||||
lock sync.Mutex
|
||||
backend string
|
||||
clients map[string]Client
|
||||
options []internal.ClientOption
|
||||
singleFlight syncx.SingleFlight
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// NewProxy returns a RpcProxy.
|
||||
func NewProxy(backend string, opts ...internal.ClientOption) *RpcProxy {
|
||||
return &RpcProxy{
|
||||
backend: backend,
|
||||
clients: make(map[string]Client),
|
||||
options: opts,
|
||||
sharedCalls: syncx.NewSingleFlight(),
|
||||
backend: backend,
|
||||
clients: make(map[string]Client),
|
||||
options: opts,
|
||||
singleFlight: syncx.NewSingleFlight(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func NewProxy(backend string, opts ...internal.ClientOption) *RpcProxy {
|
||||
func (p *RpcProxy) TakeConn(ctx context.Context) (*grpc.ClientConn, error) {
|
||||
cred := auth.ParseCredential(ctx)
|
||||
key := cred.App + "/" + cred.Token
|
||||
val, err := p.sharedCalls.Do(key, func() (interface{}, error) {
|
||||
val, err := p.singleFlight.Do(key, func() (interface{}, error) {
|
||||
p.lock.Lock()
|
||||
client, ok := p.clients[key]
|
||||
p.lock.Unlock()
|
||||
|
||||
@@ -64,3 +64,9 @@ func TestProxy(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRpcProxy_TakeConnNewClientFailed(t *testing.T) {
|
||||
proxy := NewProxy("foo", WithDialOption(grpc.WithInsecure()), WithDialOption(grpc.WithBlock()))
|
||||
_, err := proxy.TakeConn(context.Background())
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestServer_setupInterceptors(t *testing.T) {
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
SetServerSlowThreshold(time.Second)
|
||||
srv := MustNewServer(RpcServerConf{
|
||||
svr := MustNewServer(RpcServerConf{
|
||||
ServiceConf: service.ServiceConf{
|
||||
Log: logx.LogConf{
|
||||
ServiceName: "foo",
|
||||
@@ -52,11 +52,11 @@ func TestServer(t *testing.T) {
|
||||
CpuThreshold: 0,
|
||||
}, func(server *grpc.Server) {
|
||||
})
|
||||
srv.AddOptions(grpc.ConnectionTimeout(time.Hour))
|
||||
srv.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
|
||||
srv.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
|
||||
go srv.Start()
|
||||
srv.Stop()
|
||||
svr.AddOptions(grpc.ConnectionTimeout(time.Hour))
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
|
||||
svr.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
|
||||
go svr.Start()
|
||||
svr.Stop()
|
||||
}
|
||||
|
||||
func TestServerError(t *testing.T) {
|
||||
@@ -79,7 +79,7 @@ func TestServerError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_HasEtcd(t *testing.T) {
|
||||
srv := MustNewServer(RpcServerConf{
|
||||
svr := MustNewServer(RpcServerConf{
|
||||
ServiceConf: service.ServiceConf{
|
||||
Log: logx.LogConf{
|
||||
ServiceName: "foo",
|
||||
@@ -94,11 +94,26 @@ func TestServer_HasEtcd(t *testing.T) {
|
||||
Redis: redis.RedisKeyConf{},
|
||||
}, func(server *grpc.Server) {
|
||||
})
|
||||
srv.AddOptions(grpc.ConnectionTimeout(time.Hour))
|
||||
srv.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
|
||||
srv.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
|
||||
go srv.Start()
|
||||
srv.Stop()
|
||||
svr.AddOptions(grpc.ConnectionTimeout(time.Hour))
|
||||
svr.AddUnaryInterceptors(serverinterceptors.UnaryCrashInterceptor)
|
||||
svr.AddStreamInterceptors(serverinterceptors.StreamCrashInterceptor)
|
||||
go svr.Start()
|
||||
svr.Stop()
|
||||
}
|
||||
|
||||
func TestServer_StartFailed(t *testing.T) {
|
||||
svr := MustNewServer(RpcServerConf{
|
||||
ServiceConf: service.ServiceConf{
|
||||
Log: logx.LogConf{
|
||||
ServiceName: "foo",
|
||||
Mode: "console",
|
||||
},
|
||||
},
|
||||
ListenOn: "localhost:aaa",
|
||||
}, func(server *grpc.Server) {
|
||||
})
|
||||
|
||||
assert.Panics(t, svr.Start)
|
||||
}
|
||||
|
||||
type mockedServer struct {
|
||||
|
||||
Reference in New Issue
Block a user