diff options
author | Julien Dessaux | 2024-02-17 22:41:14 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-07 01:00:49 +0100 |
commit | 784ba6bc86b70859af19ab03e0a145c4e40c85d9 (patch) | |
tree | e518b21006015be0998e922899458154194918a4 | |
parent | feat(services): implemented service promises (diff) | |
download | gonf-784ba6bc86b70859af19ab03e0a145c4e40c85d9.tar.gz gonf-784ba6bc86b70859af19ab03e0a145c4e40c85d9.tar.bz2 gonf-784ba6bc86b70859af19ab03e0a145c4e40c85d9.zip |
feat(variables): implemented a list of strings value type for template variables
Diffstat (limited to '')
-rw-r--r-- | gonf/values.go | 18 | ||||
-rw-r--r-- | gonf/variables.go | 16 |
2 files changed, 32 insertions, 2 deletions
diff --git a/gonf/values.go b/gonf/values.go index 56743e2..509b6bf 100644 --- a/gonf/values.go +++ b/gonf/values.go @@ -3,6 +3,7 @@ package gonf import ( "fmt" "log/slog" + "strings" ) type Value interface { @@ -71,6 +72,21 @@ 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 @@ -83,8 +99,6 @@ func (s StringValue) String() string { return s.value } -// TODO lists - // TODO maps // TODO what else? diff --git a/gonf/variables.go b/gonf/variables.go index 17f8eb9..ed09d31 100644 --- a/gonf/variables.go +++ b/gonf/variables.go @@ -14,6 +14,22 @@ func init() { } // ----- Public ---------------------------------------------------------------- +func AppendVariable(name string, values ...string) *VariablePromise { + if v, ok := variables[name]; ok { + if l, ok := v.value.(*StringsListValue); ok { + l.Append(values...) + } + return v + } + v := &VariablePromise{ + isDefault: false, + name: name, + value: &StringsListValue{values}, + } + variables[name] = v + return v +} + func Default(name string, value string) *VariablePromise { if v, ok := variables[name]; ok { if !v.isDefault { |