chore(variables): support integer interpolation for all values

This commit is contained in:
Julien Dessaux 2024-03-11 23:19:13 +01:00
parent acbccb0a93
commit b40723b0b8
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 26 additions and 16 deletions

View file

@ -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
}