func (b *broker) Init(c *component.Component) error { b.Component = c b.InitStatus() err := b.Component.UpdateTokenKey() if err != nil { return err } err = b.Component.Announce() if err != nil { return err } b.Discovery.GetAll("handler") // Update cache var conn *grpc.ClientConn if b.nsCert == "" { conn, err = api.Dial(b.nsAddr) } else { conn, err = api.DialWithCert(b.nsAddr, b.nsCert) } if err != nil { return err } b.nsConn = conn b.ns = networkserver.NewNetworkServerClient(conn) b.checkPrefixAnnouncements() b.Component.SetStatus(component.StatusHealthy) return nil }
// Dial dials the component represented by this Announcement func (a *Announcement) Dial() (*grpc.ClientConn, error) { if a.NetAddress == "" { return nil, errors.New("Can not dial this component") } if a.Certificate == "" { return api.Dial(strings.Split(a.NetAddress, ",")[0]) } return api.DialWithCert(strings.Split(a.NetAddress, ",")[0], a.Certificate) }