func main() { flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() parse.DocParse(dmsl.Open("tests/bigtable2.dmsl", "")) return } if *filename == "" { flag.Usage() return } if *pprint { parse.Pprint = true } if *debug { r, err := parse.DocParse(dmsl.Open(*filename, "")) if err != nil { fmt.Println(err) } fmt.Println(r) } else { t, err := dmsl.ParseFile(*filename) var d interface{} if err = json.Unmarshal([]byte(*data), &d); err != nil { fmt.Println(err.Error()) } result, err := t.Execute(d.([]interface{})) if err != nil { fmt.Println(err) } else { fmt.Println(result) } } }
func (t *Template) Execute(data interface{}) (string, error) { buf := &bytes.Buffer{} err := t.Html.Execute(buf, data) if err != nil { return "", err } r, err := parse.DocParse(buf.Bytes()) return t.DocType + r, err }