Documentation
¶
Overview ¶
Package splitter provides unmarshalers for Koanf config structs to convert strings to string slices using a particular delimiter.
Example ¶
package main
import (
"fmt"
"os"
"github.com/mattdowdell/sandbox/internal/drivers/config"
"github.com/mattdowdell/sandbox/internal/drivers/config/splitter"
)
type ExampleConfig struct {
Comma splitter.Comma `koanf:"foo"`
Space splitter.Space `koanf:"bar"`
}
func main() {
// arrange
os.Setenv("FOO", "foo,bar,baz")
os.Setenv("BAR", "foo bar baz")
loaded, _ := config.Load[ExampleConfig](&config.Options{})
fmt.Printf("comma: %s -> %#v\n", loaded.Comma.String(), loaded.Comma.Unwrap())
fmt.Printf("space: %s -> %#v\n", loaded.Space.String(), loaded.Space.Unwrap())
}
Output: comma: foo,bar,baz -> []string{"foo", "bar", "baz"} space: foo bar baz -> []string{"foo", "bar", "baz"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comma ¶
type Comma []string
Comma unmarshals a string into a slice of strings using a comma as a delimiter.
func (Comma) AppendText ¶ added in v0.3.40
AppendText implements encoding.TextAppender.
func (Comma) MarshalText ¶ added in v0.3.26
MarshalText implements encoding.TextMarshaler.
func (Comma) String ¶ added in v0.3.40
String implements fmt.Stringer.
func (*Comma) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Space ¶
type Space []string
Comma unmarshals a string into a slice of strings using a space as a delimiter.
func (Space) AppendText ¶ added in v0.3.40
AppendText implements encoding.TextAppender.
func (Space) MarshalText ¶ added in v0.3.26
MarshalText implements encoding.TextMarshaler.
func (Space) String ¶ added in v0.3.40
String implements fmt.Stringer.
func (*Space) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.