toml

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package toml loads and writes TOML configuration using the shared codec pattern (sources, deep merge, key normalization, struct decode via mapstructure).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

Codec loads TOML from multiple sources.

func New

func New(opts ...Option) *Codec

New creates a TOML codec.

func (*Codec) Map

func (c *Codec) Map(ctx context.Context) (map[string]any, error)

Map merges all TOML sources into one map.

func (*Codec) Marshal

func (c *Codec) Marshal(src any) ([]byte, error)

Marshal encodes src to TOML bytes (struct or map[string]any).

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(dst any) error

Unmarshal decodes using context.Background.

func (*Codec) UnmarshalContext

func (c *Codec) UnmarshalContext(ctx context.Context, dst any) error

UnmarshalContext decodes merged TOML into dst.

func (*Codec) WriteTo

func (c *Codec) WriteTo(w io.Writer, src any) (int64, error)

WriteTo writes TOML to w.

type Option

type Option func(*Codec)

Option configures a Codec.

func WithBytes

func WithBytes(b []byte) Option

WithBytes appends TOML from bytes.

func WithDecodeHook

func WithDecodeHook(h mapstructure.DecodeHookFunc) Option

WithDecodeHook appends a decode hook.

func WithFile

func WithFile(path string) Option

WithFile appends a TOML file path.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the client for subsequent WithURL sources.

func WithHTTPHeader

func WithHTTPHeader(k, v string) Option

WithHTTPHeader adds a header for subsequent WithURL sources.

func WithKeyNormalizer

func WithKeyNormalizer(n keymap.Normalizer) Option

WithKeyNormalizer sets key normalizer after merge (nil disables).

func WithReader

func WithReader(r io.Reader) Option

WithReader appends TOML from r.

func WithSliceMerge

func WithSliceMerge(s merge.SliceStrategy) Option

WithSliceMerge sets slice merge strategy across sources.

func WithTagName

func WithTagName(name string) Option

WithTagName sets mapstructure tag name.

func WithTrim

func WithTrim(enable bool) Option

WithTrim toggles string trim on struct decode.

func WithURL

func WithURL(raw string) Option

WithURL appends TOML from an HTTP(S) URL.

func WithWeaklyTyped

func WithWeaklyTyped(enable bool) Option

WithWeaklyTyped toggles weak typing for struct decode.

Jump to

Keyboard shortcuts

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