micro.newService() 中 newOptions
func newOptions(opts ...Option) Options {
opt := Options{
Auth: auth.DefaultAuth,
Broker: broker.DefaultBroker,
Cmd: cmd.DefaultCmd,
Config: config.DefaultConfig,
Client: client.DefaultClient,
Server: server.DefaultServer,
Store: store.DefaultStore,
Registry: registry.DefaultRegistry,
Router: router.DefaultRouter,
Runtime: runtime.DefaultRuntime,
Transport: transport.DefaultTransport,
Context: context.Background(),
Signal: true,
}
for _, o := range opts {o(&opt)
}
return opt
}
初始化了一堆根底设置,来看看 Runtimeruntime.DefaultRuntime,
在 runtime/runtime.go 中的 DefaultRuntime Runtime = NewRuntime()
// NewRuntime creates new local runtime and returns it
func NewRuntime(opts ...Option) Runtime {
// get default options
options := Options{}
// apply requested options
for _, o := range opts {o(&options)
}
// make the logs directory
path := filepath.Join(os.TempDir(), "micro", "logs")
_ = os.MkdirAll(path, 0755)
return &runtime{
options: options,
closed: make(chan bool),
start: make(chan *service, 128),
namespaces: make(map[string]map[string]*service),
}
}
这里做了以下事件:
- 初始化并设置 options
- 创立日志目录,零碎的长期目录 /micro/logs
- 返回 runtime{}
runtime 的相干介绍 https://github.com/micro/docs…