data and template interface

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

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