diff options
| author | horus_arch | 2015-07-27 22:24:09 +0200 |
|---|---|---|
| committer | horus_arch | 2015-07-27 22:52:09 +0200 |
| commit | ebfb0155ac6a4fba93ebb846878ca211e9384226 (patch) | |
| tree | 0f9faa9e9afed9ce92dbd8e5cac796a833f86cd5 /generate | |
| download | ngxconf-ebfb0155ac6a4fba93ebb846878ca211e9384226.tar.gz | |
Diffstat (limited to 'generate')
| -rw-r--r-- | generate/include.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/generate/include.go b/generate/include.go new file mode 100644 index 0000000..54c2ba9 --- /dev/null +++ b/generate/include.go @@ -0,0 +1,30 @@ +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")) + +} |
