package main import ( "io" "io/ioutil" "os" "strings" ) // Reads all .txt files in the current folder // and encodes them as strings literals in textfiles.go func main() { fs, _ := ioutil.ReadDir("templates/") out, _ := os.Create("templates.go") out.Write([]byte("package main \n\nconst (\n")) for _, f := range fs { if strings.HasSuffix(f.Name(), ".tmpl") { out.Write([]byte(strings.TrimSuffix(f.Name(), ".tmpl") + " = `")) f, _ := os.Open("templates/" + f.Name()) io.Copy(out, f) out.Write([]byte("`\n")) } } out.Write([]byte(")\n")) out.Write([]byte("func getTemplate() string {\n")) out.Write([]byte(`return "{{define \"block_facebook.tmpl\"}}" + block_facebook + "{{end}}{{define \"cache_static.tmpl\"}}" + cache_static + "{{end}} {{define \"pagespeed.tmpl\"}}" + pagespeed + "{{end}} {{define \"robots.tmpl\"}}" + robots + "{{end}} {{define \"ssl.tmpl\"}}" + ssl + "{{end}}" + server`)) out.Write([]byte("\n\n}\n")) out.Write([]byte("func isGenerated() bool { return true }\n")) }