Refactor more things into class

This commit is contained in:
2024-09-12 15:50:02 +02:00
parent a5d6fa15a3
commit 3994b5aa74
2 changed files with 21 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
_ "embed"
"fmt"
"log"
"os"
@@ -12,6 +13,25 @@ import (
"github.com/davecgh/go-spew/spew"
)
//go:embed class.tmpl
var templatestr string
var classTemplate *template.Template
var fns = template.FuncMap{
"plus1": func(x int) int {
return x + 1
},
}
func init() {
var err error
classTemplate, err = template.New("class").Funcs(fns).Parse(templatestr)
if err != nil {
Error.Printf("Error parsing template: %v", err)
return
}
}
type (
Class struct {
ClassName string

18
main.go
View File

@@ -7,16 +7,12 @@ import (
"log"
"os"
"sync"
"text/template"
"github.com/davecgh/go-spew/spew"
_ "embed"
)
//go:embed class.tmpl
var templatestr string
var Error *log.Logger
var Warning *log.Logger
@@ -36,12 +32,6 @@ func init() {
spew.Config.SortKeys = true
}
var fns = template.FuncMap{
"plus1": func(x int) int {
return x + 1
},
}
func main() {
outdir := flag.String("o", ".", "Output directory")
flag.Parse()
@@ -52,12 +42,6 @@ func main() {
return
}
ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr)
if err != nil {
Error.Printf("Error parsing template: %v", err)
return
}
wg := sync.WaitGroup{}
for _, file := range files {
wg.Add(1)
@@ -68,7 +52,7 @@ func main() {
Error.Printf("Error parsing file: %v", err)
return
}
class.Write(*outdir, ltemplate)
class.Write(*outdir, classTemplate)
}(file)
}
wg.Wait()