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

fix(conv): fix misuse of String2Int64 #62

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conv/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ type Options struct {
// and this field WON'T appear in JSON
EnableThriftBase bool

// String2Int64 indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
// String2Int64 indicates if string value can be written as **Int8/Int16/Int32/Int64/Float64**,
String2Int64 bool

// Int642Stringin indicates if a int64 value a **Int64** value can be written as string
Copy link
Collaborator

Choose a reason for hiding this comment

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

"read" and "write" is just relative to json or thrift.... let us use "convert"?

// Int642String indicates if a **Int64** field can be read as string
Int642String bool

// NoBase64Binary indicates if base64 string should be Encode/Decode as []byte
Expand Down
2 changes: 1 addition & 1 deletion conv/p2j/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func TestInt2String(t *testing.T) {
require.NoError(t, err)
require.Equal(t, (`{"Int32":1,"Float64":3.14,"String":"hello","Int64":2,"Subfix":0.92653}`), string(out))

cv.opts.String2Int64 = true
cv.opts.Int642String = true
out, err = cv.Do(ctx, desc, in)
require.NoError(t, err)
require.Equal(t, (`{"Int32":1,"Float64":3.14,"String":"hello","Int64":"2","Subfix":0.92653}`), string(out))
Expand Down
2 changes: 1 addition & 1 deletion conv/p2j/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (self *BinaryConv) unmarshalSingular(ctx context.Context, resp http.Respons
if e != nil {
return wrapError(meta.ErrRead, "unmarshal Int64kind error", e)
}
if self.opts.String2Int64 {
if self.opts.Int642String {
*out = append(*out, '"')
*out = json.EncodeInt64(*out, int64(v))
*out = append(*out, '"')
Expand Down
Loading