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 itfunc 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...