本文整理匯總了Golang中github.com/mholt/caddy.Controller.NextLine方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.NextLine方法的具體用法?Golang Controller.NextLine怎麽用?Golang Controller.NextLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mholt/caddy.Controller
的用法示例。
在下文中一共展示了Controller.NextLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: headersParse
func headersParse(c *caddy.Controller) ([]Rule, error) {
var rules []Rule
for c.NextLine() {
var head Rule
head.Headers = http.Header{}
var isNewPattern bool
if !c.NextArg() {
return rules, c.ArgErr()
}
pattern := c.Val()
// See if we already have a definition for this Path pattern...
for _, h := range rules {
if h.Path == pattern {
head = h
break
}
}
// ...otherwise, this is a new pattern
if head.Path == "" {
head.Path = pattern
isNewPattern = true
}
for c.NextBlock() {
// A block of headers was opened...
name := c.Val()
value := ""
if c.NextArg() {
value = c.Val()
}
head.Headers.Add(name, value)
}
if c.NextArg() {
// ... or single header was defined as an argument instead.
name := c.Val()
value := c.Val()
if c.NextArg() {
value = c.Val()
}
head.Headers.Add(name, value)
}
if isNewPattern {
rules = append(rules, head)
} else {
for i := 0; i < len(rules); i++ {
if rules[i].Path == pattern {
rules[i] = head
break
}
}
}
}
return rules, nil
}