本文整理匯總了Golang中github.com/telemetryapp/gotelemetry_agent/agent/job.Job.Config方法的典型用法代碼示例。如果您正苦於以下問題:Golang Job.Config方法的具體用法?Golang Job.Config怎麽用?Golang Job.Config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/telemetryapp/gotelemetry_agent/agent/job.Job
的用法示例。
在下文中一共展示了Job.Config方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Init
func (p *ProcessPlugin) Init(job *job.Job) error {
c := job.Config()
job.Debugf("The configuration is %#v", c)
var ok bool
p.flowTag, ok = c["flow_tag"].(string)
if !ok {
p.flowTag, _ = c["tag"].(string)
}
p.batch, ok = c["batch"].(bool)
if ok && p.flowTag != "" {
return errors.New("You cannot specify both `flow_tag` and `batch` properties.")
}
exec, _ := c["exec"].(string)
script, _ := c["script"].(string)
if exec != "" && script != "" {
return errors.New("You cannot specify both `script` and `exec` properties.")
}
if exec != "" {
p.path = exec
} else if script != "" {
p.path = script
}
p.url, _ = c["url"].(string)
if p.path == "" && p.url == "" {
return errors.New("You must specify a `script`, `exec`, or `url` property.")
}
if p.path != "" && p.url != "" {
return errors.New("You cannot provide both `script` or `exec` and `url` properties.")
}
p.args = []string{}
p.scriptArgs = map[string]interface{}{}
if args, ok := c["args"].([]interface{}); ok {
for _, arg := range args {
if a, ok := arg.(string); ok {
p.args = append(p.args, a)
} else {
p.args = append(p.args, fmt.Sprintf("%#v", arg))
}
}
} else if args, ok := c["args"].(map[interface{}]interface{}); ok {
p.scriptArgs = config.MapTemplate(args).(map[string]interface{})
} else if args, ok := c["args"].(map[string]interface{}); ok {
p.scriptArgs = args
}
if p.path != "" {
if _, err := os.Stat(p.path); os.IsNotExist(err) {
return errors.New("File " + p.path + " does not exist.")
}
if path.Ext(p.path) == ".lua" {
p.url = "tpl://" + p.path
p.path = ""
} else {
if len(p.scriptArgs) != 0 {
return errors.New("You cannot specify an key/value hash of arguments when executing an external process. Provide an array of arguments instead.")
}
}
}
if p.url != "" {
if len(p.args) != 0 {
return errors.New("You cannot specify an array of arguments when executing a template. Provide a key/value hash instead.")
}
if strings.HasPrefix(p.url, "tpl://") {
URL, err := url.Parse(p.url)
if err != nil {
return err
}
p.templateFile = URL.Host + URL.Path
if _, err := os.Stat(p.templateFile); os.IsNotExist(err) {
return errors.New("Template " + p.templateFile + " does not exist.")
}
}
}
template, templateOK := c["template"]
variant, variantOK := c["variant"].(string)
if variantOK && templateOK {
if p.flowTag == "" {
return errors.New("The required `flow_tag` property (`string`) is either missing or of the wrong type.")
//.........這裏部分代碼省略.........