本文整理匯總了Golang中github.com/vulcand/vulcand/proxy.Proxy.UpsertListener方法的典型用法代碼示例。如果您正苦於以下問題:Golang Proxy.UpsertListener方法的具體用法?Golang Proxy.UpsertListener怎麽用?Golang Proxy.UpsertListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vulcand/vulcand/proxy.Proxy
的用法示例。
在下文中一共展示了Proxy.UpsertListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initProxy
// initProxy reads the configuration from the engine and configures the server
func initProxy(ng engine.Engine, p proxy.Proxy) (uint64, error) {
snapshot, err := ng.GetSnapshot()
if err != nil {
// Some legacy engines do not implement `GetSnapshot` so we resort to
// a slow method of obtaining configuration from Etcd.
if _, ok := err.(*engine.SnapshotNotSupportedError); ok {
return 0, initProxySlow(ng, p)
}
return 0, err
}
for _, h := range snapshot.Hosts {
if err := p.UpsertHost(h); err != nil {
return 0, err
}
}
for _, bs := range snapshot.BackendSpecs {
if err := p.UpsertBackend(bs.Backend); err != nil {
return 0, err
}
for _, server := range bs.Servers {
if err := p.UpsertServer(bs.Backend.GetUniqueId(), server); err != nil {
return 0, err
}
}
}
for _, l := range snapshot.Listeners {
if err := p.UpsertListener(l); err != nil {
return 0, err
}
}
for _, fs := range snapshot.FrontendSpecs {
if err := p.UpsertFrontend(fs.Frontend); err != nil {
return 0, err
}
for _, m := range fs.Middlewares {
if err := p.UpsertMiddleware(fs.Frontend.GetKey(), m); err != nil {
return 0, err
}
}
}
return snapshot.Index, nil
}
示例2: processChange
// processChange takes the backend change notification emitted by the backend and applies it to the server
func processChange(p proxy.Proxy, ch interface{}) error {
switch change := ch.(type) {
case *engine.HostUpserted:
return p.UpsertHost(change.Host)
case *engine.HostDeleted:
return p.DeleteHost(change.HostKey)
case *engine.ListenerUpserted:
return p.UpsertListener(change.Listener)
case *engine.ListenerDeleted:
return p.DeleteListener(change.ListenerKey)
case *engine.FrontendUpserted:
return p.UpsertFrontend(change.Frontend)
case *engine.FrontendDeleted:
return p.DeleteFrontend(change.FrontendKey)
case *engine.MiddlewareUpserted:
return p.UpsertMiddleware(change.FrontendKey, change.Middleware)
case *engine.MiddlewareDeleted:
return p.DeleteMiddleware(change.MiddlewareKey)
case *engine.BackendUpserted:
return p.UpsertBackend(change.Backend)
case *engine.BackendDeleted:
return p.DeleteBackend(change.BackendKey)
case *engine.ServerUpserted:
return p.UpsertServer(change.BackendKey, change.Server)
case *engine.ServerDeleted:
return p.DeleteServer(change.ServerKey)
}
return fmt.Errorf("unsupported change: %#v", ch)
}
示例3: initProxySlow
// initProxySlow reads configuration from Etcd piece by piece. That may take
// several minutes on large configurations!
func initProxySlow(ng engine.Engine, p proxy.Proxy) error {
hosts, err := ng.GetHosts()
if err != nil {
return err
}
for _, h := range hosts {
if err := p.UpsertHost(h); err != nil {
return err
}
}
bs, err := ng.GetBackends()
if err != nil {
return err
}
for _, b := range bs {
if err := p.UpsertBackend(b); err != nil {
return err
}
bk := engine.BackendKey{Id: b.Id}
servers, err := ng.GetServers(bk)
if err != nil {
return err
}
for _, s := range servers {
if err := p.UpsertServer(bk, s); err != nil {
return err
}
}
}
ls, err := ng.GetListeners()
if err != nil {
return err
}
for _, l := range ls {
if err := p.UpsertListener(l); err != nil {
return err
}
}
fs, err := ng.GetFrontends()
if err != nil {
return err
}
if len(fs) == 0 {
log.Warningf("No frontends found")
}
for _, f := range fs {
if err := p.UpsertFrontend(f); err != nil {
log.Warningf("Cannot register frontend \"%v\", invalid backend config", f.Id)
continue
}
fk := engine.FrontendKey{Id: f.Id}
ms, err := ng.GetMiddlewares(fk)
if err != nil {
return err
}
for _, m := range ms {
if err := p.UpsertMiddleware(fk, m); err != nil {
log.Warningf("Cannot register frontend \"%v\", invalid middleware config", f.Id)
continue
}
}
}
return nil
}