-
Notifications
You must be signed in to change notification settings - Fork 3
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
[WIP]feat: option loaders to generate kitex options #5
base: main
Are you sure you want to change the base?
Conversation
BaiZe1998
commented
Jul 26, 2024
•
edited
Loading
edited
- ServerOptionLoader
- ClientOptionLoader
- StreamClientOptionLoader
- CalloptOptionLoader
- StreamCallOptionLoader
- Unit Test
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BaiZe1998 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
optionloader/server/optionloader.go
Outdated
// RegisterTranslator registers a translator function. | ||
RegisterTranslator(translator Translator) | ||
// Load loads the server options from config and custom registered option translators. | ||
Load() ([]server.Option, error) |
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.
What about changing this interface to Load(cfg *config.ServerConfig) ([]server.Option, error)
and transfer the logic from NewServerOptionLoader
to Load
?
Not only would one optionLoader
support multiple configs, but it would also be able to call each Translator
to get the options while iterating through the config.
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.
Something like that?
func NewServerOptionLoader() OptionLoader {
return &DefaultOptionLoader{
translators:make([]Translator, 0),
}
}
func (loader *DefaultOptionLoader) Load(config *config.ServerConfig) ([]server.Option, error) {
if config == nil {
return nil, fmt.Errorf("server config not set")
}
// generate translators from config
// ....
var options []server.Option
for _, trans := range loader.translators {
options = append(options, trans(config))
}
return options, nil
}