-
Notifications
You must be signed in to change notification settings - Fork 699
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 unmarshal for ExporterType
#3565
base: master
Are you sure you want to change the base?
Changes from 1 commit
62583c1
0082ef5
8027ec4
881688e
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 |
---|---|---|
|
@@ -33,6 +33,16 @@ func (t ExporterType) MarshalJSON() ([]byte, error) { | |
return []byte(`"` + t.String() + `"`), nil | ||
} | ||
|
||
func (t *ExporterType) UnmarshalJSON(b []byte) error { | ||
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. Should we add some test vectors for marshal and unmarshal? 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. Done |
||
exporterTypeStr := strings.Trim(string(b), `"`) | ||
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. Should we be erroring if the quotes are formatted unexpectedly? For instance:
would all be unmarshalled without issue, but non of them are formatted as expected. 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. Done |
||
exporterType, err := ExporterTypeFromString(exporterTypeStr) | ||
if err != nil && !errors.Is(err, errUnknownExporterType) { | ||
return err | ||
} | ||
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. (optional) I think we could remove the special case error check and just return an error on unknown |
||
*t = exporterType | ||
return nil | ||
} | ||
|
||
func (t ExporterType) String() string { | ||
switch t { | ||
case GRPC: | ||
|
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.
By convention,
"null" == string(b)
should be a noop.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.
Done