Conversation
ea9bcca to
f0f69e0
Compare
tommyblue
left a comment
There was a problem hiding this comment.
sounds good, check the comments
| cfg, dcfg = t.Config, t.DecodedConfig | ||
| name, typ = t.Name, "metrics" | ||
| default: | ||
| panic(fmt.Sprintf("unexpected type %#v", cfg)) |
There was a problem hiding this comment.
panic? shouldn't it return an error?
There was a problem hiding this comment.
Getting an unexpected type here means there's a developer error which must be fixed, no way around that.
That's the typical use case for panic
| panic(fmt.Sprintf("unexpected type %#v", cfg)) | ||
| } | ||
|
|
||
| if cfg == nil { |
There was a problem hiding this comment.
uhm, does this ever happen? isn't already panicked in the switch?
There was a problem hiding this comment.
uhm, does this ever happen? isn't already panicked in the switch?
yes it does. ift.Configis nil.t.Configisnilif the user didn't specify an[input.config]section in the TOML.
| return nil | ||
| } | ||
|
|
||
| if err := md.PrimitiveDecode(*cfg, dcfg); err != nil { |
There was a problem hiding this comment.
PrimitiveDecode is deprecated, in favor of MetaData.PrimitiveDecode. Maybe it's worth updating it here
There was a problem hiding this comment.
where did you see that? link?
There was a problem hiding this comment.
the editor suggested that, but I now see it makes a mistake: the deprecated function is func PrimitiveDecode, not func (md *MetaData) PrimitiveDecode
| return fmt.Errorf("%s %q: error parsing config: %v", typ, name, err) | ||
| } | ||
|
|
||
| if req := CheckRequiredFields(dcfg); req != "" { |
There was a problem hiding this comment.
req could be called fieldName?
There was a problem hiding this comment.
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
IMHO fieldName seems a bit redundant here.
I actually hesitated calling it just name.
Maybe just calling it f could do if I transform the next line to be:
ErrorRequiredField{Field:f}rather than
ErrorRequiredField{req}| // "required" struct struct tag must be present and set to true. | ||
| // | ||
| // RequiredFields doesn't support struct embedding other structs. | ||
| func RequiredFields(cfg interface{}) []string { |
There was a problem hiding this comment.
is this public for testing purposes?
There was a problem hiding this comment.
no. I thought this could be a good addition to the public API for users that desire to use baker as a library.
We're provided the help functions and all but we should also provide the necessary API for users to differently.
That's why I added a detailed documentation there.
| // are set of the struct doesn't have any required fields (or any fields at all). | ||
| // | ||
| // CheckRequiredFields doesn't support struct embedding other structs. | ||
| func CheckRequiredFields(val interface{}) string { |
There was a problem hiding this comment.
is the function public for testing purposes?
There was a problem hiding this comment.
same answer as for RequiredFields
|
Oh, I forgot: I think we should also add this change to the README |
e1b6265 to
50cb62c
Compare
At the moment there's not a clear section in the README about the configuration structures of baker components. |
tommyblue
left a comment
There was a problem hiding this comment.
ok, just remove the line from the changelog then merge
| - filter: add RegexMatch filter. [#37](https://github.com/AdRoll/baker/pull/37) | ||
| - filter: add Concatenate filter [#33](https://github.com/AdRoll/baker/pull/33) | ||
| - filter: add NotNull filter [#43](https://github.com/AdRoll/baker/pull/43) | ||
| - filter: add Concatenate filter [#28](https://github.com/AdRoll/baker/pull/33) |
There was a problem hiding this comment.
| - filter: add Concatenate filter [#28](https://github.com/AdRoll/baker/pull/33) |
There was a problem hiding this comment.
already included in the file
50cb62c to
994e8fc
Compare
❓ What
Component configuration fields can now be tagged as
required:"true". If that's the case, the configuration is considered valid if and only if the field has been set to a non-zero value. This allows to handle required fields in a single place, rather than all over the place, and with a homogeneous error message.Modification to the components configuration to set required fields as required and remove component-specific checks will be pushed in a follow-up PR
🔨 How to test
✅ Checklists
This section contains a list of checklists for common uses, please delete the checklists that are useless for your current use case (or add another checklist if your use case isn't covered yet).
make gofmt-writebeen run on the code?make govetbeen run on the code? Has the code been fixed accordingly to the output?