本文整理匯總了Golang中github.com/mholt/caddy/config/setup.Controller.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.Args方法的具體用法?Golang Controller.Args怎麽用?Golang Controller.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mholt/caddy/config/setup.Controller
的用法示例。
在下文中一共展示了Controller.Args方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newMesosUpstreams
func newMesosUpstreams(c *setup.Controller) ([]proxy.Upstream, error) {
var upstreams []proxy.Upstream
for c.Next() {
upstream := &mesosUpstream{
from: "",
hosts: new(atomic.Value),
Policy: &proxy.Random{},
FailTimeout: 10 * time.Second,
MaxFails: 1,
SyncInterval: 120 * time.Second,
Scheme: "http",
}
upstream.hosts.Store(proxy.HostPool([]*proxy.UpstreamHost{}))
var proxyHeaders http.Header
var port string
if !c.Args(&upstream.from, &upstream.mesosMaster, &upstream.framework, &upstream.taskName, &port) {
return upstreams, c.ArgErr()
}
if p, err := strconv.Atoi(port); err == nil {
if p == 0 {
return upstreams, errInvalidPort
} else {
upstream.Port = p
}
} else {
return upstreams, err
}
for c.NextBlock() {
switch c.Val() {
case "policy":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
switch c.Val() {
case "random":
upstream.Policy = &proxy.Random{}
case "round_robin":
upstream.Policy = &proxy.RoundRobin{}
case "least_conn":
upstream.Policy = &proxy.LeastConn{}
default:
return upstreams, c.ArgErr()
}
case "fail_timeout":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
if dur, err := time.ParseDuration(c.Val()); err == nil {
upstream.FailTimeout = dur
} else {
return upstreams, err
}
case "max_fails":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
if n, err := strconv.Atoi(c.Val()); err == nil {
upstream.MaxFails = int32(n)
} else {
return upstreams, err
}
case "health_check":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
upstream.HealthCheck.Path = c.Val()
upstream.HealthCheck.Interval = 30 * time.Second
if c.NextArg() {
if dur, err := time.ParseDuration(c.Val()); err == nil {
upstream.HealthCheck.Interval = dur
} else {
return upstreams, err
}
}
case "proxy_header":
var header, value string
if !c.Args(&header, &value) {
return upstreams, c.ArgErr()
}
if proxyHeaders == nil {
proxyHeaders = make(map[string][]string)
}
proxyHeaders.Add(header, value)
case "sync_interval":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
if dur, err := time.ParseDuration(c.Val()); err == nil {
upstream.SyncInterval = dur
} else {
return upstreams, err
}
case "scheme":
if !c.NextArg() {
return upstreams, c.ArgErr()
}
upstream.Scheme = c.Val()
//.........這裏部分代碼省略.........