From b40723b0b8d482140c5152b22233c1b62ec7838d Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 11 Mar 2024 23:19:13 +0100 Subject: chore(variables): support integer interpolation for all values --- pkg/values.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'pkg/values.go') 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 } -- cgit v1.2.3