mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: update code format. (#628)
This commit is contained in:
parent
7e087de6e6
commit
afd9ff889e
@ -122,8 +122,7 @@ func BenchmarkGoogleBreaker(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
type mockedPromise struct {
|
||||
}
|
||||
type mockedPromise struct{}
|
||||
|
||||
func (m *mockedPromise) Accept() {
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func TestAesEcbBase64(t *testing.T) {
|
||||
// more than 32 chars
|
||||
badKey2 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
)
|
||||
var key = []byte("q4t7w!z%C*F-JaNdRgUjXn2r5u8x/A?D")
|
||||
key := []byte("q4t7w!z%C*F-JaNdRgUjXn2r5u8x/A?D")
|
||||
b64Key := base64.StdEncoding.EncodeToString(key)
|
||||
b64Val := base64.StdEncoding.EncodeToString([]byte(val))
|
||||
_, err := EcbEncryptBase64(badKey1, val)
|
||||
|
@ -139,7 +139,7 @@ func TestRollingWindowBucketTimeBoundary(t *testing.T) {
|
||||
func TestRollingWindowDataRace(t *testing.T) {
|
||||
const size = 3
|
||||
r := NewRollingWindow(size, duration)
|
||||
var stop = make(chan bool)
|
||||
stop := make(chan bool)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestChain(t *testing.T) {
|
||||
var errDummy = errors.New("dummy")
|
||||
errDummy := errors.New("dummy")
|
||||
assert.Nil(t, Chain(func() error {
|
||||
return nil
|
||||
}, func() error {
|
||||
|
@ -15,7 +15,7 @@ type (
|
||||
|
||||
// DoWithRetry runs fn, and retries if failed. Default to retry 3 times.
|
||||
func DoWithRetry(fn func() error, opts ...RetryOption) error {
|
||||
var options = newRetryOptions()
|
||||
options := newRetryOptions()
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestRetry(t *testing.T) {
|
||||
return errors.New("any")
|
||||
}))
|
||||
|
||||
var total = 2 * defaultRetryTimes
|
||||
total := 2 * defaultRetryTimes
|
||||
times = 0
|
||||
assert.Nil(t, DoWithRetry(func() error {
|
||||
times++
|
||||
|
@ -168,7 +168,7 @@ func (as *adaptiveShedder) maxPass() int64 {
|
||||
}
|
||||
|
||||
func (as *adaptiveShedder) minRt() float64 {
|
||||
var result = defaultMinRt
|
||||
result := defaultMinRt
|
||||
|
||||
as.rtCounter.Reduce(func(b *collection.Bucket) {
|
||||
if b.Count <= 0 {
|
||||
|
@ -201,7 +201,7 @@ func BenchmarkAdaptiveShedder_Allow(b *testing.B) {
|
||||
logx.Disable()
|
||||
|
||||
bench := func(b *testing.B) {
|
||||
var shedder = NewAdaptiveShedder()
|
||||
shedder := NewAdaptiveShedder()
|
||||
proba := mathx.NewProba()
|
||||
for i := 0; i < 6000; i++ {
|
||||
p, err := shedder.Allow()
|
||||
|
@ -1,7 +1,6 @@
|
||||
package load
|
||||
|
||||
type nopShedder struct {
|
||||
}
|
||||
type nopShedder struct{}
|
||||
|
||||
func newNopShedder() Shedder {
|
||||
return nopShedder{}
|
||||
@ -11,8 +10,7 @@ func (s nopShedder) Allow() (Promise, error) {
|
||||
return nopPromise{}, nil
|
||||
}
|
||||
|
||||
type nopPromise struct {
|
||||
}
|
||||
type nopPromise struct{}
|
||||
|
||||
func (p nopPromise) Pass() {
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ const (
|
||||
dateFormat = "2006-01-02"
|
||||
hoursPerDay = 24
|
||||
bufferSize = 100
|
||||
defaultDirMode = 0755
|
||||
defaultFileMode = 0600
|
||||
defaultDirMode = 0o755
|
||||
defaultFileMode = 0o600
|
||||
)
|
||||
|
||||
// ErrLogFileClosed is an error that indicates the log file is already closed.
|
||||
|
@ -752,7 +752,7 @@ func TestUnmarshalJsonNumberInt64(t *testing.T) {
|
||||
for i := 0; i <= maxUintBitsToTest; i++ {
|
||||
var intValue int64 = 1 << uint(i)
|
||||
strValue := strconv.FormatInt(intValue, 10)
|
||||
var number = json.Number(strValue)
|
||||
number := json.Number(strValue)
|
||||
m := map[string]interface{}{
|
||||
"ID": number,
|
||||
}
|
||||
@ -768,7 +768,7 @@ func TestUnmarshalJsonNumberUint64(t *testing.T) {
|
||||
for i := 0; i <= maxUintBitsToTest; i++ {
|
||||
var intValue uint64 = 1 << uint(i)
|
||||
strValue := strconv.FormatUint(intValue, 10)
|
||||
var number = json.Number(strValue)
|
||||
number := json.Number(strValue)
|
||||
m := map[string]interface{}{
|
||||
"ID": number,
|
||||
}
|
||||
@ -784,7 +784,7 @@ func TestUnmarshalJsonNumberUint64Ptr(t *testing.T) {
|
||||
for i := 0; i <= maxUintBitsToTest; i++ {
|
||||
var intValue uint64 = 1 << uint(i)
|
||||
strValue := strconv.FormatUint(intValue, 10)
|
||||
var number = json.Number(strValue)
|
||||
number := json.Number(strValue)
|
||||
m := map[string]interface{}{
|
||||
"ID": number,
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ type Foo struct {
|
||||
}
|
||||
|
||||
func TestDeferInt(t *testing.T) {
|
||||
var i = 1
|
||||
var s = "hello"
|
||||
i := 1
|
||||
s := "hello"
|
||||
number := struct {
|
||||
f float64
|
||||
}{
|
||||
|
@ -84,8 +84,7 @@ func (p *mockedProducer) Produce() (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
type mockedListener struct {
|
||||
}
|
||||
type mockedListener struct{}
|
||||
|
||||
func (l *mockedListener) OnPause() {
|
||||
}
|
||||
|
@ -95,8 +95,7 @@ func WithStarter(start Starter) Service {
|
||||
}
|
||||
|
||||
type (
|
||||
stopper struct {
|
||||
}
|
||||
stopper struct{}
|
||||
|
||||
startOnlyService struct {
|
||||
start func()
|
||||
|
@ -70,7 +70,7 @@ func TestServiceGroup_WithStart(t *testing.T) {
|
||||
wait.Add(len(multipliers))
|
||||
group := NewServiceGroup()
|
||||
for _, multiplier := range multipliers {
|
||||
var mul = multiplier
|
||||
mul := multiplier
|
||||
group.Add(WithStart(func() {
|
||||
lock.Lock()
|
||||
want *= mul
|
||||
@ -97,7 +97,7 @@ func TestServiceGroup_WithStarter(t *testing.T) {
|
||||
wait.Add(len(multipliers))
|
||||
group := NewServiceGroup()
|
||||
for _, multiplier := range multipliers {
|
||||
var mul = multiplier
|
||||
mul := multiplier
|
||||
group.Add(WithStarter(mockedStarter{
|
||||
fn: func() {
|
||||
lock.Lock()
|
||||
|
2
core/stores/cache/cachenode_test.go
vendored
2
core/stores/cache/cachenode_test.go
vendored
@ -129,7 +129,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
|
||||
assert.True(t, cn.IsNotFound(cn.Get("any", &str)))
|
||||
|
||||
store.Del("any")
|
||||
var errDummy = errors.New("dummy")
|
||||
errDummy := errors.New("dummy")
|
||||
err = cn.Take(&str, "any", func(v interface{}) error {
|
||||
return errDummy
|
||||
})
|
||||
|
@ -12,8 +12,10 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var s1, _ = miniredis.Run()
|
||||
var s2, _ = miniredis.Run()
|
||||
var (
|
||||
s1, _ = miniredis.Run()
|
||||
s2, _ = miniredis.Run()
|
||||
)
|
||||
|
||||
func TestRedis_Exists(t *testing.T) {
|
||||
store := clusterStore{dispatcher: hash.NewConsistentHash()}
|
||||
|
@ -279,8 +279,7 @@ func (p *mockPromise) Reject(reason string) {
|
||||
p.reason = reason
|
||||
}
|
||||
|
||||
type dropBreaker struct {
|
||||
}
|
||||
type dropBreaker struct{}
|
||||
|
||||
func (d *dropBreaker) Name() string {
|
||||
return "dummy"
|
||||
|
@ -945,7 +945,6 @@ func (s *Redis) Pipelined(fn func(Pipeliner) error) (err error) {
|
||||
|
||||
_, err = conn.Pipelined(fn)
|
||||
return err
|
||||
|
||||
}, acceptable)
|
||||
|
||||
return
|
||||
|
@ -384,7 +384,6 @@ func TestRedis_BitCount(t *testing.T) {
|
||||
val, err = client.BitCount("key", 2, 2)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(0), val)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -401,7 +400,7 @@ func TestRedis_BitOpAnd(t *testing.T) {
|
||||
assert.Equal(t, int64(1), val)
|
||||
valStr, err := client.Get("destKey")
|
||||
assert.Nil(t, err)
|
||||
//destKey binary 110000 ascii 0
|
||||
// destKey binary 110000 ascii 0
|
||||
assert.Equal(t, "0", valStr)
|
||||
})
|
||||
}
|
||||
@ -454,9 +453,10 @@ func TestRedis_BitOpXor(t *testing.T) {
|
||||
assert.Equal(t, "\xf0", valStr)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRedis_BitPos(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
//11111111 11110000 00000000
|
||||
// 11111111 11110000 00000000
|
||||
err := client.Set("key", "\xff\xf0\x00")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@ -481,7 +481,6 @@ func TestRedis_BitPos(t *testing.T) {
|
||||
val, err = client.BitPos("key", 1, 2, 2)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(-1), val)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -1035,7 +1034,7 @@ func TestRedisBlpopEx(t *testing.T) {
|
||||
func TestRedisGeo(t *testing.T) {
|
||||
runOnRedis(t, func(client *Redis) {
|
||||
client.Ping()
|
||||
var geoLocation = []*GeoLocation{{Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"}, {Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"}}
|
||||
geoLocation := []*GeoLocation{{Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"}, {Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"}}
|
||||
v, err := client.GeoAdd("sicily", geoLocation...)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(2), v)
|
||||
@ -1053,7 +1052,7 @@ func TestRedisGeo(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(v4[0].Dist), int64(190))
|
||||
assert.Equal(t, int64(v4[1].Dist), int64(56))
|
||||
var geoLocation2 = []*GeoLocation{{Longitude: 13.583333, Latitude: 37.316667, Name: "Agrigento"}}
|
||||
geoLocation2 := []*GeoLocation{{Longitude: 13.583333, Latitude: 37.316667, Name: "Agrigento"}}
|
||||
v5, err := client.GeoAdd("sicily", geoLocation2...)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), v5)
|
||||
@ -1087,7 +1086,6 @@ func runOnRedis(t *testing.T, fn func(client *Redis)) {
|
||||
}
|
||||
}()
|
||||
fn(NewRedis(s.Addr(), NodeType))
|
||||
|
||||
}
|
||||
|
||||
func runOnRedisTLS(t *testing.T, fn func(client *Redis)) {
|
||||
|
@ -53,7 +53,8 @@ func NewRedisLock(store *Redis, key string) *RedisLock {
|
||||
func (rl *RedisLock) Acquire() (bool, error) {
|
||||
seconds := atomic.LoadUint32(&rl.seconds)
|
||||
resp, err := rl.store.Eval(lockCommand, []string{rl.key}, []string{
|
||||
rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance)})
|
||||
rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance),
|
||||
})
|
||||
if err == red.Nil {
|
||||
return false, nil
|
||||
} else if err != nil {
|
||||
|
@ -206,7 +206,7 @@ func TestUnmarshalRowString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowStruct(t *testing.T) {
|
||||
var value = new(struct {
|
||||
value := new(struct {
|
||||
Name string
|
||||
Age int
|
||||
})
|
||||
@ -224,7 +224,7 @@ func TestUnmarshalRowStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowStructWithTags(t *testing.T) {
|
||||
var value = new(struct {
|
||||
value := new(struct {
|
||||
Age int `db:"age"`
|
||||
Name string `db:"name"`
|
||||
})
|
||||
@ -242,7 +242,7 @@ func TestUnmarshalRowStructWithTags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowStructWithTagsWrongColumns(t *testing.T) {
|
||||
var value = new(struct {
|
||||
value := new(struct {
|
||||
Age *int `db:"age"`
|
||||
Name string `db:"name"`
|
||||
})
|
||||
@ -259,7 +259,7 @@ func TestUnmarshalRowStructWithTagsWrongColumns(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsBool(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []bool{true, false}
|
||||
expect := []bool{true, false}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("1\n0")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -273,7 +273,7 @@ func TestUnmarshalRowsBool(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsInt(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []int{2, 3}
|
||||
expect := []int{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -287,7 +287,7 @@ func TestUnmarshalRowsInt(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsInt8(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []int8{2, 3}
|
||||
expect := []int8{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -301,7 +301,7 @@ func TestUnmarshalRowsInt8(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsInt16(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []int16{2, 3}
|
||||
expect := []int16{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -315,7 +315,7 @@ func TestUnmarshalRowsInt16(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsInt32(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []int32{2, 3}
|
||||
expect := []int32{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -329,7 +329,7 @@ func TestUnmarshalRowsInt32(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsInt64(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []int64{2, 3}
|
||||
expect := []int64{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -343,7 +343,7 @@ func TestUnmarshalRowsInt64(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsUint(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []uint{2, 3}
|
||||
expect := []uint{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -357,7 +357,7 @@ func TestUnmarshalRowsUint(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsUint8(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []uint8{2, 3}
|
||||
expect := []uint8{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -371,7 +371,7 @@ func TestUnmarshalRowsUint8(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsUint16(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []uint16{2, 3}
|
||||
expect := []uint16{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -385,7 +385,7 @@ func TestUnmarshalRowsUint16(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsUint32(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []uint32{2, 3}
|
||||
expect := []uint32{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -399,7 +399,7 @@ func TestUnmarshalRowsUint32(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsUint64(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []uint64{2, 3}
|
||||
expect := []uint64{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -413,7 +413,7 @@ func TestUnmarshalRowsUint64(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsFloat32(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []float32{2, 3}
|
||||
expect := []float32{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -427,7 +427,7 @@ func TestUnmarshalRowsFloat32(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsFloat64(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []float64{2, 3}
|
||||
expect := []float64{2, 3}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -441,7 +441,7 @@ func TestUnmarshalRowsFloat64(t *testing.T) {
|
||||
|
||||
func TestUnmarshalRowsString(t *testing.T) {
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []string{"hello", "world"}
|
||||
expect := []string{"hello", "world"}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("hello\nworld")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -457,7 +457,7 @@ func TestUnmarshalRowsBoolPtr(t *testing.T) {
|
||||
yes := true
|
||||
no := false
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*bool{&yes, &no}
|
||||
expect := []*bool{&yes, &no}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("1\n0")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -473,7 +473,7 @@ func TestUnmarshalRowsIntPtr(t *testing.T) {
|
||||
two := 2
|
||||
three := 3
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*int{&two, &three}
|
||||
expect := []*int{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -489,7 +489,7 @@ func TestUnmarshalRowsInt8Ptr(t *testing.T) {
|
||||
two := int8(2)
|
||||
three := int8(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*int8{&two, &three}
|
||||
expect := []*int8{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -505,7 +505,7 @@ func TestUnmarshalRowsInt16Ptr(t *testing.T) {
|
||||
two := int16(2)
|
||||
three := int16(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*int16{&two, &three}
|
||||
expect := []*int16{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -521,7 +521,7 @@ func TestUnmarshalRowsInt32Ptr(t *testing.T) {
|
||||
two := int32(2)
|
||||
three := int32(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*int32{&two, &three}
|
||||
expect := []*int32{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -537,7 +537,7 @@ func TestUnmarshalRowsInt64Ptr(t *testing.T) {
|
||||
two := int64(2)
|
||||
three := int64(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*int64{&two, &three}
|
||||
expect := []*int64{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -553,7 +553,7 @@ func TestUnmarshalRowsUintPtr(t *testing.T) {
|
||||
two := uint(2)
|
||||
three := uint(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*uint{&two, &three}
|
||||
expect := []*uint{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -569,7 +569,7 @@ func TestUnmarshalRowsUint8Ptr(t *testing.T) {
|
||||
two := uint8(2)
|
||||
three := uint8(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*uint8{&two, &three}
|
||||
expect := []*uint8{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -585,7 +585,7 @@ func TestUnmarshalRowsUint16Ptr(t *testing.T) {
|
||||
two := uint16(2)
|
||||
three := uint16(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*uint16{&two, &three}
|
||||
expect := []*uint16{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -601,7 +601,7 @@ func TestUnmarshalRowsUint32Ptr(t *testing.T) {
|
||||
two := uint32(2)
|
||||
three := uint32(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*uint32{&two, &three}
|
||||
expect := []*uint32{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -617,7 +617,7 @@ func TestUnmarshalRowsUint64Ptr(t *testing.T) {
|
||||
two := uint64(2)
|
||||
three := uint64(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*uint64{&two, &three}
|
||||
expect := []*uint64{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -633,7 +633,7 @@ func TestUnmarshalRowsFloat32Ptr(t *testing.T) {
|
||||
two := float32(2)
|
||||
three := float32(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*float32{&two, &three}
|
||||
expect := []*float32{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -649,7 +649,7 @@ func TestUnmarshalRowsFloat64Ptr(t *testing.T) {
|
||||
two := float64(2)
|
||||
three := float64(3)
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*float64{&two, &three}
|
||||
expect := []*float64{&two, &three}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("2\n3")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -665,7 +665,7 @@ func TestUnmarshalRowsStringPtr(t *testing.T) {
|
||||
hello := "hello"
|
||||
world := "world"
|
||||
runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
|
||||
var expect = []*string{&hello, &world}
|
||||
expect := []*string{&hello, &world}
|
||||
rs := sqlmock.NewRows([]string{"value"}).FromCSVString("hello\nworld")
|
||||
mock.ExpectQuery("select (.+) from users where user=?").WithArgs("anyone").WillReturnRows(rs)
|
||||
|
||||
@ -678,7 +678,7 @@ func TestUnmarshalRowsStringPtr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStruct(t *testing.T) {
|
||||
var expect = []struct {
|
||||
expect := []struct {
|
||||
Name string
|
||||
Age int64
|
||||
}{
|
||||
@ -711,7 +711,7 @@ func TestUnmarshalRowsStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStructWithNullStringType(t *testing.T) {
|
||||
var expect = []struct {
|
||||
expect := []struct {
|
||||
Name string
|
||||
NullString sql.NullString
|
||||
}{
|
||||
@ -752,7 +752,7 @@ func TestUnmarshalRowsStructWithNullStringType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStructWithTags(t *testing.T) {
|
||||
var expect = []struct {
|
||||
expect := []struct {
|
||||
Name string
|
||||
Age int64
|
||||
}{
|
||||
@ -789,7 +789,7 @@ func TestUnmarshalRowsStructAndEmbeddedAnonymousStructWithTags(t *testing.T) {
|
||||
Value int64 `db:"value"`
|
||||
}
|
||||
|
||||
var expect = []struct {
|
||||
expect := []struct {
|
||||
Name string
|
||||
Age int64
|
||||
Value int64
|
||||
@ -831,7 +831,7 @@ func TestUnmarshalRowsStructAndEmbeddedStructPtrAnonymousWithTags(t *testing.T)
|
||||
Value int64 `db:"value"`
|
||||
}
|
||||
|
||||
var expect = []struct {
|
||||
expect := []struct {
|
||||
Name string
|
||||
Age int64
|
||||
Value int64
|
||||
@ -869,7 +869,7 @@ func TestUnmarshalRowsStructAndEmbeddedStructPtrAnonymousWithTags(t *testing.T)
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStructPtr(t *testing.T) {
|
||||
var expect = []*struct {
|
||||
expect := []*struct {
|
||||
Name string
|
||||
Age int64
|
||||
}{
|
||||
@ -902,7 +902,7 @@ func TestUnmarshalRowsStructPtr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStructWithTagsPtr(t *testing.T) {
|
||||
var expect = []*struct {
|
||||
expect := []*struct {
|
||||
Name string
|
||||
Age int64
|
||||
}{
|
||||
@ -935,7 +935,7 @@ func TestUnmarshalRowsStructWithTagsPtr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalRowsStructWithTagsPtrWithInnerPtr(t *testing.T) {
|
||||
var expect = []*struct {
|
||||
expect := []*struct {
|
||||
Name string
|
||||
Age int64
|
||||
}{
|
||||
|
@ -16,7 +16,7 @@ type (
|
||||
|
||||
// NewReplacer returns a Replacer.
|
||||
func NewReplacer(mapping map[string]string) Replacer {
|
||||
var rep = &replacer{
|
||||
rep := &replacer{
|
||||
mapping: mapping,
|
||||
}
|
||||
for k := range mapping {
|
||||
@ -28,9 +28,9 @@ func NewReplacer(mapping map[string]string) Replacer {
|
||||
|
||||
func (r *replacer) Replace(text string) string {
|
||||
var builder strings.Builder
|
||||
var chars = []rune(text)
|
||||
var size = len(chars)
|
||||
var start = -1
|
||||
chars := []rune(text)
|
||||
size := len(chars)
|
||||
start := -1
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
child, ok := r.children[chars[i]]
|
||||
@ -42,12 +42,12 @@ func (r *replacer) Replace(text string) string {
|
||||
if start < 0 {
|
||||
start = i
|
||||
}
|
||||
var end = -1
|
||||
end := -1
|
||||
if child.end {
|
||||
end = i + 1
|
||||
}
|
||||
|
||||
var j = i + 1
|
||||
j := i + 1
|
||||
for ; j < size; j++ {
|
||||
grandchild, ok := child.children[chars[j]]
|
||||
if !ok {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestReplacer_Replace(t *testing.T) {
|
||||
var mapping = map[string]string{
|
||||
mapping := map[string]string{
|
||||
"一二三四": "1234",
|
||||
"二三": "23",
|
||||
"二": "2",
|
||||
@ -16,28 +16,28 @@ func TestReplacer_Replace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReplacer_ReplaceSingleChar(t *testing.T) {
|
||||
var mapping = map[string]string{
|
||||
mapping := map[string]string{
|
||||
"二": "2",
|
||||
}
|
||||
assert.Equal(t, "零一2三四五", NewReplacer(mapping).Replace("零一二三四五"))
|
||||
}
|
||||
|
||||
func TestReplacer_ReplaceExceedRange(t *testing.T) {
|
||||
var mapping = map[string]string{
|
||||
mapping := map[string]string{
|
||||
"二三四五六": "23456",
|
||||
}
|
||||
assert.Equal(t, "零一二三四五", NewReplacer(mapping).Replace("零一二三四五"))
|
||||
}
|
||||
|
||||
func TestReplacer_ReplacePartialMatch(t *testing.T) {
|
||||
var mapping = map[string]string{
|
||||
mapping := map[string]string{
|
||||
"二三四七": "2347",
|
||||
}
|
||||
assert.Equal(t, "零一二三四五", NewReplacer(mapping).Replace("零一二三四五"))
|
||||
}
|
||||
|
||||
func TestReplacer_ReplaceMultiMatches(t *testing.T) {
|
||||
var mapping = map[string]string{
|
||||
mapping := map[string]string{
|
||||
"二三": "23",
|
||||
}
|
||||
assert.Equal(t, "零一23四五一23四五", NewReplacer(mapping).Replace("零一二三四五一二三四五"))
|
||||
|
@ -154,8 +154,7 @@ Verbose: true
|
||||
}
|
||||
}
|
||||
|
||||
type mockedRouter struct {
|
||||
}
|
||||
type mockedRouter struct{}
|
||||
|
||||
func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
@ -94,8 +94,7 @@ func (s mockShedder) Allow() (load.Promise, error) {
|
||||
return nil, load.ErrServiceOverloaded
|
||||
}
|
||||
|
||||
type mockPromise struct {
|
||||
}
|
||||
type mockPromise struct{}
|
||||
|
||||
func (p mockPromise) Pass() {
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ Future {{pathToFuncName .Path}}( {{if ne .Method "get"}}{{with .RequestType}}{{.
|
||||
{{end}}`
|
||||
|
||||
func genApi(dir string, api *spec.ApiSpec) error {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -39,7 +39,7 @@ func genApi(dir string, api *spec.ApiSpec) error {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -60,7 +60,7 @@ func genApiFile(dir string) error {
|
||||
if fileExists(path) {
|
||||
return nil
|
||||
}
|
||||
apiFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
apiFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class {{.Name}}{
|
||||
`
|
||||
|
||||
func genData(dir string, api *spec.ApiSpec) error {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -42,7 +42,7 @@ func genData(dir string, api *spec.ApiSpec) error {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
file, err := os.OpenFile(dir+api.Service.Name+".dart", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -64,7 +64,7 @@ func genTokens(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
tokensFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
tokensFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -41,20 +41,20 @@ Future<Tokens> getTokens() async {
|
||||
`
|
||||
|
||||
func genVars(dir string) error {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
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';`), 0644)
|
||||
err = ioutil.WriteFile(dir+"vars.dart", []byte(`const serverHost='demo-crm.xiaoheiban.cn';`), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !fileExists(dir + "kv.dart") {
|
||||
err = ioutil.WriteFile(dir+"kv.dart", []byte(varTemplate), 0644)
|
||||
err = ioutil.WriteFile(dir+"kv.dart", []byte(varTemplate), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func buildDoc(route spec.Type) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var tps = make([]spec.Type, 0)
|
||||
tps := make([]spec.Type, 0)
|
||||
tps = append(tps, route)
|
||||
if definedType, ok := route.(spec.DefineStruct); ok {
|
||||
associatedTypes(definedType, &tps)
|
||||
@ -98,7 +98,7 @@ func buildDoc(route spec.Type) (string, error) {
|
||||
}
|
||||
|
||||
func associatedTypes(tp spec.DefineStruct, tps *[]spec.Type) {
|
||||
var hasAdded = false
|
||||
hasAdded := false
|
||||
for _, item := range *tps {
|
||||
if item.Name() == tp.Name() {
|
||||
hasAdded = true
|
||||
|
@ -107,8 +107,8 @@ func apiFormat(data string) (string, error) {
|
||||
|
||||
var builder strings.Builder
|
||||
s := bufio.NewScanner(strings.NewReader(data))
|
||||
var tapCount = 0
|
||||
var newLineCount = 0
|
||||
tapCount := 0
|
||||
newLineCount := 0
|
||||
var preLine string
|
||||
for s.Scan() {
|
||||
line := strings.TrimSpace(s.Text())
|
||||
|
@ -35,12 +35,12 @@ func genConfig(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var authNames = getAuths(api)
|
||||
authNames := getAuths(api)
|
||||
var auths []string
|
||||
for _, item := range authNames {
|
||||
auths = append(auths, fmt.Sprintf("%s %s", item, jwtTemplate))
|
||||
}
|
||||
var authImportStr = fmt.Sprintf("\"%s/rest\"", vars.ProjectOpenSourceURL)
|
||||
authImportStr := fmt.Sprintf("\"%s/rest\"", vars.ProjectOpenSourceURL)
|
||||
|
||||
return genFile(fileGenConfig{
|
||||
dir: dir,
|
||||
|
@ -31,7 +31,7 @@ func (m *{{.name}})Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
`
|
||||
|
||||
func genMiddleware(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
var middlewares = getMiddleware(api)
|
||||
middlewares := getMiddleware(api)
|
||||
for _, item := range middlewares {
|
||||
middlewareFilename := strings.TrimSuffix(strings.ToLower(item), "middleware") + "_middleware"
|
||||
filename, err := format.FileNamingFormat(cfg.NamingFormat, middlewareFilename)
|
||||
|
@ -95,11 +95,11 @@ func genRoutes(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
var routes string
|
||||
if len(g.middlewares) > 0 {
|
||||
gbuilder.WriteString("\n}...,")
|
||||
var params = g.middlewares
|
||||
params := g.middlewares
|
||||
for i := range params {
|
||||
params[i] = "serverCtx." + params[i]
|
||||
}
|
||||
var middlewareStr = strings.Join(params, ", ")
|
||||
middlewareStr := strings.Join(params, ", ")
|
||||
routes = fmt.Sprintf("rest.WithMiddlewares(\n[]rest.Middleware{ %s }, \n %s \n),",
|
||||
middlewareStr, strings.TrimSpace(gbuilder.String()))
|
||||
} else {
|
||||
@ -146,7 +146,7 @@ func genRoutes(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
||||
}
|
||||
|
||||
func genRouteImports(parentPkg string, api *spec.ApiSpec) string {
|
||||
var importSet = collection.NewSet()
|
||||
importSet := collection.NewSet()
|
||||
importSet.AddStr(fmt.Sprintf("\"%s\"", util.JoinPackages(parentPkg, contextDir)))
|
||||
for _, group := range api.Service.Groups {
|
||||
for _, route := range group.Routes {
|
||||
|
@ -39,7 +39,7 @@ func genServiceContext(dir string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
return err
|
||||
}
|
||||
|
||||
var authNames = getAuths(api)
|
||||
authNames := getAuths(api)
|
||||
var auths []string
|
||||
for _, item := range authNames {
|
||||
auths = append(auths, fmt.Sprintf("%s config.AuthConfig", item))
|
||||
@ -52,7 +52,7 @@ func genServiceContext(dir string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
|
||||
var middlewareStr string
|
||||
var middlewareAssignment string
|
||||
var middlewares = getMiddleware(api)
|
||||
middlewares := getMiddleware(api)
|
||||
|
||||
for _, item := range middlewares {
|
||||
middlewareStr += fmt.Sprintf("%s rest.Middleware\n", item)
|
||||
@ -61,7 +61,7 @@ func genServiceContext(dir string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
fmt.Sprintf("middleware.New%s().%s", strings.Title(name), "Handle"))
|
||||
}
|
||||
|
||||
var configImport = "\"" + ctlutil.JoinPackages(parentPkg, configDir) + "\""
|
||||
configImport := "\"" + ctlutil.JoinPackages(parentPkg, configDir) + "\""
|
||||
if len(middlewareStr) > 0 {
|
||||
configImport += "\n\t\"" + ctlutil.JoinPackages(parentPkg, middlewareDir) + "\""
|
||||
configImport += fmt.Sprintf("\n\t\"%s/rest\"", vars.ProjectOpenSourceURL)
|
||||
|
@ -277,15 +277,15 @@ func (c *componentsContext) buildConstructor() (string, string, error) {
|
||||
}
|
||||
|
||||
func (c *componentsContext) genGetSet(writer io.Writer, indent int) error {
|
||||
var members = c.members
|
||||
members := c.members
|
||||
for _, member := range members {
|
||||
javaType, err := specTypeToJava(member.Type)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var property = util.Title(member.Name)
|
||||
var templateStr = getSetTemplate
|
||||
property := util.Title(member.Name)
|
||||
templateStr := getSetTemplate
|
||||
if javaType == "boolean" {
|
||||
templateStr = boolTemplate
|
||||
property = strings.TrimPrefix(property, "Is")
|
||||
|
@ -67,7 +67,7 @@ func createWith(dir string, api *spec.ApiSpec, route spec.Route, packetName stri
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
var hasRequestBody = false
|
||||
hasRequestBody := false
|
||||
if route.RequestType != nil {
|
||||
if defineStruct, ok := route.RequestType.(spec.DefineStruct); ok {
|
||||
hasRequestBody = len(defineStruct.GetBodyMembers()) > 0 || len(defineStruct.GetFormMembers()) > 0
|
||||
|
@ -61,7 +61,7 @@ func writeIndent(writer io.Writer, indent int) {
|
||||
}
|
||||
|
||||
func indentString(indent int) string {
|
||||
var result = ""
|
||||
result := ""
|
||||
for i := 0; i < indent; i++ {
|
||||
result += "\t"
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ object {{with .Info}}{{.Title}}{{end}}{
|
||||
)
|
||||
|
||||
func genBase(dir, pkg string, api *spec.ApiSpec) error {
|
||||
e := os.MkdirAll(dir, 0755)
|
||||
e := os.MkdirAll(dir, 0o755)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
@ -108,7 +108,7 @@ func genBase(dir, pkg string, api *spec.ApiSpec) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
file, e := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
file, e := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o644)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
@ -146,12 +146,12 @@ func genApi(dir, pkg string, api *spec.ApiSpec) error {
|
||||
api.Info.Title = name
|
||||
api.Info.Desc = desc
|
||||
|
||||
e := os.MkdirAll(dir, 0755)
|
||||
e := os.MkdirAll(dir, 0o755)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
file, e := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
file, e := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ func (p *Parser) valid(mainApi *Api, nestedApi *Api) error {
|
||||
for _, g := range list {
|
||||
handler := g.GetHandler()
|
||||
if handler.IsNotNil() {
|
||||
var handlerName = handler.Text()
|
||||
handlerName := handler.Text()
|
||||
handlerMap[handlerName] = Holder
|
||||
path := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
||||
routeMap[path] = Holder
|
||||
|
@ -289,7 +289,7 @@ func (v *ApiVisitor) getHiddenTokensToLeft(t TokenStream, channel int, containsC
|
||||
|
||||
if index > 0 {
|
||||
allTokens := ct.GetAllTokens()
|
||||
var flag = false
|
||||
flag := false
|
||||
for i := index; i >= 0; i-- {
|
||||
tk := allTokens[i]
|
||||
if tk.GetChannel() == antlr.LexerDefaultTokenChannel {
|
||||
|
@ -128,7 +128,6 @@ func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) interface{} {
|
||||
var types []TypeExpr
|
||||
for _, each := range list {
|
||||
types = append(types, each.Accept(v).(TypeExpr))
|
||||
|
||||
}
|
||||
return types
|
||||
}
|
||||
@ -155,7 +154,6 @@ func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) interface{} {
|
||||
st.Name = v.newExprWithToken(ctx.GetStructName())
|
||||
|
||||
if util.UnExport(ctx.GetStructName().GetText()) {
|
||||
|
||||
}
|
||||
if ctx.GetStructToken() != nil {
|
||||
structExpr := v.newExprWithToken(ctx.GetStructToken())
|
||||
|
@ -10,8 +10,10 @@ import (
|
||||
)
|
||||
|
||||
// Suppress unused import error
|
||||
var _ = fmt.Printf
|
||||
var _ = unicode.IsLetter
|
||||
var (
|
||||
_ = fmt.Printf
|
||||
_ = unicode.IsLetter
|
||||
)
|
||||
|
||||
var serializedLexerAtn = []uint16{
|
||||
3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 25, 266,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,8 +16,9 @@ const (
|
||||
tagRegex = `(?m)\x60[a-z]+:".+"\x60`
|
||||
)
|
||||
|
||||
var holder = struct{}{}
|
||||
var kind = map[string]struct{}{
|
||||
var (
|
||||
holder = struct{}{}
|
||||
kind = map[string]struct{}{
|
||||
"bool": holder,
|
||||
"int": holder,
|
||||
"int8": holder,
|
||||
@ -37,7 +38,8 @@ var kind = map[string]struct{}{
|
||||
"string": holder,
|
||||
"byte": holder,
|
||||
"rune": holder,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func match(p *ApiParserParser, text string) {
|
||||
v := getCurrentTokenText(p)
|
||||
|
@ -145,7 +145,6 @@ line"`),
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
t.Run("mismatched", func(t *testing.T) {
|
||||
|
@ -120,7 +120,8 @@ func TestRoute(t *testing.T) {
|
||||
PointerExpr: ast.NewTextExpr("*Bar"),
|
||||
Star: ast.NewTextExpr("*"),
|
||||
Name: ast.NewTextExpr("Bar"),
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
@ -224,7 +225,6 @@ func TestAtHandler(t *testing.T) {
|
||||
_, err = parser.Accept(fn, `@handler "foo"`)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestAtDoc(t *testing.T) {
|
||||
|
@ -64,7 +64,7 @@ func (p parser) convert2Spec() error {
|
||||
}
|
||||
|
||||
func (p parser) fillInfo() {
|
||||
var properties = make(map[string]string, 0)
|
||||
properties := make(map[string]string, 0)
|
||||
if p.ast.Info != nil {
|
||||
p.spec.Info = spec.Info{}
|
||||
for _, kv := range p.ast.Info.Kvs {
|
||||
@ -147,8 +147,8 @@ func (p parser) findDefinedType(name string) (*spec.Type, error) {
|
||||
}
|
||||
|
||||
func (p parser) fieldToMember(field *ast.TypeField) spec.Member {
|
||||
var name = ""
|
||||
var tag = ""
|
||||
name := ""
|
||||
tag := ""
|
||||
if !field.IsAnonymous {
|
||||
name = field.Name.Text()
|
||||
if field.Tag == nil {
|
||||
@ -239,7 +239,7 @@ func (p parser) fillService() error {
|
||||
route.ResponseType = p.astTypeToSpec(astRoute.Route.Reply.Name)
|
||||
}
|
||||
if astRoute.AtDoc != nil {
|
||||
var properties = make(map[string]string, 0)
|
||||
properties := make(map[string]string, 0)
|
||||
for _, kv := range astRoute.AtDoc.Kv {
|
||||
properties[kv.Key.Text()] = kv.Value.Text()
|
||||
}
|
||||
@ -271,7 +271,7 @@ func (p parser) fillService() error {
|
||||
|
||||
func (p parser) fillRouteAtServer(astRoute *ast.ServiceRoute, route *spec.Route) error {
|
||||
if astRoute.AtServer != nil {
|
||||
var properties = make(map[string]string, 0)
|
||||
properties := make(map[string]string, 0)
|
||||
for _, kv := range astRoute.AtServer.Kv {
|
||||
properties[kv.Key.Text()] = kv.Value.Text()
|
||||
}
|
||||
@ -295,7 +295,7 @@ func (p parser) fillRouteAtServer(astRoute *ast.ServiceRoute, route *spec.Route)
|
||||
|
||||
func (p parser) fillAtServer(item *ast.Service, group *spec.Group) {
|
||||
if item.AtServer != nil {
|
||||
var properties = make(map[string]string, 0)
|
||||
properties := make(map[string]string, 0)
|
||||
for _, kv := range item.AtServer.Kv {
|
||||
properties[kv.Key.Text()] = kv.Value.Text()
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func WriteIndent(writer io.Writer, indent int) {
|
||||
|
||||
// RemoveComment filters comment content
|
||||
func RemoveComment(line string) string {
|
||||
var commentIdx = strings.Index(line, "//")
|
||||
commentIdx := strings.Index(line, "//")
|
||||
if commentIdx >= 0 {
|
||||
return strings.TrimSpace(line[:commentIdx])
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func TestDo(t *testing.T) {
|
||||
|
||||
tempDir := t.TempDir()
|
||||
typesfile := filepath.Join(tempDir, "types.go")
|
||||
err = ioutil.WriteFile(typesfile, []byte(testTypes), 0666)
|
||||
err = ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = Do(&Context{
|
||||
|
@ -68,7 +68,7 @@ func TestBuilderSql(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildSqlDefaultValue(t *testing.T) {
|
||||
var eq = builder.Eq{}
|
||||
eq := builder.Eq{}
|
||||
eq["age"] = 0
|
||||
eq["user_name"] = ""
|
||||
|
||||
|
@ -230,7 +230,7 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
||||
return "", err
|
||||
}
|
||||
|
||||
var findCode = make([]string, 0)
|
||||
findCode := make([]string, 0)
|
||||
findOneCode, findOneCodeMethod, err := genFindOne(table, withCache)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -15,9 +15,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/tools/goctl/model/sql/builderx"
|
||||
)
|
||||
|
||||
var (
|
||||
source = "CREATE TABLE `test_user` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `mobile` varchar(255) COLLATE utf8mb4_bin NOT NULL,\n `class` bigint NOT NULL,\n `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,\n `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n UNIQUE KEY `mobile_unique` (`mobile`),\n UNIQUE KEY `class_name_unique` (`class`,`name`),\n KEY `create_index` (`create_time`),\n KEY `name_index` (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"
|
||||
)
|
||||
var source = "CREATE TABLE `test_user` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `mobile` varchar(255) COLLATE utf8mb4_bin NOT NULL,\n `class` bigint NOT NULL,\n `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,\n `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n UNIQUE KEY `mobile_unique` (`mobile`),\n UNIQUE KEY `class_name_unique` (`class`,`name`),\n KEY `create_index` (`create_time`),\n KEY `name_index` (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"
|
||||
|
||||
func TestCacheModel(t *testing.T) {
|
||||
logx.Disable()
|
||||
|
@ -134,7 +134,6 @@ func TestGenCacheKeys(t *testing.T) {
|
||||
return true
|
||||
}())
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func cacheKeyEqual(k1 Key, k2 Key) bool {
|
||||
@ -161,5 +160,4 @@ func cacheKeyEqual(k1 Key, k2 Key) bool {
|
||||
k1.DataKeyRight == k2.DataKeyRight &&
|
||||
k1.DataKeyExpression == k2.DataKeyExpression &&
|
||||
k1.KeyExpression == k2.KeyExpression
|
||||
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ func convertColumns(columns []*sqlparser.ColumnDefinition, primaryColumn string)
|
||||
comment = string(column.Type.Comment.Val)
|
||||
}
|
||||
|
||||
var isDefaultNull = true
|
||||
isDefaultNull := true
|
||||
if column.Type.NotNull {
|
||||
isDefaultNull = false
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ func PluginCommand(c *cli.Context) error {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var plugin = c.String("plugin")
|
||||
plugin := c.String("plugin")
|
||||
if len(plugin) == 0 {
|
||||
return errors.New("missing plugin")
|
||||
}
|
||||
@ -113,7 +113,7 @@ func getCommand(arg string) (string, bool, error) {
|
||||
return abs, false, nil
|
||||
}
|
||||
|
||||
var defaultErr = errors.New("invalid plugin value " + arg)
|
||||
defaultErr := errors.New("invalid plugin value " + arg)
|
||||
if strings.HasPrefix(arg, "http") {
|
||||
items := strings.Split(arg, "/")
|
||||
if len(items) == 0 {
|
||||
|
@ -89,7 +89,7 @@ func (g *DefaultGenerator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf
|
||||
return err
|
||||
}
|
||||
|
||||
var alias = collection.NewSet()
|
||||
alias := collection.NewSet()
|
||||
for _, item := range proto.Message {
|
||||
alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(item.Name), fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(item.Name))))
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func (g *DefaultGenerator) GenLogic(ctx DirContext, proto parser.Proto, cfg *con
|
||||
}
|
||||
|
||||
func (g *DefaultGenerator) genLogicFunction(goPackage string, rpc *parser.RPC) (string, error) {
|
||||
var functions = make([]string, 0)
|
||||
functions := make([]string, 0)
|
||||
text, err := util.LoadTemplate(category, logicFuncTemplateFileFile, logicFunctionTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -164,6 +164,7 @@ func CamelCase(s string) string {
|
||||
}
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func isASCIILower(c byte) bool {
|
||||
return 'a' <= c && c <= 'z'
|
||||
}
|
||||
|
@ -21,11 +21,9 @@ type (
|
||||
MarkDone()
|
||||
Must(err error)
|
||||
}
|
||||
colorConsole struct {
|
||||
}
|
||||
colorConsole struct{}
|
||||
// for idea log
|
||||
ideaConsole struct {
|
||||
}
|
||||
ideaConsole struct{}
|
||||
)
|
||||
|
||||
// NewConsole returns an instance of Console
|
||||
|
@ -61,8 +61,8 @@ func FindGoModPath(dir string) (string, bool) {
|
||||
|
||||
absDir = strings.ReplaceAll(absDir, `\`, `/`)
|
||||
var rootPath string
|
||||
var tempPath = absDir
|
||||
var hasGoMod = false
|
||||
tempPath := absDir
|
||||
hasGoMod := false
|
||||
for {
|
||||
if FileExists(filepath.Join(tempPath, goModeIdentifier)) {
|
||||
rootPath = strings.TrimPrefix(absDir[len(tempPath):], "/")
|
||||
|
@ -42,7 +42,7 @@ func (s String) ReplaceAll(old, new string) string {
|
||||
return strings.ReplaceAll(s.source, old, new)
|
||||
}
|
||||
|
||||
//Source returns the source string value
|
||||
// Source returns the source string value
|
||||
func (s String) Source() string {
|
||||
return s.source
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
const regularPerm = 0666
|
||||
const regularPerm = 0o666
|
||||
|
||||
// DefaultTemplate is a tool to provides the text/template operations
|
||||
type DefaultTemplate struct {
|
||||
|
@ -36,8 +36,7 @@ func init() {
|
||||
balancer.Register(newBuilder())
|
||||
}
|
||||
|
||||
type p2cPickerBuilder struct {
|
||||
}
|
||||
type p2cPickerBuilder struct{}
|
||||
|
||||
func newBuilder() balancer.Builder {
|
||||
return base.NewBalancerBuilder(Name, new(p2cPickerBuilder))
|
||||
|
@ -103,8 +103,7 @@ func TestP2cPicker_Pick(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type mockClientConn struct {
|
||||
}
|
||||
type mockClientConn struct{}
|
||||
|
||||
func (m mockClientConn) UpdateAddresses(addresses []resolver.Address) {
|
||||
}
|
||||
|
@ -14,9 +14,11 @@ It has these top-level messages:
|
||||
*/
|
||||
package mock
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
fmt "fmt"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
@ -24,9 +26,11 @@ import (
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
var (
|
||||
_ = proto.Marshal
|
||||
_ = fmt.Errorf
|
||||
_ = math.Inf
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
@ -72,8 +76,10 @@ func init() {
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
var (
|
||||
_ context.Context
|
||||
_ grpc.ClientConn
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
|
@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// DepositServer is used for mocking.
|
||||
type DepositServer struct {
|
||||
}
|
||||
type DepositServer struct{}
|
||||
|
||||
// Deposit handles the deposit requests.
|
||||
func (*DepositServer) Deposit(ctx context.Context, req *DepositRequest) (*DepositResponse, error) {
|
||||
|
@ -67,8 +67,7 @@ func (m mockedShedder) Allow() (load.Promise, error) {
|
||||
return nil, load.ErrServiceOverloaded
|
||||
}
|
||||
|
||||
type mockedPromise struct {
|
||||
}
|
||||
type mockedPromise struct{}
|
||||
|
||||
func (m mockedPromise) Pass() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user