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
}

初始化了一堆基础设置,来看看Runtime
runtime.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),
    }
}

这里做了以下事情:

  1. 初始化并设置options
  2. 创建日志目录,系统的临时目录/micro/logs
  3. 返回runtime{}

runtime的相关介绍https://github.com/micro/docs...

go micro 分析系列文章
go micro server 启动分析
go micro client
go micro broker
go micro cmd
go micro config
go micro store
go micro registry
go micro router
go micro runtime
go micro transport
go micro web
go micro registry 插件consul
go micro plugin
go micro jwt 网关鉴权
go micro 链路追踪
go micro 熔断与限流
go micro wrapper 中间件
go micro metrics 接入Prometheus、Grafana


舞林
1.5k 声望38 粉丝

漫步风雨中


« 上一篇
go micro router
下一篇 »
go micro transport