Configuration package improvements (validation and data structure) #212
Replies: 2 comments
-
Thanks for creating this discussion. I have several use-cases. 1. Support for slices of structures "some_config_list_of_endpoints": [
{
"name": "dummy entry",
"api_key": "value123",
"url": "https://example.com",
},
{
"name": "yet another entry",
"api_key": "uuid-something-something",
"url": "https://some-url.com",
}
] I would like to have the 2. Configuration in structs
var EndpointConfigs []EndpointConfig // example
type EndpointConfig struct {
Name string `json:"name"`
ApiKey string `json:"api_key"`
BaseUrl string `json:"url"`
} 3. Content validation for configuration 3.1 Validation through using a RuleSet (per entry) config.Register("some_config_list_of_endpoints.name", config.Entry{
Value: "",
Type: reflect.String,
Validation: v.RuleSet{
Path: ".",
Rules: v.List{v.Required(), v.String(), v.Min(1)},
}
}) This would remove boilerplate, because one does not have to define a separate validation layer in their app for config. 3.2 Validation via the eventual struct type CustomAuthService struct {
Url string `json:"url" validate:"required, type=string, min=1"`
} This way we circumvent "manually" defining the RuleSets and the need for validation boilerplate. Also this way we centralize defining, validation and containing configuration within Goyave. We could even look into supporting custom validation libraries like Generic Pros
Possible cons
|
Beta Was this translation helpful? Give feedback.
-
By using an interface instead of |
Beta Was this translation helpful? Give feedback.
-
#210 #211 started a discussion on inconveniences with the configuration package, especially when it comes to more complex data structures (slices of structures for example) and validation of the entries. I would like to take some time and think about improvements for the config package, or maybe a redesign for a future major version.
Please share here your wishlist for the configuration package, talk about your use-cases, etc. Feel free to share your ideas!
Beta Was this translation helpful? Give feedback.
All reactions