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

Most realisations of ymlloader and some realisations of etcdloader #1

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

Conversation

Printemps417
Copy link

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ zhu-mi-shan
❌ Printemps417
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Printemps417

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

**Additional context**

Add any other context about the problem here.
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是改了什么?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只是 \n 被改成了 \r\n ,那就调整一下你们的 IDE 设置,这样没意义的修改会干扰 review 和后续的协作。

go.mod Outdated
@@ -0,0 +1,52 @@
module github.com/Printemps417/optionloader
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github.com/kitex-contrib/optionloader

@@ -0,0 +1 @@
package client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有完成的内容不要提交

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etcd 和 consul 的实现,可以分到独立的 PR 提交

kitexclient "github.com/cloudwego/kitex/client"
)

type clientTranslator func(FieldConfig interface{}) ([]kitexclient.Option, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非导出的符号,这个库的使用者怎么用呢?

}
func (loader *clientLoader) Load() error {
for field, translator := range loader.translators {
// 通过字段名获取字段值
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloudWeGo 项目里不应该使用中文注释

continue
}
loader.options = append(loader.options, opts...)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于配置中没有注册 translator 的key,最好也打个日志,以便排查。

}

// 实现 Loader 接口的 GetOptions 方法。
func (l *clientLoader) GetOptions() ([]kitexclient.Option, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 GetOptions 这么实现的话,就没必要返回 error 了。

我建议是在 Load 方法加载配置数据,GetOptions 完成翻译,期间如果出现错误,可以返回错误,这样调用方才能根据情况处理。

return nil
}

// 实现 Loader 接口的 AddDefaultOptions 方法。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口的意义是什么?

func (l *clientLoader) DeregisterTranslator(fieldName string) error {
// 注销字段名到 client 选项的转换器
delete(l.translators, fieldName)
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个返回值也没什么意义


// CircuitBreaker
type Circuitbreaker circuitbreak.CBConfig
type YMLConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样硬编码的配置项,用户怎么扩展?

@HeyJavaBean
Copy link

ci挂了,可以调整下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants