@@ 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 {