Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a helper generic function DecodeSliceOfJSON #522

Merged
merged 4 commits into from
Apr 2, 2024

Conversation

sgasho
Copy link
Contributor

@sgasho sgasho commented Apr 1, 2024

added a helper function DecodeSliceOfJSON to struct scan a redis result.
code provided in #521 (comment) did not work so I changed a little.

Related Issue

close #521

@codecov-commenter
Copy link

codecov-commenter commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 95.60%. Comparing base (a74b679) to head (227572f).

Files Patch % Lines
helper.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #522      +/-   ##
==========================================
+ Coverage   95.57%   95.60%   +0.02%     
==========================================
  Files          80       80              
  Lines       33178    33192      +14     
==========================================
+ Hits        31710    31732      +22     
+ Misses       1267     1260       -7     
+ Partials      201      200       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

helper.go Outdated Show resolved Hide resolved
@rueian
Copy link
Collaborator

rueian commented Apr 2, 2024

image The error-handling parts are covered by tests. Could you also add some tests for them?

@rueian
Copy link
Collaborator

rueian commented Apr 2, 2024

Sorry @sgasho, I didn't notice that your original version can actually work with both *[]T and *[]*T. So, I now believe your original version is superior. Could you change it back?

@sgasho sgasho requested a review from rueian April 2, 2024 12:57
@rueian rueian added the feature label Apr 2, 2024
@rueian rueian merged commit 2ac91fb into redis:main Apr 2, 2024
2 checks passed
@sgasho sgasho deleted the feature/#521_slicescan branch April 2, 2024 13:16
var t T
if err = v.DecodeJSON(&t); err != nil {
if IsRedisNil(err) {
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rueian @sgasho If this happens, then ts[i] will be an empty value. Is this the expected behavior? Probably not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see there is a test for this behavior, so probably it is a desired behavior. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add DecodeSliceOfJSON to handle []Struct results easier
4 participants