Skip to content

Commit

Permalink
chore(format): change by gofumpt tool (zeromicro#697)
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored May 18, 2021
1 parent 73417f5 commit 73906f9
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/breaker/googlebreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (b *googleBreaker) markFailure() {
b.stat.Add(0)
}

func (b *googleBreaker) history() (accepts int64, total int64) {
func (b *googleBreaker) history() (accepts, total int64) {
b.stat.Reduce(func(b *collection.Bucket) {
accepts += int64(b.Sum)
total += b.Count
Expand Down
2 changes: 1 addition & 1 deletion core/collection/timingwheel.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (tw *TimingWheel) drainAll(fn func(key, value interface{})) {
}
}

func (tw *TimingWheel) getPositionAndCircle(d time.Duration) (pos int, circle int) {
func (tw *TimingWheel) getPositionAndCircle(d time.Duration) (pos, circle int) {
steps := int(d / tw.interval)
pos = (tw.tickedPos + steps) % tw.numSlots
circle = (steps - 1) / tw.numSlots
Expand Down
2 changes: 1 addition & 1 deletion core/discov/internal/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package internal

// Listener interface wraps the OnUpdate method.
type Listener interface {
OnUpdate(keys []string, values []string, newKey string)
OnUpdate(keys, values []string, newKey string)
}
2 changes: 1 addition & 1 deletion core/hash/consistenthash.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h *ConsistentHash) AddWithReplicas(node interface{}, replicas int) {
h.ring[hash] = append(h.ring[hash], node)
}

sort.Slice(h.keys, func(i int, j int) bool {
sort.Slice(h.keys, func(i, j int) bool {
return h.keys[i] < h.keys[j]
})
}
Expand Down
2 changes: 1 addition & 1 deletion core/logx/tracelogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ func (t mockTrace) Follow(ctx context.Context, serviceName, operationName string
return nil, nil
}

func (t mockTrace) Visit(fn func(key string, val string) bool) {
func (t mockTrace) Visit(fn func(key, val string) bool) {
}
2 changes: 1 addition & 1 deletion core/mapping/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func parseNumberRange(str string) (*numberRange, error) {
}, nil
}

func parseOption(fieldOpts *fieldOptions, fieldName string, option string) error {
func parseOption(fieldOpts *fieldOptions, fieldName, option string) error {
switch {
case option == stringOption:
fieldOpts.FromString = true
Expand Down
2 changes: 1 addition & 1 deletion core/stores/cache/cachenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c cacheNode) doTake(v interface{}, key string, query func(v interface{}) e
return jsonx.Unmarshal(val.([]byte), v)
}

func (c cacheNode) processCache(key string, data string, v interface{}) error {
func (c cacheNode) processCache(key, data string, v interface{}) error {
err := jsonx.Unmarshal([]byte(data), v)
if err == nil {
return nil
Expand Down
16 changes: 8 additions & 8 deletions core/stores/kv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type (
// Store interface represents a KV store.
Store interface {
Del(keys ...string) (int, error)
Eval(script string, key string, args ...interface{}) (interface{}, error)
Eval(script, key string, args ...interface{}) (interface{}, error)
Exists(key string) (bool, error)
Expire(key string, seconds int) error
Expireat(key string, expireTime int64) error
Expand All @@ -39,15 +39,15 @@ type (
Llen(key string) (int, error)
Lpop(key string) (string, error)
Lpush(key string, values ...interface{}) (int, error)
Lrange(key string, start int, stop int) ([]string, error)
Lrange(key string, start, stop int) ([]string, error)
Lrem(key string, count int, value string) (int, error)
Persist(key string) (bool, error)
Pfadd(key string, values ...interface{}) (bool, error)
Pfcount(key string) (int64, error)
Rpush(key string, values ...interface{}) (int, error)
Sadd(key string, values ...interface{}) (int, error)
Scard(key string) (int64, error)
Set(key string, value string) error
Set(key, value string) error
Setex(key, value string, seconds int) error
Setnx(key, value string) (bool, error)
SetnxEx(key, value string, seconds int) (bool, error)
Expand All @@ -74,7 +74,7 @@ type (
Zrevrange(key string, start, stop int64) ([]string, error)
ZrevrangebyscoreWithScores(key string, start, stop int64) ([]redis.Pair, error)
ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) ([]redis.Pair, error)
Zscore(key string, value string) (int64, error)
Zscore(key, value string) (int64, error)
Zrevrank(key, field string) (int64, error)
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func (cs clusterStore) Del(keys ...string) (int, error) {
return val, be.Err()
}

func (cs clusterStore) Eval(script string, key string, args ...interface{}) (interface{}, error) {
func (cs clusterStore) Eval(script, key string, args ...interface{}) (interface{}, error) {
node, err := cs.getRedis(key)
if err != nil {
return nil, err
Expand Down Expand Up @@ -321,7 +321,7 @@ func (cs clusterStore) Lpush(key string, values ...interface{}) (int, error) {
return node.Lpush(key, values...)
}

func (cs clusterStore) Lrange(key string, start int, stop int) ([]string, error) {
func (cs clusterStore) Lrange(key string, start, stop int) ([]string, error) {
node, err := cs.getRedis(key)
if err != nil {
return nil, err
Expand Down Expand Up @@ -393,7 +393,7 @@ func (cs clusterStore) Scard(key string) (int64, error) {
return node.Scard(key)
}

func (cs clusterStore) Set(key string, value string) error {
func (cs clusterStore) Set(key, value string) error {
node, err := cs.getRedis(key)
if err != nil {
return err
Expand Down Expand Up @@ -648,7 +648,7 @@ func (cs clusterStore) Zrevrank(key, field string) (int64, error) {
return node.Zrevrank(key, field)
}

func (cs clusterStore) Zscore(key string, value string) (int64, error) {
func (cs clusterStore) Zscore(key, value string) (int64, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
Expand Down
12 changes: 6 additions & 6 deletions core/stores/mongoc/cachedcollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type (
CachedCollection interface {
Count(query interface{}) (int, error)
DelCache(keys ...string) error
FindAllNoCache(v interface{}, query interface{}, opts ...QueryOption) error
FindAllNoCache(v, query interface{}, opts ...QueryOption) error
FindOne(v interface{}, key string, query interface{}) error
FindOneNoCache(v interface{}, query interface{}) error
FindOneNoCache(v, query interface{}) error
FindOneId(v interface{}, key string, id interface{}) error
FindOneIdNoCache(v interface{}, id interface{}) error
FindOneIdNoCache(v, id interface{}) error
GetCache(key string, v interface{}) error
Insert(docs ...interface{}) error
Pipe(pipeline interface{}) mongo.Pipe
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *cachedCollection) DelCache(keys ...string) error {
return c.cache.Del(keys...)
}

func (c *cachedCollection) FindAllNoCache(v interface{}, query interface{}, opts ...QueryOption) error {
func (c *cachedCollection) FindAllNoCache(v, query interface{}, opts ...QueryOption) error {
q := c.collection.Find(query)
for _, opt := range opts {
q = opt(q)
Expand All @@ -83,7 +83,7 @@ func (c *cachedCollection) FindOne(v interface{}, key string, query interface{})
})
}

func (c *cachedCollection) FindOneNoCache(v interface{}, query interface{}) error {
func (c *cachedCollection) FindOneNoCache(v, query interface{}) error {
q := c.collection.Find(query)
return q.One(v)
}
Expand All @@ -95,7 +95,7 @@ func (c *cachedCollection) FindOneId(v interface{}, key string, id interface{})
})
}

func (c *cachedCollection) FindOneIdNoCache(v interface{}, id interface{}) error {
func (c *cachedCollection) FindOneIdNoCache(v, id interface{}) error {
q := c.collection.FindId(id)
return q.One(v)
}
Expand Down
6 changes: 3 additions & 3 deletions core/stores/mongoc/cachedmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (mm *Model) GetCollection(session *mgo.Session) CachedCollection {
}

// FindAllNoCache finds all records without cache.
func (mm *Model) FindAllNoCache(v interface{}, query interface{}, opts ...QueryOption) error {
func (mm *Model) FindAllNoCache(v, query interface{}, opts ...QueryOption) error {
return mm.execute(func(c CachedCollection) error {
return c.FindAllNoCache(v, query, opts...)
})
Expand All @@ -89,7 +89,7 @@ func (mm *Model) FindOne(v interface{}, key string, query interface{}) error {
}

// FindOneNoCache unmarshals a record into v with query, without cache.
func (mm *Model) FindOneNoCache(v interface{}, query interface{}) error {
func (mm *Model) FindOneNoCache(v, query interface{}) error {
return mm.execute(func(c CachedCollection) error {
return c.FindOneNoCache(v, query)
})
Expand All @@ -103,7 +103,7 @@ func (mm *Model) FindOneId(v interface{}, key string, id interface{}) error {
}

// FindOneIdNoCache unmarshals a record into v with query, without cache.
func (mm *Model) FindOneIdNoCache(v interface{}, id interface{}) error {
func (mm *Model) FindOneIdNoCache(v, id interface{}) error {
return mm.execute(func(c CachedCollection) error {
return c.FindOneIdNoCache(v, id)
})
Expand Down
12 changes: 6 additions & 6 deletions core/stores/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *Redis) BitOpXor(destKey string, keys ...string) (val int64, err error)
}

// BitPos is redis bitpos command implementation.
func (s *Redis) BitPos(key string, bit int64, start, end int64) (val int64, err error) {
func (s *Redis) BitPos(key string, bit, start, end int64) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *Redis) GeoAdd(key string, geoLocation ...*GeoLocation) (val int64, err
}

// GeoDist is the implementation of redis geodist command.
func (s *Redis) GeoDist(key string, member1, member2, unit string) (val float64, err error) {
func (s *Redis) GeoDist(key, member1, member2, unit string) (val float64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down Expand Up @@ -795,7 +795,7 @@ func (s *Redis) Lpush(key string, values ...interface{}) (val int, err error) {
}

// Lrange is the implementation of redis lrange command.
func (s *Redis) Lrange(key string, start int, stop int) (val []string, err error) {
func (s *Redis) Lrange(key string, start, stop int) (val []string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ func (s *Redis) ScriptLoad(script string) (string, error) {
}

// Set is the implementation of redis set command.
func (s *Redis) Set(key string, value string) error {
func (s *Redis) Set(key, value string) error {
return s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down Expand Up @@ -1412,7 +1412,7 @@ func (s *Redis) Zincrby(key string, increment int64, field string) (val int64, e
}

// Zscore is the implementation of redis zscore command.
func (s *Redis) Zscore(key string, value string) (val int64, err error) {
func (s *Redis) Zscore(key, value string) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down Expand Up @@ -1684,7 +1684,7 @@ func (s *Redis) ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64
}

// Zrevrank is the implementation of redis zrevrank command.
func (s *Redis) Zrevrank(key string, field string) (val int64, err error) {
func (s *Redis) Zrevrank(key, field string) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/stringx/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Reverse(s string) string {
}

// Substr returns runes between start and stop [start, stop) regardless of the chars are ascii or utf8.
func Substr(str string, start int, stop int) (string, error) {
func Substr(str string, start, stop int) (string, error) {
rs := []rune(str)
length := len(rs)

Expand Down
2 changes: 1 addition & 1 deletion rest/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type mockedRouter struct{}
func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
}

func (m mockedRouter) Handle(method string, path string, handler http.Handler) error {
func (m mockedRouter) Handle(method, path string, handler http.Handler) error {
return errors.New("foo")
}

Expand Down
2 changes: 1 addition & 1 deletion rest/httpx/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "net/http"
// Router interface represents a http router that handles http requests.
type Router interface {
http.Handler
Handle(method string, path string, handler http.Handler) error
Handle(method, path string, handler http.Handler) error
SetNotFoundHandler(handler http.Handler)
SetNotAllowedHandler(handler http.Handler)
}
2 changes: 1 addition & 1 deletion tools/goctl/api/docgen/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
`
)

func genDoc(api *spec.ApiSpec, dir string, filename string) error {
func genDoc(api *spec.ApiSpec, dir, filename string) error {
fp, _, err := util.MaybeCreateFile(dir, "", filename)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions tools/goctl/api/parser/g4/ast/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) interface{} {
return &final
}

func (v *ApiVisitor) acceptService(root *Api, final *Api) {
func (v *ApiVisitor) acceptService(root, final *Api) {
for _, service := range root.Service {
if _, ok := final.serviceM[service.ServiceApi.Name.Text()]; !ok && len(final.serviceM) > 0 {
v.panic(service.ServiceApi.Name, fmt.Sprintf("mutiple service declaration"))
Expand Down Expand Up @@ -104,7 +104,7 @@ func (v *ApiVisitor) duplicateServerItemCheck(service *Service) {
}
}

func (v *ApiVisitor) acceptType(root *Api, final *Api) {
func (v *ApiVisitor) acceptType(root, final *Api) {
for _, tp := range root.Type {
if _, ok := final.typeM[tp.NameExpr().Text()]; ok {
v.panic(tp.NameExpr(), fmt.Sprintf("duplicate type '%s'", tp.NameExpr().Text()))
Expand All @@ -115,7 +115,7 @@ func (v *ApiVisitor) acceptType(root *Api, final *Api) {
}
}

func (v *ApiVisitor) acceptInfo(root *Api, final *Api) {
func (v *ApiVisitor) acceptInfo(root, final *Api) {
if root.Info != nil {
infoM := map[string]PlaceHolder{}
if final.Info != nil {
Expand All @@ -133,7 +133,7 @@ func (v *ApiVisitor) acceptInfo(root *Api, final *Api) {
}
}

func (v *ApiVisitor) acceptImport(root *Api, final *Api) {
func (v *ApiVisitor) acceptImport(root, final *Api) {
for _, imp := range root.Import {
if _, ok := final.importM[imp.Value.Text()]; ok {
v.panic(imp.Import, fmt.Sprintf("duplicate import '%s'", imp.Value.Text()))
Expand All @@ -144,7 +144,7 @@ func (v *ApiVisitor) acceptImport(root *Api, final *Api) {
}
}

func (v *ApiVisitor) acceptSyntax(root *Api, final *Api) {
func (v *ApiVisitor) acceptSyntax(root, final *Api) {
if root.Syntax != nil {
if final.Syntax != nil {
v.panic(root.Syntax.Syntax, fmt.Sprintf("mutiple syntax declaration"))
Expand Down
6 changes: 3 additions & 3 deletions tools/goctl/api/parser/g4/ast/apiparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (p *Parser) invoke(linePrefix, content string) (v *Api, err error) {
return
}

func (p *Parser) valid(mainApi *Api, nestedApi *Api) error {
func (p *Parser) valid(mainApi, nestedApi *Api) error {
err := p.nestedApiCheck(mainApi, nestedApi)
if err != nil {
return err
Expand Down Expand Up @@ -237,7 +237,7 @@ func (p *Parser) valid(mainApi *Api, nestedApi *Api) error {
return nil
}

func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap map[string]PlaceHolder, mainRouteMap map[string]PlaceHolder) error {
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
for _, each := range nestedApi.Service {
for _, r := range each.ServiceApi.ServiceRoute {
handler := r.GetHandler()
Expand All @@ -260,7 +260,7 @@ func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap map[string]P
return nil
}

func (p *Parser) nestedApiCheck(mainApi *Api, nestedApi *Api) error {
func (p *Parser) nestedApiCheck(mainApi, nestedApi *Api) error {
if len(nestedApi.Import) > 0 {
importToken := nestedApi.Import[0].Import
return fmt.Errorf("%s line %d:%d the nested api does not support import",
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/model/sql/gen/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestGenCacheKeys(t *testing.T) {
})
}

func cacheKeyEqual(k1 Key, k2 Key) bool {
func cacheKeyEqual(k1, k2 Key) bool {
k1Join := k1.FieldNameJoin
k2Join := k2.FieldNameJoin
sort.Strings(k1Join)
Expand Down
4 changes: 2 additions & 2 deletions tools/goctl/model/sql/test/model/studentmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type (
StudentModel interface {
Insert(data Student) (sql.Result, error)
FindOne(id int64) (*Student, error)
FindOneByClassName(class string, name string) (*Student, error)
FindOneByClassName(class, name string) (*Student, error)
Update(data Student) error
// only for test
Delete(id int64, className, studentName string) error
Expand Down Expand Up @@ -85,7 +85,7 @@ func (m *defaultStudentModel) FindOne(id int64) (*Student, error) {
}
}

func (m *defaultStudentModel) FindOneByClassName(class string, name string) (*Student, error) {
func (m *defaultStudentModel) FindOneByClassName(class, name string) (*Student, error) {
studentClassNameKey := fmt.Sprintf("%s%v%v", cacheStudentClassNamePrefix, class, name)
var resp Student
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func getCommand(arg string) (string, bool, error) {
return arg, false, nil
}

func downloadFile(filepath string, url string) error {
func downloadFile(filepath, url string) error {
resp, err := http.Get(url)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 73906f9

Please sign in to comment.