Compatibility with rejson:latest 2.0.6#60
Conversation
Shivam010
left a comment
There was a problem hiding this comment.
I haven't really used debug command much, I want to check it first before I comment anything on it.
And thanks @breno12321 for your contribution.
| res, command_err := r.Conn.Do(name, args...) | ||
|
|
||
| if err != nil { | ||
| return nil, command_err | ||
| } |
There was a problem hiding this comment.
Why use the command_err variable but not check it? Why not use err variable itself here ?
There was a problem hiding this comment.
it said that no variable on the left were created, something like this in my IDE I don't know. I can try again later today
There was a problem hiding this comment.
func (r *Redigo) JSONType(key, path string) (res interface{}, err error) {
name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandTYPE, key, path)
if err != nil {
return nil, err
}
res, err = r.Conn.Do(name, args...)
if err != nil {
return nil, err
}
switch v := res.(type) {
case string:
return v, nil
case []byte:
return string(v), nil
case nil:
return
default:
err := fmt.Errorf("type returned not expected %T", v)
return nil, err
}
}Changing to just = instead of := it works, sorry, getting used to Go notation hehe
There was a problem hiding this comment.
Newbie question ❓ @Shivam010 this way the res is already created by the returning definition for the function? 🤔 so no need to var assignment?
There was a problem hiding this comment.
Yes. var and := declare a new variable and hence, I think you were getting the error. = this will just assign the value to already created variables
| switch v := res.(type) { | ||
| case string: | ||
| return v, nil | ||
| case []uint8: | ||
| return string(v), nil | ||
| case nil: | ||
| return | ||
| default: | ||
| err := fmt.Errorf("type returned not expected %T", v) | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
Yes, I agree with this. Just a few suggestions, it would be better if we directly return the value in case of default and we should also handle the []byte type.
And I don't think nil check should be required, is there something I am missing here?
There was a problem hiding this comment.
There is some tests regarding nil inputs and they would break if not handled properly
https://github.com/nitishm/go-rejson/blob/master/rejson_test.go#L763-L770
There was a problem hiding this comment.
About the byte agree ill make the change, thought []uint8 would cover
There was a problem hiding this comment.
Maybe I leave just the []byte, more straight forward 😅
There was a problem hiding this comment.
Yes, change it to []byte, that would be more clear
|
I thank U @Shivam010 for helping me, I started to learn Go this week so.... All help is welcome and tips and tricks and good resources haha |
|
@breno12321 It's my pleasure to help you. You can also join the Gophers slack community https://invite.slack.gobridge.org/ there's a lot of great people out there. And here are the resources for you (quote from Slack): |
Shivam010
left a comment
There was a problem hiding this comment.
Push your changes, and I think then we will be good to go
|
Question @Shivam010 besides Linting, should I remove the Debug command? Since its not consistent with the tests? The []byte I've already made the fix |
There was a problem hiding this comment.
Yes, you are right.
JSON.DEBUG seems to have some issue and the redis/rejson team is working on it.
Ref:
So, I think, for now, we can skip the debug command test cases with t.SkipNow() instead of removing them.
@breno12321 Can you add it?
|
I can skip sorry for the late response life been crazy 😅 |
|
Think its all good @Shivam010! 😊 |
Yeah, no problem. And thanks for your contribution. |


Problem
Solution