-
Notifications
You must be signed in to change notification settings - Fork 290
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
Parse fields that implement TextUnmarshaller interface #148
Conversation
@alsamylkin, thanks for your PR! By analyzing the history of the files in this pull request, we identified @shawnburke, @anuptalwalkar and @glibsm to be potential reviewers. |
Could you run the bench and paste the results in the PR description? |
case *bool: | ||
return strconv.ParseBool(v) | ||
case encoding.TextUnmarshaler: | ||
err := target.(encoding.TextUnmarshaler).UnmarshalText([]byte(v)) |
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.
Is []byte(v)
always going to be happy?
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.
From my understanding string is just a readonly byte slice, so yes, it will be always happy.
switch targetType.Name() { | ||
case "int": | ||
target := reflect.New(targetType).Interface() | ||
switch target.(type) { |
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.
do a colon equals assignment here like line 338 so you don't have to re-cast on 348
@@ -192,5 +192,19 @@ | |||
// Note that any fields you wish to deserialize into must be exported, just like | |||
// json.Unmarshal and friends. | |||
// | |||
// Benchmarks |
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.
Master branch:
BenchmarkYAMLCreateSingleFile-8 50000 31637 ns/op 10832 B/op 121 allocs/op
BenchmarkYAMLCreateMultiFile-8 30000 52003 ns/op 19840 B/op 207 allocs/op
BenchmarkYAMLSimpleGetLevel1-8 50000000 27.0 ns/op 0 B/op 0 allocs/op
BenchmarkYAMLSimpleGetLevel3-8 50000000 27.5 ns/op 0 B/op 0 allocs/op
BenchmarkYAMLSimpleGetLevel7-8 50000000 26.8 ns/op 0 B/op 0 allocs/op
BenchmarkYAMLPopulateStruct-8 2000000 879 ns/op 192 B/op 10 allocs/op
BenchmarkYAMLPopulateStructNested-8 500000 2744 ns/op 632 B/op 34 allocs/op
BenchmarkYAMLPopulateStructNestedMultipleFiles-8 500000 3684 ns/op 816 B/op 45 allocs/op
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.
lgtm
- hero: LaunchpadMcQuack | ||
- hero: LaunchpadMcQuack | ||
- hero: Scrooge | ||
- hero: Scrooge |
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.
nit: its complaining about new line here.
Very nice touch, thanks Alex!
…On Tue, Jan 3, 2017 at 6:25 PM alsamylkin ***@***.***> wrote:
Merged #148 <#148>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#148 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAF7P3b_17mRyCQKe1EdlcjNW8GxyNCGks5rOwMZgaJpZM4LYeJk>
.
|
Right now we can parse only bools, ints and strings. This change allows to convert strings to types that implement encoding.TextUnmarshaller interface, e.g. time.Time or math/big.Int