dati

data and template interface
git clone git://git.gearsix.net/dati
Log | Files | Refs | Atom | README | LICENSE

commit d41aa38337e414708ef2e48fccb184b6844aa9e7
parent 1260938241f998a1dc52409b5390dbd88f56d3b1
Author: gearsix <gearsix@tuta.io>
Date:   Sat, 27 Feb 2021 16:34:18 +0000

made template & data types public

Diffstat:
Msrc/data.go | 10+++++-----
Msrc/data_test.go | 6+++---
Msrc/suti.go | 2+-
Msrc/template.go | 4++--
4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/data.go b/src/data.go @@ -10,21 +10,21 @@ import ( "strings" ) -type data interface{} +type Data map[string]interface{} func getDataType(path string) string { return strings.TrimPrefix(filepath.Ext(path), ".") } // LoadDataFiles TODO -func LoadDataFiles(paths ...string) map[string]data { +func LoadDataFiles(paths ...string) map[string]Data { var err error var stat os.FileInfo - var d data + var d Data var dtype string var f *os.File - loaded := make(map[string]data) + loaded := make(map[string]Data) for _, path := range paths { if stat, err = os.Stat(path); err != nil { @@ -67,7 +67,7 @@ func LoadDataFiles(paths ...string) map[string]data { } // LoadData TODO -func LoadData(lang string, in io.Reader) (d data, e error) { +func LoadData(lang string, in io.Reader) (d Data, e error) { var fbuf []byte if fbuf, e = ioutil.ReadAll(in); e != nil { return diff --git a/src/data_test.go b/src/data_test.go @@ -9,13 +9,13 @@ import ( const goodJson = `{"example": 1}` const badJson = `{"example":2:]}}` -func writeTestFile(path string, data string) (e error) { +func writeTestFile(path string, Data string) (e error) { var f *os.File if f, e = os.Create(path); e != nil { return } - if _, e = f.WriteString(data); e != nil { + if _, e = f.WriteString(Data); e != nil { return } f.Close() @@ -26,7 +26,7 @@ func writeTestFile(path string, data string) (e error) { func TestLoadDataFiles(t *testing.T) { var e error var p []string - var d map[string]data + var d map[string]Data tdir := t.TempDir() p = append(p, tdir+"/good.json") diff --git a/src/suti.go b/src/suti.go @@ -30,7 +30,7 @@ func main() { _ = LoadDataFiles(options.DataPaths...) _ = LoadDataFiles(options.GlobalDataPaths...) - templates := make([]template, 0) + templates := make([]Template, 0) for _, r := range options.RootPaths { if t, e := LoadTemplateFile(r, options.PartialPaths...); e != nil { warn("unable to load templates (%s)", e) diff --git a/src/template.go b/src/template.go @@ -9,13 +9,13 @@ import ( hmpl "html/template" ) -type template interface{} +type Template interface{} func getTemplateType(path string) string { return strings.TrimPrefix(filepath.Ext(path), ".") } -func LoadTemplateFile(root string, partials ...string) (t template, e error) { +func LoadTemplateFile(root string, partials ...string) (t Template, e error) { if len(root) == 0 { e = fmt.Errorf("no root template specified") }