mirror of
https://github.com/cubixle/tuugen.git
synced 2026-04-30 19:48:44 +01:00
tidy up
This commit is contained in:
+10
-18
@@ -7,7 +7,6 @@ import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
@@ -50,23 +49,6 @@ func (s serviceFuncDef) ArgsToStr() string {
|
||||
|
||||
// generate the service/interactor template and store it to a file.
|
||||
func createFileFromProto(FS embed.FS, cfg Config, templateFile, outputFile string) error {
|
||||
// load service template
|
||||
t, err := template.ParseFS(FS, templateFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check/create file path
|
||||
fp := filepath.Dir(outputFile)
|
||||
|
||||
if err := os.MkdirAll(fp, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
def, err := parseProto(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -77,6 +59,16 @@ func createFileFromProto(FS embed.FS, cfg Config, templateFile, outputFile strin
|
||||
def.Imports = append(def.Imports, cfg.ImportPath+"/internal/interactors")
|
||||
}
|
||||
|
||||
f, err := createFile(outputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t, err := template.ParseFS(FS, templateFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.Execute(f, def); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user