本文整理汇总了Golang中github.com/cloudfoundry-incubator/routing-api/db.DB.ReadRouterGroups方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.ReadRouterGroups方法的具体用法?Golang DB.ReadRouterGroups怎么用?Golang DB.ReadRouterGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/routing-api/db.DB
的用法示例。
在下文中一共展示了DB.ReadRouterGroups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: seedRouterGroups
func seedRouterGroups(cfg config.Config, logger lager.Logger, database db.DB) {
// seed router groups from config
if len(cfg.RouterGroups) > 0 {
routerGroups, _ := database.ReadRouterGroups()
// if config not empty and db is empty, seed
if len(routerGroups) == 0 {
for _, rg := range cfg.RouterGroups {
guid, err := uuid.NewV4()
if err != nil {
logger.Error("failed to generate a guid for router group", err)
os.Exit(1)
}
rg.Guid = guid.String()
logger.Info("seeding", lager.Data{"router-group": rg})
err = database.SaveRouterGroup(rg)
if err != nil {
logger.Error("failed to save router group from config", err)
os.Exit(1)
}
}
}
}
}
示例2:
g, err := uuid.NewV4()
Expect(err).NotTo(HaveOccurred())
guid = g.String()
routerGroup = models.RouterGroup{
Name: "router-group-1",
Type: "tcp",
Guid: guid,
ReservablePorts: "10-20,25",
}
err = etcd.SaveRouterGroup(routerGroup)
Expect(err).NotTo(HaveOccurred())
})
It("can list the router groups", func() {
rg, err := etcd.ReadRouterGroups()
Expect(err).NotTo(HaveOccurred())
Expect(len(rg)).To(Equal(1))
Expect(rg[0]).Should(Equal(routerGroup))
})
It("updates the router group", func() {
routerGroup.Type = "http"
routerGroup.ReservablePorts = "10-20,25,30"
err := etcd.SaveRouterGroup(routerGroup)
Expect(err).NotTo(HaveOccurred())
node, err := etcdClient.Get(db.ROUTER_GROUP_BASE_KEY + "/" + guid)
Expect(err).NotTo(HaveOccurred())
Expect(node.TTL).To(Equal(uint64(0)))