func NewRouter(c *config.Config) *Router { r := &Router{ config: c, } // setup number of procs if r.config.GoMaxProcs != 0 { runtime.GOMAXPROCS(r.config.GoMaxProcs) } // setup nats r.establishNATS() r.registry = NewRegistry(r.config) r.registry.isStateStale = func() bool { return !r.natsClient.Ping() } r.varz = NewVarz(r.registry) r.proxy = NewProxy(r.config, r.registry, r.varz, r) //怎么把自己也传过去,作为参数 varz := &vcap.Varz{ UniqueVarz: r.varz, } healthz := &vcap.Healthz{ LockableObject: r.registry, } var host string if r.config.Status.Port != 0 { host = fmt.Sprintf("%s:%d", r.config.Ip, r.config.Status.Port) } component := &vcap.VcapComponent{ Type: "Router", Index: r.config.Index, Host: host, Credentials: []string{r.config.Status.User, r.config.Status.Pass}, Config: r.config, Logger: log, Varz: varz, Healthz: healthz, InfoRoutes: map[string]json.Marshaler{ "/routes": r.registry, }, } vcap.Register(component, r.natsClient) return r }
func NewRouter(c *config.Config) *Router { r := &Router{ config: c, } // setup number of procs if r.config.GoMaxProcs != 0 { runtime.GOMAXPROCS(r.config.GoMaxProcs) } // setup nats r.natsClient = startNATS(r.config.Nats.Host, r.config.Nats.User, r.config.Nats.Pass) // setup varz r.varz = NewVarz() r.registry = NewRegistry(r.config) r.proxy = &Proxy{ Config: r.config, Varz: r.varz, Registry: r.registry, } r.varz.Registry = r.registry varz := &vcap.Varz{ UniqueVarz: r.varz, } var host string if r.config.Status.Port != 0 { host = fmt.Sprintf("%s:%d", r.config.Ip, r.config.Status.Port) } component := &vcap.VcapComponent{ Type: "Router", Index: r.config.Index, Host: host, Credentials: []string{r.config.Status.User, r.config.Status.Pass}, Config: r.config, Logger: log, Varz: varz, Healthz: "ok", } vcap.Register(component, r.natsClient) return r }
func (r *Router) RegisterComponent() { vcap.Register(r.component, r.mbusClient) }