-
Notifications
You must be signed in to change notification settings - Fork 454
feat: add float_format flag #367
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ type Generator struct { | |
| fieldNamer FieldNamer | ||
| simpleBytes bool | ||
| skipMemberNameUnescaping bool | ||
| floatFmt string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not byte? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd made it string to keep it consistent with the incoming flag which would be string. Also, in case we use byte and pass it as empty, the generator sets it as: I could try figuring this out further if byte seems more relevant as the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can check what value is correct on code generation stage and pass default value if cmd line parameter not passed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So currently, since the flag package does not have support for byte/rune flags, it is a bit difficult to do this. I guess it might be okay to keep it as is (?), since the internal method converts the string to byte and sets the default value as well. |
||
|
|
||
| // package path to local alias map for tracking imports | ||
| imports map[string]string | ||
|
|
@@ -133,6 +134,11 @@ func (g *Generator) SimpleBytes() { | |
| g.simpleBytes = true | ||
| } | ||
|
|
||
| // SetFloatFmt sets the format for formatting float numbers using strconv. | ||
| func (g *Generator) SetFloatFmt(fmt string) { | ||
| g.floatFmt = fmt | ||
| } | ||
|
|
||
| // addTypes requests to generate encoding/decoding funcs for the given type. | ||
| func (g *Generator) addType(t reflect.Type) { | ||
| if g.typesSeen[t] { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package tests | ||
|
|
||
| //easyjson:json | ||
| type FloatFmtStruct struct { | ||
| A float64 `json:"a"` | ||
| B float64 `json:"b"` | ||
| } | ||
|
|
||
| var floatFmtStruct = FloatFmtStruct{ | ||
| A: 100000000, | ||
| B: 1000, | ||
| } | ||
| var floatFmtString = `{"a":100000000,"b":1000}` |
Uh oh!
There was an error while loading. Please reload this page.