summaryrefslogtreecommitdiff
path: root/gonf/variables.go
diff options
context:
space:
mode:
authorJulien Dessaux2024-02-13 08:09:43 +0100
committerJulien Dessaux2024-03-07 00:59:46 +0100
commite4eccafed79d739762ea791d97d5a2c9da191eb9 (patch)
treeadba995f4695038253f1aafcbfae94b7119b1ec5 /gonf/variables.go
parentchore(templates): cleaned the templating api (diff)
downloadgonf-e4eccafed79d739762ea791d97d5a2c9da191eb9.tar.gz
gonf-e4eccafed79d739762ea791d97d5a2c9da191eb9.tar.bz2
gonf-e4eccafed79d739762ea791d97d5a2c9da191eb9.zip
feat(variables): allow variable promises to be used directly where template values are
Diffstat (limited to '')
-rw-r--r--gonf/variables.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/gonf/variables.go b/gonf/variables.go
index 2c1247c..17f8eb9 100644
--- a/gonf/variables.go
+++ b/gonf/variables.go
@@ -1,6 +1,9 @@
package gonf
-import "log/slog"
+import (
+ "fmt"
+ "log/slog"
+)
// ----- Globals ---------------------------------------------------------------
var variables map[string]*VariablePromise
@@ -47,12 +50,20 @@ type VariablePromise struct {
value Value
}
+// We want VariablePromise to satisfy the Value interface
+func (s VariablePromise) Bytes() []byte {
+ return s.value.Bytes()
+}
+func (s VariablePromise) String() string {
+ return s.value.String()
+}
+
// ----- Internal --------------------------------------------------------------
func getVariable(name string) string {
if v, ok := variables[name]; ok {
return v.value.String()
} else {
slog.Error("undefined variable or default", "name", name)
- return ""
+ panic(fmt.Sprintf("undefined variable or default %s", name))
}
}