Embedded the Templates in the go binary
All checks were successful
Build / Build (push) Successful in 1m26s

This commit is contained in:
simon 2025-05-19 21:46:38 +02:00
parent 1f05960ffc
commit 41437f0f2f
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"embed"
"encoding/json"
"flag"
"fmt"
@ -13,6 +14,9 @@ import (
"github.com/knadh/koanf/providers/file"
)
//go:embed templates/*
var embeddedTemplates embed.FS
var appConfig = koanf.New(".")
func main() {
@ -48,7 +52,7 @@ func main() {
cfg.FileName = *outFileName
}
proto.InitTemplates()
proto.InitTemplates(embeddedTemplates, "templates/*.tmpl")
header, err := proto.CreateCStyleHeader(&cfg)
if err != nil {

View File

@ -3,6 +3,7 @@ package proto
import (
"bytes"
"encoding/json"
"io/fs"
"log"
"strconv"
"text/template"
@ -73,13 +74,13 @@ type CStyleData struct {
var tmpl *template.Template
func InitTemplates() {
func InitTemplates(fsys fs.FS, pattern string) {
funcs := template.FuncMap{
"snake": toSnakeCase,
"isLast": isLast,
}
Ntmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl")
Ntmpl, err := template.New("all").Funcs(funcs).ParseFS(fsys, pattern)
if err != nil {
log.Fatalf("failed to parse templates: %v", err)
}