~evanj/embed

1dcb9ff9e687d097033a5873ed00c89cefaa97a0 — Evan M Jones 4 years ago 4c8625c
Fix(*): File naming and getters.
1 files changed, 12 insertions(+), 2 deletions(-)

M embed.go
M embed.go => embed.go +12 -2
@@ 64,7 64,7 @@ func main() {

	src := g.format()

	baseName := fmt.Sprintf("_%s_embed.go", *id)
	baseName := fmt.Sprintf("%s_embed.go", *id)
	outputName := filepath.Join(dir, strings.ToLower(baseName))
	err := ioutil.WriteFile(outputName, src, 0644)
	if err != nil {


@@ 164,11 164,21 @@ func (g *Generator) generate(pattern string, id string) error {
var {{ .ID }} map[string]string

func init() {
	{{ .ID }}= make(map[string]string)
	{{ .ID }} = make(map[string]string)
	{{ range .Files }}
	{{ $.ID }}["{{ .Name }}"] = ` + "`{{ .Content }}`" + `
	{{ end }}
}

func Get(name string) (string, bool) {
	val, ok := {{ .ID }}[name]
	return val, ok
}

func Must(name string) string {
	val, _ := {{ .ID }}[name]
	return val
}
`)

	if err != nil {