github.com/naoina/kocha@v0.7.1-0.20171129072645-78c7a531f799/cmd/kocha-build/skeleton/build/builder.go.tmpl (about)

     1  // AUTO-GENERATED BY kocha build
     2  // DO NOT EDIT THIS FILE
     3  package main
     4  
     5  import (
     6  	"github.com/naoina/kocha"
     7  	"github.com/naoina/kocha/util"
     8  	"io/ioutil"
     9  	config "{{.configImportPath}}"
    10  	"os"
    11  	"text/template"
    12  )
    13  
    14  const (
    15  	mainTemplate = {{.mainTemplate|printf "%q"}}
    16  )
    17  
    18  func main() {
    19  	funcMap := template.FuncMap{
    20  		"goString": util.GoString,
    21  	}
    22  	t := template.Must(template.New("main").Funcs(funcMap).Parse(mainTemplate))
    23  	file, err := os.Create("{{.mainFilePath}}")
    24  	if err != nil {
    25  		panic(err)
    26  	}
    27  	defer file.Close()
    28  	app, err := kocha.New(config.AppConfig)
    29  	if err != nil {
    30  		panic(err)
    31  	}
    32  	res := map[string]string{
    33  		{{range $name, $path := .resources}}
    34  		"{{$name}}": "{{$path}}",
    35  		{{end}}
    36  	}
    37  	resources := make(map[string]string)
    38  	for name, path := range res {
    39  		buf, err := ioutil.ReadFile(path)
    40  		if err != nil {
    41  			panic(err)
    42  		}
    43  		resources[name] = util.Gzip(string(buf))
    44  	}
    45  	data := map[string]interface{}{
    46  		"app":                   app,
    47  		"configImportPath":      "{{.configImportPath}}",
    48  		"dbImportPath":          "{{.dbImportPath}}",
    49  		"migrationImportPath":  "{{.migrationImportPath}}",
    50  		"resources":             resources,
    51  		"version":               "{{.version}}",
    52  	}
    53  	if err := t.Execute(file, data); err != nil {
    54  		panic(err)
    55  	}
    56  }