-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for uint and uint64 #116
Conversation
I know you guys are in the middle of a refactor, but wanted to make sure I was on the right path. Let me know when you are done making internal changes, and I will refactor this fix accordingly. Thanks! |
// AddUInt adds a string key and integer value to the encoder's fields. The key | ||
// is JSON-escaped. | ||
func (enc *jsonEncoder) AddUInt(key string, val uint) { | ||
enc.AddInt64(key, int64(val)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to use strconv.AppendUint
here, otherwise very large values will actually be printed as negative numbers (since the int64
will overflow).
Same below for AddUint64
. You probably want to use strconv.AppendUint
int AddUint64
, and AddUint
can just call AddUint64
.
@akshayjshah We should consider simplifying the Encoder interface for int64
and uint64
to remove AddInt
and AddUint
and just have the 64-bit versions, and the field can cast itself.
Also fixed tests to use large ints that would overflow normal values
Thanks for the catch. Updated the pull requests accordingly. |
Looks great! Only one nit: instead of |
In advance of #116, add support for unsigned ints in the text encoder.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
@@ -114,8 +115,12 @@ func TestJSONEncoderFields(t *testing.T) { | |||
{"bool", `"k\\":true`, func(e Encoder) { e.AddBool(`k\`, true) }}, | |||
{"int", `"k":42`, func(e Encoder) { e.AddInt("k", 42) }}, | |||
{"int", `"k\\":42`, func(e Encoder) { e.AddInt(`k\`, 42) }}, | |||
{"int64", `"k":42`, func(e Encoder) { e.AddInt64("k", 42) }}, | |||
{"int64", `"k\\":42`, func(e Encoder) { e.AddInt64(`k\`, 42) }}, | |||
{"int64", fmt.Sprintf(`"k":%d`, math.MaxInt64), func(e Encoder) { e.AddInt64("k", math.MaxInt64) }}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating these tests, can you also add MinInt64
to the int64
test?
Just a single test for that (don't need to duplicate the key escaping test)
I've updated the naming and added a test for MinInt64. Let me know if you see anything else. |
Hi Chuck! Looks good to me, but I don't see you in our list of CLA signatories. Have you signed the CLA? Note that you'll have to use the correct GitHub username ( |
Ahh sorry, the browser auto-completed the github username and didn't realize it. Should be updated now. |
Cool - thanks for the contribution (and your patience)! Merging this now. |
Thank you for the PR, Chuck! |
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
* Add a TextEncoder for human-readable output When logging to console, JSON isn't the most friendly output - it's nice for machines but not optimal for humans. This PR adds a text encoder that prioritizes human readability, along with a few time-handling options for that encoder. In advance of #116, this PR also includes support for unsigned ints.
Fixes #110
Before opening your pull request, please make sure that you've:
make test
); and finally,make lint
).Thanks for your contribution!