split

package
v0.4.44 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

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

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

AppendText implements encoding.TextAppender.

func (Comma) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Comma) String

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

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

AppendText implements encoding.TextAppender.

func (Space) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Space) String

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