mirror of
https://github.com/cubixle/tuugen.git
synced 2026-04-30 13:38:44 +01:00
work on generating main.go and use config not hardcoded vals
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user