diff --git a/embed.go b/embed.go index 2979477..7dd64d8 100644 --- a/embed.go +++ b/embed.go @@ -17,14 +17,19 @@ func embedTemplate() string { "\n" + "package {{.Package}}\n" + "\n" + + "\t{{ if not .EmptyContent }} " + "import \"encoding/base64\"\n" + + "{{ end }}\n" + "\n" + "// {{.Name}}Resource is a generated function returning the Resource as a []byte.\n" + "func {{.Name}}Resource() ([]byte, error) {\n" + "\tvar resource = \"{{.Content}}\"\n" + "\n" + - "\treturn base64.StdEncoding.DecodeString(resource)\n" + - "}\n" + - "" + "\treturn {{ if .EmptyContent }} " + + "[]byte(resource), nil" + + "{{ else }}" + + "base64.StdEncoding.DecodeString(resource)" + + "{{ end }}\n" + + "}\n" + "" return tmpl } diff --git a/embed.tpl b/embed.tpl index d589411..0fbf2c1 100644 --- a/embed.tpl +++ b/embed.tpl @@ -6,11 +6,12 @@ package {{.Package}} -import "encoding/base64" + {{ if not .EmptyContent }} import "encoding/base64" +{{ end }} // {{.Name}}Resource is a generated function returning the Resource as a []byte. func {{.Name}}Resource() ([]byte, error) { var resource = "{{.Content}}" - return base64.StdEncoding.DecodeString(resource) + return {{ if .EmptyContent }} []byte(resource), nil{{ else }}base64.StdEncoding.DecodeString(resource){{ end }} } diff --git a/mule.go b/mule.go index 1a724a8..44f14d8 100644 --- a/mule.go +++ b/mule.go @@ -185,9 +185,10 @@ func main() { } data := struct { - Package string - Name string - Content string + Package string + Name string + Content string + EmptyContent bool }{ Package: pckg, Name: strings.Split(functionname, ".")[0], @@ -198,6 +199,10 @@ func main() { os.Exit(1) } + if len(data.Content) == 0 { + data.EmptyContent = true + } + outfile, err := os.Create(outfilename) if err != nil { fmt.Printf("Error creating target file '%s'\n%v\n", outfilename, err)