-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature: ToMap() utility #59
Comments
I briefly played around with this, it's not trivial. Paramgen currently works in two steps. Step 1 is to extract the parameters map, step 2 is to generate code based on the map using a Go template. I thought at first it would be as easy as updating the Go template in step 2, but that's not the case, because the extracted parameters don't have the information about the original field names. The whole thing gets much more complicated if you think about nested fields and wildcards (maps). I also tried playing around with an approach where the config would get marshalled into JSON, unmarshalled into a map and then flattened, in case it contains nested fields. This approach also breaks down when fields are not tagged using a So even though this seems easy, and for the basic case it probably is, it's not trivial to implement in the general case and support for nested structs, wildcards and fields without an explicit However, what's easy to do is to generate constants for fields: #60 Example: conduit-commons/paramgen/internal/testdata/basic/want.go Lines 10 to 35 in 58f3e14
Do you think this would be helpful @alarbada? |
@lovromazgon it is much better indeed, it statically prevents mistakes when updating / deleting properties. Still, when adding a new one you've got to be a bit careful. But for my tests #60 is more than enough. Thanks a lot! |
Ok merged #60 and regarding this as done for now. |
Feature description
In all the connectors I make I always have to either hardcode the
map[string]string
configuration, which is very susceptible of subtle connector misconfiguration bugs, or manually implement atoMap()
method that returns the configuration as a map like this:This works, but is also error prone, as I still need to manually check that the config parameter keys correspond to the ones on the source config. I'd rather do this:
And have the toMap() automatically generated by paramgen, instead of me implementing it. This way I've got a bit more "type safety", I make it impossible to misspell a property key and value.
The text was updated successfully, but these errors were encountered: