Skip to content

Commit

Permalink
go fmt code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHAO committed Aug 8, 2018
1 parent 6ab8451 commit d885c0c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 39 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
language: go

os:
- linux
- osx

go:
- "1.10"
- master

before_install:
install:
- go get -u golang.org/x/vgo
- go get -u golang.org/x/tools/cmd/goimports

script:
- diff <(goimports -d .) <(printf "")
- make test
4 changes: 2 additions & 2 deletions config/mc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var (
BodyBigStr: "1M",
BodyInCStr: "4K",
FlushMaxStr: "100M",
TimeoutMS: 3000,
TimeoutMS: 3000,
}
)

Expand All @@ -27,7 +27,7 @@ type MCConfig struct {
BodyBigStr string `yaml:"body_big_str,omitempty"`

BodyInCStr string `yaml:"body_c_str,omitempty"`
TimeoutMS int `yaml:"timeout_ms,omitempty"`
TimeoutMS int `yaml:"timeout_ms,omitempty"`
}

func IsValidKeySize(ksz uint32) bool {
Expand Down
2 changes: 1 addition & 1 deletion config/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (rt *RouteTable) GetDBRouteConfig(addr string) (r DBRouteConfig) {
if !found {
return
}
for b, _ := range buckets {
for b := range buckets {
r.BucketsStat[b] = 1
r.BucketsHex = append(r.BucketsHex, BucketIDHex(b, rt.NumBucket))
}
Expand Down
2 changes: 1 addition & 1 deletion memcache/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func (req *Request) Check(resp *Response) error {
switch req.Cmd {
case "get", "gets":
if resp.Items != nil {
for key, _ := range resp.Items {
for key := range resp.Items {
if !contain(req.Keys, key) {
logger.Errorf("unexpected key in response: %s", key)
return errors.New("unexpected key in response: " + key)
Expand Down
61 changes: 31 additions & 30 deletions memcache/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/douban/gobeansdb/config"
"strings"
"testing"

"github.com/douban/gobeansdb/config"
)

type reqTest struct {
Expand All @@ -16,31 +17,31 @@ type reqTest struct {
}

var reqTests = []reqTest{
reqTest{
{
cmd: "get abc cdf \r\n",
answer: "END\r\n",
},
reqTest{
{
cmd: "set abc 2 3 2 noreply\r\nok\r\n",
answer: "",
},
reqTest{
{
cmd: "set abc a 3 2 noreply\r\nok\r\n",
answer: "CLIENT_ERROR invalid cmd\r\n",
},
reqTest{
{
cmd: "set cdf 0 0 2\r\nok\r\n",
answer: "STORED\r\n",
},
reqTest{
{
cmd: "get cdf\r\n",
answer: "VALUE cdf 0 2\r\nok\r\nEND\r\n",
},
reqTest{
{
cmd: "get abc \r\n",
answer: "VALUE abc 2 2\r\nok\r\nEND\r\n",
},
reqTest{
{
cmd: "stats curr_items cmd_get cmd_set get_hits get_misses\r\n",
answer: "STAT curr_items 2\r\n" +
"STAT cmd_get 4\r\n" +
Expand All @@ -49,42 +50,42 @@ var reqTests = []reqTest{
"STAT get_misses 2\r\n" +
"END\r\n",
},
reqTest{
{
cmd: "set abc 3 3 3 2 noreply\r\nok\r\n",
answer: "CLIENT_ERROR invalid cmd\r\n",
},
reqTest{
{
cmd: "set abc a 3 2 noreply\r\nok\r\n",
answer: "CLIENT_ERROR invalid cmd\r\n",
},
reqTest{
{
cmd: "set abc 3 3 10\r\nok\r\n",
answer: "CLIENT_ERROR network error\r\n",
},
reqTest{
{
cmd: "get \r\n",
answer: "CLIENT_ERROR invalid cmd\r\n",
},
reqTest{
{
cmd: "get " + strings.Repeat("a", 300) + " \r\n",
answer: "CLIENT_ERROR key length error\r\n",
},
reqTest{
{
cmd: "set hello 0 0 92160\r\n" + strings.Repeat("a", 1024*90) + "\r\n",
answer: "CLIENT_ERROR value too large\r\n",
maxSize: 1000,
},
reqTest{
{
cmd: "set hello 0 0 1000\r\n" + strings.Repeat("a", 1000) + "\r\n",
answer: "STORED\r\n",
maxSize: 1000,
},
reqTest{
{
cmd: "set hello 0 0 1000\r\n" + strings.Repeat("a", 1000) + "\r\n",
answer: "CLIENT_ERROR value too large\r\n",
maxSize: 999,
},
reqTest{
{
cmd: "set hello 0 0 1000\r\n" + strings.Repeat("a", 1000) + "\r\n",
answer: "STORED\r\n",
maxSize: 1001,
Expand All @@ -99,62 +100,62 @@ var reqTests = []reqTest{
// "cas abc -5 10 0 134020434\r\n\r\n",
// "STORED\r\n",
// },
reqTest{
{
cmd: "delete abc\r\n",
answer: "DELETED\r\n",
},
reqTest{
{
cmd: "delete abc noreply\r\n",
answer: "",
},
reqTest{
{
cmd: "append cdf 0 0 2\r\n 2\r\n",
answer: "STORED\r\n",
},
// reqTest{
// "prepend cdf 0 0 2\r\n1 \r\n",
// "STORED",
// },
reqTest{
{
cmd: "get cdf\r\n",
answer: "VALUE cdf 0 4\r\nok 2\r\nEND\r\n",
},
reqTest{
{
cmd: "append ap 0 0 2\r\nap\r\n",
answer: "NOT_STORED\r\n",
},

reqTest{
{
cmd: "set n 4 0 1\r\n5\r\n",
answer: "STORED\r\n",
},
reqTest{
{
cmd: "incr n 3\r\n",
answer: "8\r\n",
},
reqTest{
{
cmd: "incr nn 7\r\n",
answer: "7\r\n",
},

reqTest{
{
cmd: "flush_all\r\n",
answer: "OK\r\n",
},
reqTest{
{
cmd: "verbosity 1\r\n",
answer: "OK\r\n",
},
reqTest{
{
cmd: "version\r\n",
answer: "VERSION " + config.Version + "\r\n",
},

reqTest{
{
cmd: "quit\r\n",
answer: "",
},
reqTest{
{
cmd: "error\r\n",
answer: "CLIENT_ERROR non memcache command\r\n",
},
Expand Down
4 changes: 2 additions & 2 deletions memcache/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ReqHistoy struct {
WaitTime time.Duration
ServeStart time.Time
ServeTime time.Duration
Stat string
Stat string
StatStart time.Time
Working bool
}
Expand Down Expand Up @@ -56,7 +56,7 @@ func (rl *ReqLimiter) Get(req *Request) {
Cmd: req.Cmd,
Keys: req.Keys,
ServeStart: time.Now(),
WaitTime: d,
WaitTime: d,
Working: true,
}
if d > rl.MaxWait {
Expand Down
3 changes: 2 additions & 1 deletion quicklz/cquicklz.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ size_t qlz_compress(const void *source, char *destination, size_t size, char *sc
import "C"
import (
"fmt"
"unsafe"

"github.com/douban/gobeansdb/cmem"
"github.com/douban/gobeansdb/utils"
"unsafe"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion store/hstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func checkDataWithHints(dir string, chunk int) error {
}
n := len(hm)
if n > 0 {
for k, _ := range dm {
for k := range dm {
return fmt.Errorf("%d hint key not in data, one of them: %s", n, k)
}
}
Expand Down

0 comments on commit d885c0c

Please sign in to comment.