37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
generator.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
Aiwantaozi 提交于 2019-04-11 17:03 . Add fluentd configure parser
package generator
import (
"bytes"
"os"
"text/template"
)
var tmplCache = template.New("template")
func init() {
tmplCache = tmplCache.Funcs(template.FuncMap{"escapeString": escapeString})
tmplCache = template.Must(tmplCache.Parse(FilterCustomTagTemplate))
tmplCache = template.Must(tmplCache.Parse(clusterFilterSyslogTemplate))
tmplCache = template.Must(tmplCache.Parse(clusterOutputTemplate))
tmplCache = template.Must(tmplCache.Parse(projectFilterSyslogTemplate))
tmplCache = template.Must(tmplCache.Parse(projectOutputTemplate))
}
func GenerateConfigFile(outputPath, templateM, tempalteName string, conf map[string]interface{}) error {
tp, err := tmplCache.Parse(templateM)
if err != nil {
return err
}
output, err := os.Create(outputPath)
if err != nil {
return err
}
defer output.Close()
return tp.Execute(output, conf)
}
func GenerateConfig(tempalteName string, conf interface{}) ([]byte, error) {
buf := &bytes.Buffer{}
if err := tmplCache.ExecuteTemplate(buf, tempalteName, conf); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.10

搜索帮助