Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
884c349d11 | ||
|
|
9c2606f03d |
12
README.md
Normal file
12
README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# 🛠️ Go Template Builder
|
||||
|
||||
A lightweight, no-nonsense Go library to parse and render templates directly from files. Stop writing boilerplate for `text/template` and `html/template`—just point to a file, pass your data, and you're done.
|
||||
|
||||
---
|
||||
|
||||
## 📦 Installation
|
||||
|
||||
To use this package in your project, run:
|
||||
|
||||
```bash
|
||||
go get [gitea.tecamino.com//paadi/template-builder](https://gitea.tecamino.com/paadi/template-builder)
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module gitea.tecamino.com/paadi/template-builder
|
||||
|
||||
go 1.25.4
|
||||
32
templateBuilder.go
Normal file
32
templateBuilder.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package templatebuilder
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"os"
|
||||
)
|
||||
|
||||
type TemplateBuilder struct {
|
||||
}
|
||||
|
||||
func NewTemplateBuilder() *TemplateBuilder {
|
||||
return &TemplateBuilder{}
|
||||
}
|
||||
|
||||
func (tb *TemplateBuilder) Generate(templatePath, outputFile string, data any) error {
|
||||
tmpl, err := template.ParseFiles(templatePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
err = tmpl.Execute(f, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
templatebuilder "gitea.tecamino.com/paadi/template-builder.git"
|
||||
templatebuilder "gitea.tecamino.com/paadi/template-builder"
|
||||
)
|
||||
|
||||
type Inventory struct {
|
||||
|
||||
Reference in New Issue
Block a user