|
2 months ago | |
---|---|---|
cmd | 3 months ago | |
examples | 10 months ago | |
CHANGELOG.md | 2 months ago | |
LICENSE | 2 years ago | |
README.md | 3 months ago | |
TODO.md | 2 months ago | |
data.go | 2 months ago | |
data_test.go | 2 months ago | |
file.go | 9 months ago | |
file_test.go | 9 months ago | |
go.mod | 1 year ago | |
go.sum | 2 years ago | |
template.go | 2 months ago | |
template_test.go | 2 months ago |
dati provides a single unified interface for data-serialization and template languages. Ideally it supports any language that you need! If it doesn't, let me know or feel free to add support and submit a patch.
It can be used as a Go library or a binary for excuting data against templates, it was built as a library first but works well in both forms:
Why?
Load data files without dati:
package example
import("os";"io";"path/filepath";"encoding/json";"gopkg.in/yaml.v3";"github.com/pelletier/go-toml")
func ParseDataFile(path string) (data map[string]any, err error) {
var file *os.File
if file, err = os.Open(path); err != nil {
return
}
var filedata []byte
if filedata, err = io.ReadAll(file); err != nil {
return
}
switch filepath.Ext(path) {
case ".yaml":
err = yaml.Unmarshal(filedata, &data)
case ".toml":
err = toml.Unmarshal(filedata, &data)
case ".json":
err = json.Unmarshal(filedata, &data)
default:
err = fmt.Errorf("unsupported filetype: '%s'", filepath.Ext(path))
}
return
}
Load any data file with dati:
package example
import ("notabug.org/gearsix/dati")
func ParseDataFile(path string) (data map[string]any, err error) {
err = dati.LoadDataFile(path, &data)
return
}
And this doesn't even begin to demonstrate the relief dati provides when libraries have different interfaces (the template libraries are much worse for this)!
Supported Data-Serialization Languages
Supported Template Language
All of these libraries do the hard work, dati just combines them together - so thanks to the authors. Also here for reference.