data and template interface

gearsix 2750e20741 project: updated TODO; updated CHANGELOG 8 mesi fa
cmd 869ef50010 Overhaul to README docs; update to the `-h` for the dati binary. 8 mesi fa
examples 9e9f19905a v1 changes; removed DEPRECIATED code and a few fixes 1 anno fa
CHANGELOG.md 2750e20741 project: updated TODO; updated CHANGELOG 8 mesi fa
LICENSE a4fdfd4c88 added GPLv3 license; added mustache support 3 anni fa
README.md 869ef50010 Overhaul to README docs; update to the `-h` for the dati binary. 8 mesi fa
TODO.md 2750e20741 project: updated TODO; updated CHANGELOG 8 mesi fa
data.go abca941a73 bugfix: data & template ReadLanguage major fix 8 mesi fa
data_test.go c8e489bd45 test: fixes to data_test & template_test 8 mesi fa
file.go e0ca51e79c minor improvements, better variable names, updated LICENSE dates, etc 1 anno fa
file_test.go e0ca51e79c minor improvements, better variable names, updated LICENSE dates, etc 1 anno fa
go.mod 912752f46b REBRAND to 'dati - data and template interface' 2 anni fa
go.sum bb46d788e3 go.sum update 3 anni fa
template.go abca941a73 bugfix: data & template ReadLanguage major fix 8 mesi fa
template_test.go c8e489bd45 test: fixes to data_test & template_test 8 mesi fa

README.md

Overview

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:

  • The Go library allows you to easily parse data-serialization and template languages using a single interface (removing the need to learn a seperate library for each). This allows much better coherence and readability in your own software.
  • The binary was originally intended to showcase what can be done with the library. It works well as its own data-template executioner though.

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)!

Documentation

Go library documentation

Binary documentation

Supported Languages

Supported Data-Serialization Languages

Supported Template Language

Acknowledgments

All of these libraries do the hard work, dati just combines them together - so thanks to the authors. Also here for reference.

Authors

  • gearsix