summaryrefslogtreecommitdiff
path: root/pkg/values.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/values.go')
-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
}