Documentation
¶
Overview ¶
Package split 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/split"
)
type ExampleConfig struct {
Comma split.Comma `koanf:"foo"`
Space split.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 ¶
AppendText implements encoding.TextAppender.
func (Comma) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
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 ¶
AppendText implements encoding.TextAppender.
func (Space) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Space) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
Click to show internal directories.
Click to hide internal directories.