summaryrefslogtreecommitdiff
path: root/pkg/values.go
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-11 23:19:13 +0100
committerJulien Dessaux2024-03-11 23:19:13 +0100
commitb40723b0b8d482140c5152b22233c1b62ec7838d (patch)
treeeb1a7995c4e2d2c17ce9a98807aabed0ca3b81f2 /pkg/values.go
parentfeat(gonf): bootstrapped the gonf cli (diff)
downloadgonf-b40723b0b8d482140c5152b22233c1b62ec7838d.tar.gz
gonf-b40723b0b8d482140c5152b22233c1b62ec7838d.tar.bz2
gonf-b40723b0b8d482140c5152b22233c1b62ec7838d.zip
chore(variables): support integer interpolation for all values
Diffstat (limited to '')
-rw-r--r--pkg/values.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/pkg/values.go b/pkg/values.go
index 509b6bf..bb82787 100644
--- a/pkg/values.go
+++ b/pkg/values.go
@@ -3,11 +3,13 @@ package gonf
import (
"fmt"
"log/slog"
+ "strconv"
"strings"
)
type Value interface {
Bytes() []byte
+ Int() (int, error)
String() string
}
@@ -53,6 +55,9 @@ type BytesValue struct {
func (b BytesValue) Bytes() []byte {
return b.value
}
+func (b BytesValue) Int() (int, error) {
+ return strconv.Atoi(string(b.value))
+}
func (b BytesValue) String() string {
return string(b.value[:])
}
@@ -65,8 +70,8 @@ type IntValue struct {
func (i IntValue) Bytes() []byte {
return []byte(string(i.value))
}
-func (i IntValue) Int() int {
- return i.value
+func (i IntValue) Int() (int, error) {
+ return i.value, nil
}
func (i IntValue) String() string {
return string(i.value)
@@ -83,6 +88,9 @@ func (s *StringsListValue) Append(v ...string) {
func (s StringsListValue) Bytes() []byte {
return []byte(s.String())
}
+func (s StringsListValue) Int() (int, error) {
+ return len(s.value), nil
+}
func (s StringsListValue) String() string {
return strings.Join(s.value, "\n")
}
@@ -95,6 +103,9 @@ type StringValue struct {
func (s StringValue) Bytes() []byte {
return []byte(s.value)
}
+func (s StringValue) Int() (int, error) {
+ return strconv.Atoi(s.value)
+}
func (s StringValue) String() string {
return s.value
}