summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gonf/values.go17
-rw-r--r--gonf/variables.go15
2 files changed, 26 insertions, 6 deletions
diff --git a/gonf/values.go b/gonf/values.go
index 6e37c99..b77e703 100644
--- a/gonf/values.go
+++ b/gonf/values.go
@@ -1,6 +1,9 @@
package gonf
-import "log/slog"
+import (
+ "fmt"
+ "log/slog"
+)
type Value interface {
Bytes() []byte
@@ -14,8 +17,11 @@ func interfaceToValue(v any) Value {
if vv, ok := v.([]byte); ok {
return &BytesValue{vv}
}
- slog.Error("interfaceToTemplateValue", "value", v, "error", "Not Implemented")
- return nil
+ if vv, ok := v.(*VariablePromise); ok {
+ return vv
+ }
+ slog.Error("interfaceToValue", "value", v, "error", "Not Implemented")
+ panic(fmt.Sprintf("interfaceToValue cannot take type %T as argument. Value was %#v.", v, v))
}
func interfaceToTemplateValue(v any) Value {
@@ -25,8 +31,11 @@ func interfaceToTemplateValue(v any) Value {
if vv, ok := v.([]byte); ok {
return &TemplateValue{data: string(vv)}
}
+ if vv, ok := v.(*VariablePromise); ok {
+ return vv
+ }
slog.Error("interfaceToTemplateValue", "value", v, "error", "Not Implemented")
- return nil
+ panic(fmt.Sprintf("interfaceToTemplateValue cannot take type %T as argument. Value was %#v.", v, v))
}
// ----- BytesValue -----------------------------------------------------------------
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))
}
}