chore(repo): renamed gonf subfolder to something more traditional in go land

This commit is contained in:
Julien Dessaux 2024-03-07 00:54:35 +01:00
parent 3b9af43738
commit 560becfd32
Signed by: adyxax
GPG key ID: F92E51B86E07177E
14 changed files with 2 additions and 2 deletions

104
pkg/values.go Normal file
View file

@ -0,0 +1,104 @@
package gonf
import (
"fmt"
"log/slog"
"strings"
)
type Value interface {
Bytes() []byte
String() string
}
func interfaceToValue(v any) Value {
if vv, ok := v.([]byte); ok {
return &BytesValue{vv}
}
if vv, ok := v.(int); ok {
return &IntValue{vv}
}
if vv, ok := v.(string); ok {
return &StringValue{vv}
}
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 {
if vv, ok := v.([]byte); ok {
return &TemplateValue{data: string(vv)}
}
if vv, ok := v.(int); ok {
return &IntValue{vv}
}
if vv, ok := v.(string); ok {
return &TemplateValue{data: vv}
}
if vv, ok := v.(*VariablePromise); ok {
return vv
}
slog.Error("interfaceToTemplateValue", "value", v, "error", "Not Implemented")
panic(fmt.Sprintf("interfaceToTemplateValue cannot take type %T as argument. Value was %#v.", v, v))
}
// ----- BytesValue ------------------------------------------------------------
type BytesValue struct {
value []byte
}
func (b BytesValue) Bytes() []byte {
return b.value
}
func (b BytesValue) String() string {
return string(b.value[:])
}
// ----- IntValue --------------------------------------------------------------
type IntValue struct {
value int
}
func (i IntValue) Bytes() []byte {
return []byte(string(i.value))
}
func (i IntValue) Int() int {
return i.value
}
func (i IntValue) String() string {
return string(i.value)
}
// ----- StringsListValue ------------------------------------------------------
type StringsListValue struct {
value []string
}
func (s *StringsListValue) Append(v ...string) {
s.value = append(s.value, v...)
}
func (s StringsListValue) Bytes() []byte {
return []byte(s.String())
}
func (s StringsListValue) String() string {
return strings.Join(s.value, "\n")
}
// ----- StringValue -----------------------------------------------------------
type StringValue struct {
value string
}
func (s StringValue) Bytes() []byte {
return []byte(s.value)
}
func (s StringValue) String() string {
return s.value
}
// TODO maps
// TODO what else?