Skip to content

Commit

Permalink
Linter Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoswal committed Nov 11, 2024
1 parent cb87936 commit ec716ff
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func evalJSONGET(args []string, store *dstore.Store) []byte {

// Check for RESP3 support
if formatOptions.resp3 {
result, err = jsonGETResp3(store, paths, key, formatOptions, isLegacy)
result, err = jsonGETResp3(store, paths, key, isLegacy)

if err != nil {
return err
Expand All @@ -642,9 +642,9 @@ func evalJSONGET(args []string, store *dstore.Store) []byte {

// Determine which function to call based on the number of paths
if len(paths) > 1 {
result, err = jsonGETMulti(store, paths, key, formatOptions, isLegacy)
result, err = jsonGETMulti(store, paths, key, isLegacy)
} else {
result, err = jsonGETSingle(store, paths[0], key, formatOptions, isLegacy)
result, err = jsonGETSingle(store, paths[0], key, isLegacy)
}

if err != nil {
Expand All @@ -668,14 +668,14 @@ func isPathLegacy(path string) bool {
return strings.HasPrefix(path, "$")
}

func jsonGETSingle(store *dstore.Store, path string, key string, formatOptions ReplyFormatOptions, isLegacy bool) (interface{}, []byte) {
func jsonGETSingle(store *dstore.Store, path, key string, isLegacy bool) (results interface{}, err2 []byte) {
if isLegacy {
return jsonGETSingleLegacy(store, path, key, formatOptions)
return jsonGETSingleLegacy(store, path, key)
}
return jsonGETSingleNormal(store, path, key, formatOptions)
return jsonGETSingleNormal(store, path, key)
}

func jsonGETSingleNormal(store *dstore.Store, path string, key string, formatOptions ReplyFormatOptions) (interface{}, []byte) {
func jsonGETSingleNormal(store *dstore.Store, path, key string) (results interface{}, err2 []byte) {
// Retrieve the object from the store
obj := store.Get(key)
if obj == nil {
Expand All @@ -698,9 +698,9 @@ func jsonGETSingleNormal(store *dstore.Store, path string, key string, formatOpt

// Execute the JSONPath query
pathResults := expr.Get(jsonData)

const emptyJSONArray = "[]"
if len(pathResults) == 0 {
return "[]", nil
return emptyJSONArray, nil
}

// Serialize the result
Expand All @@ -711,7 +711,7 @@ func jsonGETSingleNormal(store *dstore.Store, path string, key string, formatOpt
return string(resultBytes), nil
}

func jsonGETSingleLegacy(store *dstore.Store, path string, key string, formatOptions ReplyFormatOptions) (interface{}, []byte) {
func jsonGETSingleLegacy(store *dstore.Store, path, key string) (results interface{}, err2 []byte) {
// Retrieve the object from the store
obj := store.Get(key)
if obj == nil {
Expand Down Expand Up @@ -761,7 +761,7 @@ func jsonGETSingleLegacy(store *dstore.Store, path string, key string, formatOpt
return string(resultBytes), nil
}

func jsonGETMulti(store *dstore.Store, paths []string, key string, formatOptions ReplyFormatOptions, isLegacy bool) (interface{}, []byte) {
func jsonGETMulti(store *dstore.Store, paths []string, key string, isLegacy bool) (multiResults interface{}, err2 []byte) {
// Retrieve the object by key
obj := store.Get(key)
if obj == nil {
Expand Down Expand Up @@ -820,7 +820,7 @@ func jsonGETMulti(store *dstore.Store, paths []string, key string, formatOptions
}

// Convert a single value to RESP3 format
func valueToResp3(value interface{}, formatOptions ReplyFormatOptions) interface{} {
func valueToResp3(value interface{}) interface{} {
// Convert the value to the appropriate RESP3 format
switch v := value.(type) {
case string:
Expand All @@ -833,7 +833,7 @@ func valueToResp3(value interface{}, formatOptions ReplyFormatOptions) interface
}

// Process a single path and convert its results to RESP3 format
func toResp3Path(path string, formatOptions ReplyFormatOptions, jsonData interface{}, isLegacy bool) (interface{}, []byte) {
func toResp3Path(path string, jsonData interface{}, isLegacy bool) (resp3Result interface{}, err2 []byte) {
expr, parseErr := jp.ParseString(path)
if parseErr != nil {
return nil, diceerrors.NewErrWithMessage(fmt.Sprintf("Path '%s' does not exist", path))
Expand All @@ -845,22 +845,21 @@ func toResp3Path(path string, formatOptions ReplyFormatOptions, jsonData interfa
// For non-legacy mode, return an empty array if no result found
if !isLegacy {
return []interface{}{}, nil
} else {
// In legacy mode, immediately mark as missing if no result found
return nil, diceerrors.NewErrWithMessage(fmt.Sprintf("Path '%s' does not exist", path))
}

return nil, diceerrors.NewErrWithMessage(fmt.Sprintf("Path '%s' does not exist", path))
}

// Convert the results to RESP3 format
resp3Results := []interface{}{}
for _, result := range pathResults {
resp3Results = append(resp3Results, valueToResp3(result, formatOptions))
resp3Results = append(resp3Results, valueToResp3(result))
}

return resp3Results, nil
}

func jsonGETResp3(store *dstore.Store, paths []string, key string, formatOptions ReplyFormatOptions, isLegacy bool) (interface{}, []byte) {
func jsonGETResp3(store *dstore.Store, paths []string, key string, isLegacy bool) (resp3Result interface{}, err2 []byte) {
// Retrieve the object by key
obj := store.Get(key)
if obj == nil {
Expand Down Expand Up @@ -898,7 +897,7 @@ func jsonGETResp3(store *dstore.Store, paths []string, key string, formatOptions

// Process each path and convert to RESP3
for _, path := range paths {
resp3Result, respErr := toResp3Path(path, formatOptions, jsonData, isLegacy)
resp3Result, respErr := toResp3Path(path, jsonData, isLegacy)
if respErr != nil {
return nil, respErr
}
Expand Down Expand Up @@ -950,20 +949,20 @@ func maxStrLen(arr []string) int {

// Define the constants
const (
CMD_ARG_NOESCAPE = "NOESCAPE"
CMD_ARG_INDENT = "INDENT"
CMD_ARG_NEWLINE = "NEWLINE"
CMD_ARG_SPACE = "SPACE"
CMD_ARG_FORMAT = "FORMAT"
CmdArgNoEscape = "NOESCAPE"
CmdArgIndent = "INDENT"
CmdArgNewLine = "NEWLINE"
CmdArgSpace = "SPACE"
CmdArgFormat = "FORMAT"
)

// Calculate the max length of JSON.GET subcommands.
var JSONGET_SUBCOMMANDS_MAXSTRLEN = maxStrLen([]string{
CMD_ARG_NOESCAPE,
CMD_ARG_INDENT,
CMD_ARG_NEWLINE,
CMD_ARG_SPACE,
CMD_ARG_FORMAT,
var JSONGetSubCommandsMaxStrLen = maxStrLen([]string{
CmdArgNoEscape,
CmdArgIndent,
CmdArgNewLine,
CmdArgSpace,
CmdArgFormat,
})

// helper function used by evalJSONGET and evalJSONMGET to prepare the results
Expand Down

0 comments on commit ec716ff

Please sign in to comment.