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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -13,6 +14,9 @@ import (
|
|||||||
"github.com/knadh/koanf/providers/file"
|
"github.com/knadh/koanf/providers/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed templates/*
|
||||||
|
var embeddedTemplates embed.FS
|
||||||
|
|
||||||
var appConfig = koanf.New(".")
|
var appConfig = koanf.New(".")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -48,7 +52,7 @@ func main() {
|
|||||||
cfg.FileName = *outFileName
|
cfg.FileName = *outFileName
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.InitTemplates()
|
proto.InitTemplates(embeddedTemplates, "templates/*.tmpl")
|
||||||
|
|
||||||
header, err := proto.CreateCStyleHeader(&cfg)
|
header, err := proto.CreateCStyleHeader(&cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package proto
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -73,13 +74,13 @@ type CStyleData struct {
|
|||||||
|
|
||||||
var tmpl *template.Template
|
var tmpl *template.Template
|
||||||
|
|
||||||
func InitTemplates() {
|
func InitTemplates(fsys fs.FS, pattern string) {
|
||||||
funcs := template.FuncMap{
|
funcs := template.FuncMap{
|
||||||
"snake": toSnakeCase,
|
"snake": toSnakeCase,
|
||||||
"isLast": isLast,
|
"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 {
|
if err != nil {
|
||||||
log.Fatalf("failed to parse templates: %v", err)
|
log.Fatalf("failed to parse templates: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user