本文整理汇总了Golang中github.com/tsuru/tsuru/router.ValidCName函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidCName函数的具体用法?Golang ValidCName怎么用?Golang ValidCName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValidCName函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetCName
func (r *galebRouter) SetCName(cname, name string) error {
backendName, err := router.Retrieve(name)
if err != nil {
return err
}
domain, err := config.GetString(r.prefix + ":domain")
if err != nil {
return err
}
if !router.ValidCName(cname, domain) {
return router.ErrCNameNotAllowed
}
data, err := getGalebData(backendName)
if err != nil {
return err
}
client, err := r.getClient()
if err != nil {
return err
}
for _, val := range data.CNames {
if val.CName == cname {
return router.ErrCNameExists
}
}
virtualHostParams := galebClient.VirtualHostParams{
Name: cname,
RuleDefault: data.RootRuleId,
}
virtualHostId, err := client.AddVirtualHost(&virtualHostParams)
if err != nil {
return err
}
return data.addCName(cname, virtualHostId)
}
示例2: SetCName
func (r *vulcandRouter) SetCName(cname, name string) error {
usedName, err := router.Retrieve(name)
if err != nil {
return err
}
if !router.ValidCName(cname, r.domain) {
return router.ErrCNameNotAllowed
}
frontendName := r.frontendName(cname)
if found, _ := r.client.GetFrontend(engine.FrontendKey{Id: frontendName}); found != nil {
return router.ErrCNameExists
}
frontend, err := engine.NewHTTPFrontend(
frontendName,
r.backendName(usedName),
fmt.Sprintf(`Host(%q)`, cname),
engine.HTTPFrontendSettings{},
)
if err != nil {
return &router.RouterError{Err: err, Op: "set-cname"}
}
err = r.client.UpsertFrontend(*frontend, engine.NoTTL)
if err != nil {
return &router.RouterError{Err: err, Op: "set-cname"}
}
return nil
}
示例3: SetCName
func (r *galebRouter) SetCName(cname, name string) error {
backendName, err := router.Retrieve(name)
if err != nil {
return err
}
if !router.ValidCName(cname, r.domain) {
return router.ErrCNameNotAllowed
}
_, err = r.client.AddVirtualHost(r.virtualHostName(cname))
if err == galebClient.ErrItemAlreadyExists {
return router.ErrCNameExists
}
if err != nil {
return err
}
return r.client.SetRuleVirtualHost(ruleName(backendName), r.virtualHostName(cname))
}
示例4: SetCName
func (r *fakeRouter) SetCName(cname, name string) error {
backendName, err := router.Retrieve(name)
if err != nil {
return err
}
if !r.HasBackend(backendName) {
return nil
}
if !router.ValidCName(cname, "fakerouter.com") {
return router.ErrCNameNotAllowed
}
r.mutex.Lock()
defer r.mutex.Unlock()
if _, ok := r.cnames[cname]; ok {
return router.ErrCNameExists
}
r.cnames[cname] = backendName
return nil
}
示例5: SetCName
func (r *hipacheRouter) SetCName(cname, name string) error {
backendName, err := router.Retrieve(name)
if err != nil {
return err
}
domain, err := config.GetString(r.prefix + ":domain")
if err != nil {
return &router.RouterError{Op: "setCName", Err: err}
}
if !router.ValidCName(cname, domain) {
return router.ErrCNameNotAllowed
}
conn, err := r.connect()
if err != nil {
return &router.RouterError{Op: "set", Err: err}
}
cnameExists := false
currentCnames, err := conn.LRange("cname:"+backendName, 0, -1).Result()
if err != nil {
return &router.RouterError{Op: "set", Err: err}
}
for _, n := range currentCnames {
if n == cname {
cnameExists = true
break
}
}
if !cnameExists {
err = conn.RPush("cname:"+backendName, cname).Err()
if err != nil {
return &router.RouterError{Op: "set", Err: err}
}
}
frontend := "frontend:" + backendName + "." + domain
cnameFrontend := "frontend:" + cname
wantedRoutes, err := conn.LRange(frontend, 1, -1).Result()
if err != nil {
return &router.RouterError{Op: "get", Err: err}
}
currentRoutes, err := conn.LRange(cnameFrontend, 0, -1).Result()
if err != nil {
return &router.RouterError{Op: "get", Err: err}
}
// Routes are always added again and duplicates removed this will ensure
// that after a call to SetCName is made routes will be identical to the
// original entry.
if len(currentRoutes) == 0 {
err = conn.RPush(cnameFrontend, backendName).Err()
if err != nil {
return &router.RouterError{Op: "setCName", Err: err}
}
} else {
currentRoutes = currentRoutes[1:]
}
for _, r := range wantedRoutes {
err = conn.RPush(cnameFrontend, r).Err()
if err != nil {
return &router.RouterError{Op: "setCName", Err: err}
}
}
for _, r := range currentRoutes {
err = conn.LRem(cnameFrontend, 1, r).Err()
if err != nil {
return &router.RouterError{Op: "setCName", Err: err}
}
}
if cnameExists {
return router.ErrCNameExists
}
return nil
}