commit d4297c1310ac97fe39f3ff757b857cc379f47de5
parent b7d640207abe4608ba5e665a0a83fab107e7a8a2
Author: gearsix <gearsix@tuta.io>
Date: Fri, 3 Feb 2023 17:40:38 +0000
modified LoadData/LoadTemplate to use new Supported*Format
Diffstat:
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/data.go b/data.go
@@ -88,15 +88,13 @@ func LoadData(format string, in io.Reader, outp interface{}) error {
return nil
}
- switch IsSupportedDataLang(format) {
- case 0:
+ switch ReadDataFormat(format) {
+ case JSON:
e = json.Unmarshal(inbuf, outp)
- case 1:
+ case YAML:
e = yaml.Unmarshal(inbuf, outp)
- case 2:
+ case TOML:
e = toml.Unmarshal(inbuf, outp)
- case -1:
- fallthrough
default:
e = fmt.Errorf("'%s' is not a supported data language", format)
}
diff --git a/template.go b/template.go
@@ -253,18 +253,14 @@ func loadTemplateMst(rootName string, root io.Reader, partials map[string]io.Rea
// `lang`. `partials` should be a string of template, with syntax
// matching that of `lang`.
func LoadTemplate(lang string, rootName string, root io.Reader, partials map[string]io.Reader) (t Template, e error) {
- if IsSupportedTemplateLang(lang) == -1 {
- e = fmt.Errorf("invalid type '%s'", lang)
- return
- }
-
t.Name = rootName
- switch lang {
- case "tmpl":
+
+ switch SupportedTemplateFormat(lang) {
+ case TMPL:
t.T, e = loadTemplateTmpl(rootName, root, partials)
- case "hmpl":
+ case HMPL:
t.T, e = loadTemplateHmpl(rootName, root, partials)
- case "mst":
+ case MST:
t.T, e = loadTemplateMst(rootName, root, partials)
default:
e = fmt.Errorf("'%s' is not a supported template language", lang)