64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"html/template"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
type IndexData struct {
|
|
Assets string
|
|
Control string
|
|
|
|
Bucket string
|
|
Title string
|
|
|
|
Development bool
|
|
}
|
|
|
|
var data = IndexData{
|
|
Development: true,
|
|
}
|
|
var tmpl string
|
|
var out string
|
|
|
|
func main() {
|
|
flag.StringVar(&tmpl, "t", "", "template file")
|
|
flag.StringVar(&out, "o", "", "output file")
|
|
flag.StringVar(&data.Assets, "a", "", ".Assets")
|
|
flag.StringVar(&data.Control, "c", "", ".Control")
|
|
flag.StringVar(&data.Bucket, "b", "", ".Bucket")
|
|
flag.StringVar(&data.Title, "title", "", ".Title")
|
|
flag.Parse()
|
|
|
|
f, err := os.Open(tmpl)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
buf, err := ioutil.ReadAll(f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
t := template.Must(
|
|
template.New("index").Parse(string(buf)),
|
|
)
|
|
|
|
indexBuf := new(bytes.Buffer)
|
|
err = t.Execute(indexBuf, data)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
of, err := os.OpenFile(out, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
_, err = of.Write(indexBuf.Bytes())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|