summaryrefslogtreecommitdiff
path: root/tmpl
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2025-03-09 20:14:46 -0400
committerGitHub <noreply@github.com>2025-03-10 00:14:46 +0000
commitbfa6b9dcef7592e6dd8225aaa0d0ab5aef5b3f84 (patch)
tree7e844defee92dc3af320df20baa6f9b421d4a4c9 /tmpl
parent7942441e61471f578a57910b3aa93636f5a0310d (diff)
chore(refactoring): Refactor/modernizations (#2345)
chore(refactoring): Refactor with modernization refactorings * range over int * replace interface{} with any * replace common map operations with maps.Copy/maps.Clone * simplifying loops with slices.Contains/ContainsFunc * modernize benchmarks with b.Loop * modernize tests with t.Context * use fmt.Appendf * range over strings.SplitSeq * use new stdlib crypto/pbkdf2 package --------- Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'tmpl')
-rw-r--r--tmpl/tmpl.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/tmpl/tmpl.go b/tmpl/tmpl.go
index c4f6aefd..d1e5c75b 100644
--- a/tmpl/tmpl.go
+++ b/tmpl/tmpl.go
@@ -11,12 +11,12 @@ import (
// Template -
type Template struct {
root *template.Template
- defaultCtx interface{}
+ defaultCtx any
path string
}
// New -
-func New(root *template.Template, tctx interface{}, path string) *Template {
+func New(root *template.Template, tctx any, path string) *Template {
return &Template{root, tctx, path}
}
@@ -43,7 +43,7 @@ func (t *Template) PathDir() (string, error) {
// {{ tmpl.Inline "name" "inline template" }} - named template with default context
// {{ tmpl.Inline "inline template" $foo }} - unnamed (single-use) template with given context
// {{ tmpl.Inline "name" "inline template" $foo }} - named template with given context
-func (t *Template) Inline(args ...interface{}) (string, error) {
+func (t *Template) Inline(args ...any) (string, error) {
name, in, ctx, err := t.parseArgs(args...)
if err != nil {
return "", err
@@ -51,7 +51,7 @@ func (t *Template) Inline(args ...interface{}) (string, error) {
return t.inline(name, in, ctx)
}
-func (t *Template) inline(name, in string, ctx interface{}) (string, error) {
+func (t *Template) inline(name, in string, ctx any) (string, error) {
tmpl, err := t.root.New(name).Parse(in)
if err != nil {
return "", err
@@ -60,7 +60,7 @@ func (t *Template) inline(name, in string, ctx interface{}) (string, error) {
}
// Exec - execute (render) a template - this is the built-in `template` action, except with output...
-func (t *Template) Exec(name string, tmplcontext ...interface{}) (string, error) {
+func (t *Template) Exec(name string, tmplcontext ...any) (string, error) {
ctx := t.defaultCtx
if len(tmplcontext) == 1 {
ctx = tmplcontext[0]
@@ -72,7 +72,7 @@ func (t *Template) Exec(name string, tmplcontext ...interface{}) (string, error)
return render(tmpl, ctx)
}
-func render(tmpl *template.Template, ctx interface{}) (string, error) {
+func render(tmpl *template.Template, ctx any) (string, error) {
out := &bytes.Buffer{}
err := tmpl.Execute(out, ctx)
if err != nil {
@@ -81,7 +81,7 @@ func render(tmpl *template.Template, ctx interface{}) (string, error) {
return out.String(), nil
}
-func (t *Template) parseArgs(args ...interface{}) (name, in string, ctx interface{}, err error) {
+func (t *Template) parseArgs(args ...any) (name, in string, ctx any, err error) {
name = "<inline>"
ctx = t.defaultCtx
@@ -97,7 +97,7 @@ func (t *Template) parseArgs(args ...interface{}) (name, in string, ctx interfac
case 1:
in = first
case 2:
- // this can either be (name string, in string) or (in string, ctx interface{})
+ // this can either be (name string, in string) or (in string, ctx any)
switch second := args[1].(type) {
case string:
name = first