work on generating main.go and use config not hardcoded vals

This commit is contained in:
cubixle
2021-06-18 13:58:58 +01:00
parent feff0c38eb
commit f435f65536
10 changed files with 124 additions and 76 deletions
+31
View File
@@ -0,0 +1,31 @@
package tuugen
import (
"embed"
"html/template"
"os"
"path/filepath"
)
func GenerateMain(FS embed.FS, cfg Config) error {
t, err := template.ParseFS(FS, "templates/main.go.tmpl")
if err != nil {
return err
}
outputFile := "cmd/app/main.go"
fp := filepath.Dir(outputFile)
if err := os.MkdirAll(fp, 0777); err != nil {
return err
}
f, err := os.Create(outputFile)
if err != nil {
return nil
}
if err := t.Execute(f, cfg); err != nil {
return err
}
return nil
}