-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Description
(Repost from https://github.com/go-easygen/easygen/wiki/V1-&-V2)
Version 1
Info
Sample code, V1
func exampleV1(templateFile string, config templateData) error {
t, err := easygen.ParseFiles(false, templateFile)
check(err)
env := make(map[string]string)
for _, e := range os.Environ() {
sep := strings.Index(e, "=")
env[e[0:sep]] = e[sep+1:]
}
config.ENV = env
err = t.Execute(os.Stdout, config)
return err
}Version 2
Sample code, V2
See
Lines 12 to 29 in 8022ae3
| func ExampleProcess() { | |
| tmpl0 := easygen.NewTemplate().Customize() | |
| tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egVar.FuncDefs()) | |
| tmplFileName := "test/var0" | |
| easygen.Process(tmpl, os.Stdout, tmplFileName) | |
| // To use Execute(), TemplateFileName has to be exact | |
| m := easygen.ReadDataFile(tmplFileName + ".yaml") | |
| easygen.Execute(tmpl, os.Stdout, tmplFileName+".tmpl", m) | |
| // Output: | |
| // Input: "some-init-method" | |
| // Output 1: "SomeInitMethod" | |
| // Output 2: "SOME_INIT_METHOD" | |
| // Input: "some-init-method" | |
| // Output 1: "SomeInitMethod" | |
| // Output 2: "SOME_INIT_METHOD" | |
| } |
In above code, to define tmpl with basic easygen functions without the addon ones, do
tmpl := easygen.NewTemplate().Funcs(easygen.FuncDefs())