Embedded the Templates in the go binary
All checks were successful
Build / Build (push) Successful in 1m26s
All checks were successful
Build / Build (push) Successful in 1m26s
This commit is contained in:
parent
1f05960ffc
commit
41437f0f2f
6
main.go
6
main.go
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user