gopkg.in/easygen.v4@v4.1.0/example_execute_test.go (about) 1 package easygen_test 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/go-easygen/easygen" 9 "github.com/go-easygen/easygen/egCal" 10 "github.com/go-easygen/easygen/egVar" 11 ) 12 13 type variable struct { 14 Name string 15 } 16 17 // for standalone test, change package to `main` and the next func def to, 18 // func main() { 19 func ExampleExecute() { 20 easygen.Opts.Debug = 1 21 22 tmpl0 := easygen.NewTemplate().Customize() 23 tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egVar.FuncDefs()).Funcs(egCal.FuncDefs()) 24 25 // define driving data of any tye 26 v0 := variable{"some-init-method"} 27 // https://godoc.org/github.com/go-easygen/easygen#Execute 28 // provide full template file name with extension 29 easygen.Execute(tmpl, os.Stdout, "test/var0.tmpl", v0) 30 31 // Demo of using driving data of pure slice/array 32 v1 := []string{"red", "blue", "white"} 33 easygen.Execute(tmpl, os.Stdout, "test/list00.tmpl", v1) 34 35 // Demo output to string 36 var b strings.Builder 37 easygen.Execute(tmpl, &b, "test/list00f.tmpl", v1) 38 fmt.Print(b.String()) 39 40 // Output: 41 // Input: "some-init-method" 42 // Output 1: "SomeInitMethod" 43 // Output 2: "SOME_INIT_METHOD" 44 // The colors are: red, blue, white, . 45 // The colors are: red, blue, white. 46 } 47 48 // To show the full code in GoDoc 49 type dummyExecute struct { 50 }