Skip to content

Commit

Permalink
Merge pull request #21 from u5surf/issue-20
Browse files Browse the repository at this point in the history
Add gometalinter to travis ci #20
  • Loading branch information
nitishm authored Jan 9, 2019
2 parents 90ca2c0 + 1216de4 commit a03048c
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 64 deletions.
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
lll:
line-length: 120

linters:
enable-all: true
disable:
- scopelint
- gochecknoglobals
- dupl
- unparam

run:
skip-dirs:
- vendor

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ before_install:
- go get honnef.co/go/tools/cmd/staticcheck
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.12.5

install:
- dep ensure

script:
- go test -v .
- go test -covermode=count -coverprofile=profile.cov .
- go vet -x .
- staticcheck .
- golangci-lint run ./...

after_script:
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci
Expand Down
20 changes: 12 additions & 8 deletions examples/json_array.go → examples/json_array/json_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/json"
"flag"
"fmt"
"log"

"github.com/gomodule/redigo/redis"
"github.com/nitishm/go-rejson"
"log"
)

func main() {
Expand All @@ -19,8 +20,11 @@ func main() {
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
}
defer func() {
conn.Do("FLUSHALL")
conn.Close()
_, err = conn.Do("FLUSHALL")
err = conn.Close()
if err != nil {
log.Fatalf("Failed to communicate to redis-server @ %v", err)
}
}()

ArrIn := []string{"one", "two", "three", "four", "five"}
Expand Down Expand Up @@ -85,28 +89,28 @@ func main() {

res, err = rejson.JSONArrIndex(conn, "arr", ".", "one")
if err != nil {
log.Fatalf("Failed to JSONArrIndex", err)
log.Fatalf("Failed to JSONArrIndex %v", err)
return
}
fmt.Println("Index of \"one\":", res)

res, err = rejson.JSONArrIndex(conn, "arr", ".", "three", 3, 10)
if err != nil {
log.Fatalf("Failed to JSONArrIndex", err)
log.Fatalf("Failed to JSONArrIndex %v", err)
return
}
fmt.Println("Out of range:", res)

res, err = rejson.JSONArrIndex(conn, "arr", ".", "ten")
if err != nil {
log.Fatalf("Failed to JSONArrIndex", err)
log.Fatalf("Failed to JSONArrIndex %v", err)
return
}
fmt.Println("\"ten\" not found:", res)

res, err = rejson.JSONArrTrim(conn, "arr", ".", 1, 2)
if err != nil {
log.Fatalf("Failed to JSONArrTrim", err)
log.Fatalf("Failed to JSONArrTrim %v", err)
return
}
fmt.Println("no. of elements left:", res)
Expand All @@ -125,7 +129,7 @@ func main() {

res, err = rejson.JSONArrInsert(conn, "arr", ".", 0, "one")
if err != nil {
log.Fatalf("Failed to JSONArrInsert", err)
log.Fatalf("Failed to JSONArrInsert %v", err)
return
}
fmt.Println("no. of elements:", res)
Expand Down
10 changes: 7 additions & 3 deletions examples/json_obj.go → examples/json_obj/json_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/json"
"flag"
"fmt"
"log"

"github.com/gomodule/redigo/redis"
"github.com/nitishm/go-rejson"
"log"
)

func main() {
Expand All @@ -19,8 +20,11 @@ func main() {
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
}
defer func() {
conn.Do("FLUSHALL")
conn.Close()
_, err = conn.Do("FLUSHALL")
err = conn.Close()
if err != nil {
log.Fatalf("Failed to communicate to redis-server @ %v", err)
}
}()

type Object struct {
Expand Down
7 changes: 5 additions & 2 deletions examples/json_set.go → examples/json_set/json_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ func main() {
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
}
defer func() {
conn.Do("FLUSHALL")
conn.Close()
_, err = conn.Do("FLUSHALL")
err = conn.Close()
if err != nil {
log.Fatalf("Failed to communicate to redis-server @ %v", err)
}
}()

student := Student{
Expand Down
21 changes: 12 additions & 9 deletions rejson.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
DebugMemorySubcommand = "MEMORY"
// DebugHelpSubcommand provide the corresponding HELP sub commands for JSONDebug
DebugHelpSubcommand = "HELP"
// DebugHelpOutput is the ouput of command JSON.Debug HELP <obj> [path]
// DebugHelpOutput is the output of command JSON.Debug HELP <obj> [path]
DebugHelpOutput = "MEMORY <key> [path] - reports memory usage\nHELP - this message"
)

Expand Down Expand Up @@ -252,7 +252,8 @@ func commandJSONDebug(argsIn ...interface{}) (argsOut []interface{}, err error)
// CommandBuilder is used to build a command that can be used directly with redigo's conn.Do()
// This is especially useful if you do not need to conn.Do() and instead need to use the JSON.* commands in a
// MUTLI/EXEC scenario along with some other operations like GET/SET/HGET/HSET/...
func CommandBuilder(commandNameIn string, argsIn ...interface{}) (commandNameOut string, argsOut []interface{}, err error) {
func CommandBuilder(commandNameIn string, argsIn ...interface{}) (commandNameOut string,
argsOut []interface{}, err error) {
cmd, ok := commandMux[commandNameIn]
if !ok {
return commandNameOut, nil, fmt.Errorf("command %s not supported by ReJSON", commandNameIn)
Expand Down Expand Up @@ -306,7 +307,7 @@ func JSONGet(conn redis.Conn, key string, path string, opts ...JSONGetOption) (r
// JSON.MGET <key> [key ...] <path>
func JSONMGet(conn redis.Conn, path string, keys ...string) (res interface{}, err error) {
if len(keys) == 0 {
err = fmt.Errorf("need atlesat one key as an argument")
err = fmt.Errorf("need atleast one key as an argument")
return nil, err
}

Expand Down Expand Up @@ -365,7 +366,7 @@ func JSONStrLen(conn redis.Conn, key string, path string) (res interface{}, err
// JSON.ARRAPPEND <key> <path> <json> [json ...]
func JSONArrAppend(conn redis.Conn, key string, path string, values ...interface{}) (res interface{}, err error) {
if len(values) == 0 {
err = fmt.Errorf("need atlesat one value string as an argument")
err = fmt.Errorf("need atleast one value string as an argument")
return nil, err
}

Expand Down Expand Up @@ -393,15 +394,17 @@ func JSONArrPop(conn redis.Conn, key, path string, index int) (res interface{},

// JSONArrIndex returns the index of the json element provided and return -1 if element is not present
// JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
func JSONArrIndex(conn redis.Conn, key, path string, jsonValue interface{}, optionalRange ...int) (res interface{}, err error) {
func JSONArrIndex(conn redis.Conn, key, path string,
jsonValue interface{}, optionalRange ...int) (res interface{}, err error) {
args := []interface{}{key, path, jsonValue}

ln := len(optionalRange)
if ln > 2 {
switch {
case ln > 2:
return nil, fmt.Errorf("need atmost two integeral value as an argument representing array range")
} else if ln == 1 { // only inclusive start is present
case ln == 1: // only inclusive start is present
args = append(args, optionalRange[0])
} else if ln == 2 { // both inclusive start and exclusive end are present
case ln == 2: // both inclusive start and exclusive end are present
args = append(args, optionalRange[0], optionalRange[1])
}
name, args, _ := CommandBuilder("JSON.ARRINDEX", args...)
Expand All @@ -419,7 +422,7 @@ func JSONArrTrim(conn redis.Conn, key, path string, start, end int) (res interfa
// JSON.ARRINSERT <key> <path> <index> <json> [json ...]
func JSONArrInsert(conn redis.Conn, key, path string, index int, values ...interface{}) (res interface{}, err error) {
if len(values) == 0 {
err = fmt.Errorf("need atlesat one value string as an argument")
err = fmt.Errorf("need atleast one value string as an argument")
return nil, err
}

Expand Down
Loading

0 comments on commit a03048c

Please sign in to comment.