filehandler

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileHandler

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

FileHandler implements ConfigHandler using local files. It supports JSON, YAML, and TOML formats.

func New

func New(opts ...Option) (*FileHandler, error)

New creates a new FileHandler with the given options.

func (*FileHandler) Load

func (h *FileHandler) Load(data any) error

Load reads the config file into data.

func (*FileHandler) Save

func (h *FileHandler) Save(data any) error

Save writes data to the config file.

type FileIO

type FileIO interface {
	Write(data any, file string) error
	Read(data any, file string) error
	GetExtension() string
}

FileIO is the interface for reading and writing config data to files.

func BuildFileIO

func BuildFileIO(o *Optional) FileIO

BuildFileIO returns a FileIO implementation for the resolved file type.

type FileType

type FileType string

FileType represents a supported configuration file format.

const (
	JSON    FileType = "json"
	YAML    FileType = "yaml"
	TOML    FileType = "toml"
	DYNAMIC FileType = "dynamic"
)

type Json

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

func (*Json) GetExtension

func (j *Json) GetExtension() string

func (*Json) Read

func (j *Json) Read(data any, file string) error

func (*Json) Write

func (j *Json) Write(data any, file string) error

type Option

type Option func(f *Optional)

Option is a functional option for configuring a FileHandler.

func WithName

func WithName(n string) Option

WithName sets a custom config file name. Default is "app".

func WithPath

func WithPath(p string) Option

WithPath sets a custom config file directory. Default is the working directory.

func WithType

func WithType(t FileType) Option

WithType sets the config file format. Supported: filehandler.DYNAMIC (default), filehandler.JSON, filehandler.YAML, filehandler.TOML.

type Optional

type Optional struct {
	Name string
	Path string
	Type FileType
}

Optional holds configuration for creating a FileHandler.

type Toml

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

func (*Toml) GetExtension

func (t *Toml) GetExtension() string

func (*Toml) Read

func (t *Toml) Read(data any, file string) error

func (*Toml) Write

func (t *Toml) Write(data any, file string) error

type Yaml

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

func (*Yaml) GetExtension

func (y *Yaml) GetExtension() string

func (*Yaml) Read

func (y *Yaml) Read(data any, file string) error

func (*Yaml) Write

func (y *Yaml) Write(data any, file string) error

Jump to

Keyboard shortcuts

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