Conversation
candiduslynx
left a comment
There was a problem hiding this comment.
I feel that extracting client, transformer & reverse transformer into a separate struct that embeds the aforementioned elements might streamline the code a bit more
| } | ||
|
|
||
| func (s *FileSpec) SetDefaults() { | ||
| if s.Delimiter == 0 { |
There was a problem hiding this comment.
Delimiter can be the NUL character, so depending on the zero value doesn't do it 100% :)
There was a problem hiding this comment.
Seems like we're unlikely to run into this in practice, but if we want to be safe we could probably change Delimiter to string and use the first rune in the string (with validation that it doesn't have > 1 runes). Then we can check for the empty string here.
|
I like that. One question - can users still use the old method or now they have to embed this client and it's all or nothing? |
All of the old ways are still exposed... They should be used in cases where the default/ managed version is unsuitable |
yevgenypats
left a comment
There was a problem hiding this comment.
Look good from quick look, will defer to @hermanschaaf re-review.
hermanschaaf
left a comment
There was a problem hiding this comment.
I think storing *csvSpec and *jsonSpec as state on the file spec is maybe a little bit unusual, but I can see why you went this route: so that you can call Validate() directly on the file spec, as long as UnmarshalSpec() was called first. This way we can add new file types to this library without updating the logic in all the destinations, which is quite a nice property. LGTM 👍
| } | ||
| return &Client{ | ||
| spec: spec, | ||
| csvTransformer: &csvFile.Transformer{}, |
There was a problem hiding this comment.
thought:
- make value receiver instead of pointer receiver for
csvFile.Transformer{} - drop reverse transformer func from
csvFile.Transformer{}as it should be inherited from embedded struct - you can change the field to be value here and not init it al all
Summary
This PR exposes a new method
NewClient()that takes in a single struct. It returns a client that handles all of the read/write conversions for various file typesHere is how I expect destinations to use this functionality
The spec that users will use will look like this:
format_spec(csv headers, delimiters, replacing any sort of special characters)spec.spec(same level asformat)Use the following steps to ensure your PR is ready to be reviewed
go fmtto format your code 🖊golangci-lint run🚨 (install golangci-lint here)