本文整理匯總了Golang中github.com/mholt/caddy/config/setup.Controller.Err方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.Err方法的具體用法?Golang Controller.Err怎麽用?Golang Controller.Err使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mholt/caddy/config/setup.Controller
的用法示例。
在下文中一共展示了Controller.Err方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseSearch
// parseSearch controller information to create a IndexSearch config
func parseSearch(c *setup.Controller) (*Config, error) {
conf := &Config{
HostName: c.Address(),
Engine: `bleve`,
IndexDirectory: `/tmp/caddyIndex`,
IncludePaths: []*regexp.Regexp{},
ExcludePaths: []*regexp.Regexp{},
Endpoint: `/search`,
SiteRoot: c.Root,
}
incPaths := []string{}
excPaths := []string{}
for c.Next() {
args := c.RemainingArgs()
if len(args) == 1 {
incPaths = append(incPaths, c.Val())
}
for c.NextBlock() {
switch c.Val() {
case "engine":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Engine = c.Val()
case "+path":
if !c.NextArg() {
return nil, c.ArgErr()
}
incPaths = append(incPaths, c.Val())
incPaths = append(incPaths, c.RemainingArgs()...)
case "-path":
if !c.NextArg() {
return nil, c.ArgErr()
}
excPaths = append(excPaths, c.Val())
excPaths = append(excPaths, c.RemainingArgs()...)
case "endpoint":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Endpoint = c.Val()
case "datadir":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.IndexDirectory = c.Val()
case "template":
var err error
if c.NextArg() {
conf.Template, err = template.ParseFiles(filepath.Join(conf.SiteRoot, c.Val()))
if err != nil {
return nil, err
}
} else {
conf.Template, err = template.New("search-results").Parse(defaultTemplate)
if err != nil {
return nil, err
}
}
}
}
}
if len(incPaths) == 0 {
incPaths = append(incPaths, "^/")
}
conf.IncludePaths = convertToRegExp(incPaths)
conf.ExcludePaths = convertToRegExp(excPaths)
dir := conf.IndexDirectory
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return nil, c.Err("Given 'datadir' not a valid path.")
}
}
return conf, nil
}
示例2: parseSearch
// parseSearch controller information to create a IndexSearch config
func parseSearch(c *setup.Controller) (conf *Config, err error) {
conf = &Config{
HostName: c.Address(),
Engine: `bleve`,
IndexDirectory: `/tmp/caddyIndex`,
IncludePaths: []*regexp.Regexp{},
ExcludePaths: []*regexp.Regexp{},
Endpoint: `/search`,
}
incPaths := []string{}
excPaths := []string{}
for c.Next() {
args := c.RemainingArgs()
if len(args) == 1 {
incPaths = append(incPaths, c.Val())
}
for c.NextBlock() {
switch c.Val() {
case "engine":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Engine = c.Val()
case "+path":
if !c.NextArg() {
return nil, c.ArgErr()
}
incPaths = append(incPaths, c.Val())
incPaths = append(incPaths, c.RemainingArgs()...)
case "-path":
if !c.NextArg() {
return nil, c.ArgErr()
}
excPaths = append(excPaths, c.Val())
excPaths = append(excPaths, c.RemainingArgs()...)
case "endpoint":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Endpoint = c.Val()
case "datadir":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.IndexDirectory = c.Val()
}
}
}
if len(incPaths) == 0 {
incPaths = append(incPaths, "^/")
}
conf.IncludePaths = convertToRegExp(incPaths)
conf.ExcludePaths = convertToRegExp(excPaths)
dir := conf.IndexDirectory
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return nil, c.Err("Given `datadir` not a valid path.")
}
}
return
}