splitter

package
v0.3.85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 3 Imported by: 0

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

func (c Comma) AppendText(b []byte) ([]byte, error)

AppendText implements encoding.TextAppender.

func (Comma) MarshalText added in v0.3.26

func (c Comma) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Comma) String added in v0.3.40

func (c Comma) String() string

String implements fmt.Stringer.

func (*Comma) UnmarshalText

func (c *Comma) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Comma) Unwrap

func (c Comma) Unwrap() []string

Unwrap returns the underlying string slice after unmarshaling.

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

func (s Space) AppendText(b []byte) ([]byte, error)

AppendText implements encoding.TextAppender.

func (Space) MarshalText added in v0.3.26

func (s Space) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Space) String added in v0.3.40

func (s Space) String() string

String implements fmt.Stringer.

func (*Space) UnmarshalText

func (s *Space) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Space) Unwrap

func (s Space) Unwrap() []string

Unwrap returns the underlying string slice after unmarshaling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL