chore(format): change by gofumpt tool (#697)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
master
Bo-Yi Wu 4 years ago committed by GitHub
parent 73417f54db
commit 73906f996d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,7 +94,7 @@ func (b *googleBreaker) markFailure() {
b.stat.Add(0) 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) { b.stat.Reduce(func(b *collection.Bucket) {
accepts += int64(b.Sum) accepts += int64(b.Sum)
total += b.Count total += b.Count

@ -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) steps := int(d / tw.interval)
pos = (tw.tickedPos + steps) % tw.numSlots pos = (tw.tickedPos + steps) % tw.numSlots
circle = (steps - 1) / tw.numSlots circle = (steps - 1) / tw.numSlots

@ -2,5 +2,5 @@ package internal
// Listener interface wraps the OnUpdate method. // Listener interface wraps the OnUpdate method.
type Listener interface { type Listener interface {
OnUpdate(keys []string, values []string, newKey string) OnUpdate(keys, values []string, newKey string)
} }

@ -83,7 +83,7 @@ func (h *ConsistentHash) AddWithReplicas(node interface{}, replicas int) {
h.ring[hash] = append(h.ring[hash], node) 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] return h.keys[i] < h.keys[j]
}) })
} }

@ -112,5 +112,5 @@ func (t mockTrace) Follow(ctx context.Context, serviceName, operationName string
return nil, nil return nil, nil
} }
func (t mockTrace) Visit(fn func(key string, val string) bool) { func (t mockTrace) Visit(fn func(key, val string) bool) {
} }

@ -286,7 +286,7 @@ func parseNumberRange(str string) (*numberRange, error) {
}, nil }, nil
} }
func parseOption(fieldOpts *fieldOptions, fieldName string, option string) error { func parseOption(fieldOpts *fieldOptions, fieldName, option string) error {
switch { switch {
case option == stringOption: case option == stringOption:
fieldOpts.FromString = true fieldOpts.FromString = true

@ -205,7 +205,7 @@ func (c cacheNode) doTake(v interface{}, key string, query func(v interface{}) e
return jsonx.Unmarshal(val.([]byte), v) 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) err := jsonx.Unmarshal([]byte(data), v)
if err == nil { if err == nil {
return nil return nil

@ -17,7 +17,7 @@ type (
// Store interface represents a KV store. // Store interface represents a KV store.
Store interface { Store interface {
Del(keys ...string) (int, error) 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) Exists(key string) (bool, error)
Expire(key string, seconds int) error Expire(key string, seconds int) error
Expireat(key string, expireTime int64) error Expireat(key string, expireTime int64) error
@ -39,7 +39,7 @@ type (
Llen(key string) (int, error) Llen(key string) (int, error)
Lpop(key string) (string, error) Lpop(key string) (string, error)
Lpush(key string, values ...interface{}) (int, 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) Lrem(key string, count int, value string) (int, error)
Persist(key string) (bool, error) Persist(key string) (bool, error)
Pfadd(key string, values ...interface{}) (bool, error) Pfadd(key string, values ...interface{}) (bool, error)
@ -47,7 +47,7 @@ type (
Rpush(key string, values ...interface{}) (int, error) Rpush(key string, values ...interface{}) (int, error)
Sadd(key string, values ...interface{}) (int, error) Sadd(key string, values ...interface{}) (int, error)
Scard(key string) (int64, error) Scard(key string) (int64, error)
Set(key string, value string) error Set(key, value string) error
Setex(key, value string, seconds int) error Setex(key, value string, seconds int) error
Setnx(key, value string) (bool, error) Setnx(key, value string) (bool, error)
SetnxEx(key, value string, seconds int) (bool, error) SetnxEx(key, value string, seconds int) (bool, error)
@ -74,7 +74,7 @@ type (
Zrevrange(key string, start, stop int64) ([]string, error) Zrevrange(key string, start, stop int64) ([]string, error)
ZrevrangebyscoreWithScores(key string, start, stop int64) ([]redis.Pair, error) ZrevrangebyscoreWithScores(key string, start, stop int64) ([]redis.Pair, error)
ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) ([]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) Zrevrank(key, field string) (int64, error)
} }
@ -123,7 +123,7 @@ func (cs clusterStore) Del(keys ...string) (int, error) {
return val, be.Err() 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) node, err := cs.getRedis(key)
if err != nil { if err != nil {
return nil, err return nil, err
@ -321,7 +321,7 @@ func (cs clusterStore) Lpush(key string, values ...interface{}) (int, error) {
return node.Lpush(key, values...) 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) node, err := cs.getRedis(key)
if err != nil { if err != nil {
return nil, err return nil, err
@ -393,7 +393,7 @@ func (cs clusterStore) Scard(key string) (int64, error) {
return node.Scard(key) 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) node, err := cs.getRedis(key)
if err != nil { if err != nil {
return err return err
@ -648,7 +648,7 @@ func (cs clusterStore) Zrevrank(key, field string) (int64, error) {
return node.Zrevrank(key, field) 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) node, err := cs.getRedis(key)
if err != nil { if err != nil {
return 0, err return 0, err

@ -24,11 +24,11 @@ type (
CachedCollection interface { CachedCollection interface {
Count(query interface{}) (int, error) Count(query interface{}) (int, error)
DelCache(keys ...string) 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 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 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 GetCache(key string, v interface{}) error
Insert(docs ...interface{}) error Insert(docs ...interface{}) error
Pipe(pipeline interface{}) mongo.Pipe Pipe(pipeline interface{}) mongo.Pipe
@ -68,7 +68,7 @@ func (c *cachedCollection) DelCache(keys ...string) error {
return c.cache.Del(keys...) 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) q := c.collection.Find(query)
for _, opt := range opts { for _, opt := range opts {
q = opt(q) q = opt(q)
@ -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) q := c.collection.Find(query)
return q.One(v) return q.One(v)
} }
@ -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) q := c.collection.FindId(id)
return q.One(v) return q.One(v)
} }

@ -75,7 +75,7 @@ func (mm *Model) GetCollection(session *mgo.Session) CachedCollection {
} }
// FindAllNoCache finds all records without cache. // 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 mm.execute(func(c CachedCollection) error {
return c.FindAllNoCache(v, query, opts...) return c.FindAllNoCache(v, query, opts...)
}) })
@ -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. // 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 mm.execute(func(c CachedCollection) error {
return c.FindOneNoCache(v, query) return c.FindOneNoCache(v, query)
}) })
@ -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. // 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 mm.execute(func(c CachedCollection) error {
return c.FindOneIdNoCache(v, id) return c.FindOneIdNoCache(v, id)
}) })

@ -180,7 +180,7 @@ func (s *Redis) BitOpXor(destKey string, keys ...string) (val int64, err error)
} }
// BitPos is redis bitpos command implementation. // 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 { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {
@ -346,7 +346,7 @@ func (s *Redis) GeoAdd(key string, geoLocation ...*GeoLocation) (val int64, err
} }
// GeoDist is the implementation of redis geodist command. // 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 { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {
@ -795,7 +795,7 @@ func (s *Redis) Lpush(key string, values ...interface{}) (val int, err error) {
} }
// Lrange is the implementation of redis lrange command. // 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 { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {
@ -1074,7 +1074,7 @@ func (s *Redis) ScriptLoad(script string) (string, error) {
} }
// Set is the implementation of redis set command. // 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 { return s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {
@ -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. // 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 { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {
@ -1684,7 +1684,7 @@ func (s *Redis) ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64
} }
// Zrevrank is the implementation of redis zrevrank command. // 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 { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)
if err != nil { if err != nil {

@ -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. // 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) rs := []rune(str)
length := len(rs) length := len(rs)

@ -159,7 +159,7 @@ type mockedRouter struct{}
func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) { 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") return errors.New("foo")
} }

@ -5,7 +5,7 @@ import "net/http"
// Router interface represents a http router that handles http requests. // Router interface represents a http router that handles http requests.
type Router interface { type Router interface {
http.Handler http.Handler
Handle(method string, path string, handler http.Handler) error Handle(method, path string, handler http.Handler) error
SetNotFoundHandler(handler http.Handler) SetNotFoundHandler(handler http.Handler)
SetNotAllowedHandler(handler http.Handler) SetNotAllowedHandler(handler http.Handler)
} }

@ -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) fp, _, err := util.MaybeCreateFile(dir, "", filename)
if err != nil { if err != nil {
return err return err

@ -42,7 +42,7 @@ func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) interface{} {
return &final return &final
} }
func (v *ApiVisitor) acceptService(root *Api, final *Api) { func (v *ApiVisitor) acceptService(root, final *Api) {
for _, service := range root.Service { for _, service := range root.Service {
if _, ok := final.serviceM[service.ServiceApi.Name.Text()]; !ok && len(final.serviceM) > 0 { if _, ok := final.serviceM[service.ServiceApi.Name.Text()]; !ok && len(final.serviceM) > 0 {
v.panic(service.ServiceApi.Name, fmt.Sprintf("mutiple service declaration")) v.panic(service.ServiceApi.Name, fmt.Sprintf("mutiple service declaration"))
@ -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 { for _, tp := range root.Type {
if _, ok := final.typeM[tp.NameExpr().Text()]; ok { if _, ok := final.typeM[tp.NameExpr().Text()]; ok {
v.panic(tp.NameExpr(), fmt.Sprintf("duplicate type '%s'", tp.NameExpr().Text())) v.panic(tp.NameExpr(), fmt.Sprintf("duplicate type '%s'", tp.NameExpr().Text()))
@ -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 { if root.Info != nil {
infoM := map[string]PlaceHolder{} infoM := map[string]PlaceHolder{}
if final.Info != nil { if final.Info != nil {
@ -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 { for _, imp := range root.Import {
if _, ok := final.importM[imp.Value.Text()]; ok { if _, ok := final.importM[imp.Value.Text()]; ok {
v.panic(imp.Import, fmt.Sprintf("duplicate import '%s'", imp.Value.Text())) v.panic(imp.Import, fmt.Sprintf("duplicate import '%s'", imp.Value.Text()))
@ -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 root.Syntax != nil {
if final.Syntax != nil { if final.Syntax != nil {
v.panic(root.Syntax.Syntax, fmt.Sprintf("mutiple syntax declaration")) v.panic(root.Syntax.Syntax, fmt.Sprintf("mutiple syntax declaration"))

@ -177,7 +177,7 @@ func (p *Parser) invoke(linePrefix, content string) (v *Api, err error) {
return return
} }
func (p *Parser) valid(mainApi *Api, nestedApi *Api) error { func (p *Parser) valid(mainApi, nestedApi *Api) error {
err := p.nestedApiCheck(mainApi, nestedApi) err := p.nestedApiCheck(mainApi, nestedApi)
if err != nil { if err != nil {
return err return err
@ -237,7 +237,7 @@ func (p *Parser) valid(mainApi *Api, nestedApi *Api) error {
return nil 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 _, each := range nestedApi.Service {
for _, r := range each.ServiceApi.ServiceRoute { for _, r := range each.ServiceApi.ServiceRoute {
handler := r.GetHandler() handler := r.GetHandler()
@ -260,7 +260,7 @@ func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap map[string]P
return nil return nil
} }
func (p *Parser) nestedApiCheck(mainApi *Api, nestedApi *Api) error { func (p *Parser) nestedApiCheck(mainApi, nestedApi *Api) error {
if len(nestedApi.Import) > 0 { if len(nestedApi.Import) > 0 {
importToken := nestedApi.Import[0].Import importToken := nestedApi.Import[0].Import
return fmt.Errorf("%s line %d:%d the nested api does not support import", return fmt.Errorf("%s line %d:%d the nested api does not support import",

@ -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 k1Join := k1.FieldNameJoin
k2Join := k2.FieldNameJoin k2Join := k2.FieldNameJoin
sort.Strings(k1Join) sort.Strings(k1Join)

@ -28,7 +28,7 @@ type (
StudentModel interface { StudentModel interface {
Insert(data Student) (sql.Result, error) Insert(data Student) (sql.Result, error)
FindOne(id int64) (*Student, error) FindOne(id int64) (*Student, error)
FindOneByClassName(class string, name string) (*Student, error) FindOneByClassName(class, name string) (*Student, error)
Update(data Student) error Update(data Student) error
// only for test // only for test
Delete(id int64, className, studentName string) error Delete(id int64, className, studentName string) error
@ -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) studentClassNameKey := fmt.Sprintf("%s%v%v", cacheStudentClassNamePrefix, class, name)
var resp Student var resp Student
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {

@ -136,7 +136,7 @@ func getCommand(arg string) (string, bool, error) {
return arg, false, nil return arg, false, nil
} }
func downloadFile(filepath string, url string) error { func downloadFile(filepath, url string) error {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err

@ -15,7 +15,7 @@ import (
// Run provides the execution of shell scripts in golang, // Run provides the execution of shell scripts in golang,
// which can support macOS, Windows, and Linux operating systems. // which can support macOS, Windows, and Linux operating systems.
// Other operating systems are currently not supported // Other operating systems are currently not supported
func Run(arg string, dir string, in ...*bytes.Buffer) (string, error) { func Run(arg, dir string, in ...*bytes.Buffer) (string, error) {
goos := runtime.GOOS goos := runtime.GOOS
var cmd *exec.Cmd var cmd *exec.Cmd
switch goos { switch goos {

Loading…
Cancel
Save