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

将config的初始化在CreateAPP时执行,并且可以传入初始化好的conf来自由载入conf #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iKuiki
Copy link

@iKuiki iKuiki commented Apr 26, 2019

修改了App的初始化逻辑:

原来:app的setting是在Run方法执行时载入的,通过conf的LoadConfig方法
现在:app的setting是在Create时载入的,并且可以传入已经load好的conf.Config对象,来跳过从硬盘读取

影响:
为了提前初始化conf,将参数debug也一并移动到了CreateAPP方法中,所以原来在run时才传的debug参数现在要移到CreateAPP的时候传入

CreateAPP的参数除了debug,还可以传入其他选项,当前实现了传入conf.Config对象,可以直接以此作为setting来创建app:

func NewApp(version string, debug bool, options ...interface{}) module.App {
...
	var (
		optConf *conf.Config
	)
	for _, option := range options {
		switch o := option.(type) {
		case conf.Config:
			optConf = &o
		default:
			panic(option)
		}
	}
...
}

以这种方式传入options可以使app变得更为灵活

例如,以后可以把logger也作为一个实例化好的对象直接传入(入未传入则使用默认的),然后app内部需要log时直接调用app.logger.Debug("something")这样,可以进一步解耦,我们只需要定一个log Interface,这样可以很方便的对接到三方logger方案并且非常优雅

望采纳

希望mqant越加强大

@liangdas
Copy link
Owner

可以基于real分支修改不,real分支是以后的分支,我近期打算合并到主分支了

@liangdas
Copy link
Owner

你这样的方案很不错,未来mqant都打算改造为这样的接口形式

@iKuiki
Copy link
Author

iKuiki commented Apr 28, 2019

我有基于real分支有修改,但是real分支没有对应的test或者对应的example可以用来测试,我没测过不知是否会影响其他的地方

@liangdas
Copy link
Owner

我最近会花时间来合并这个代码

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.

2 participants