Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BaiZe1998
Copy link

@BaiZe1998 BaiZe1998 commented Jul 26, 2024

  • ServerOptionLoader
  • ClientOptionLoader
  • StreamClientOptionLoader
  • CalloptOptionLoader
  • StreamCallOptionLoader
  • Unit Test

Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

// RegisterTranslator registers a translator function.
RegisterTranslator(translator Translator)
// Load loads the server options from config and custom registered option translators.
Load() ([]server.Option, error)

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.

Copy link
Author

@BaiZe1998 BaiZe1998 Jul 30, 2024

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
}

@DMwangnima DMwangnima self-assigned this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants