file

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package file implements provider.Provider for local file-based configuration. It watches a file for changes using fsnotify (fsevents on macOS, inotify on Linux) and re-reads the file on every change, calling compare-and-swap on dynamic values. Supports JSON and YAML flat key:value formats (not nested).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path is the path to the configuration file.
	Path string

	// Format specifies how to parse the file. Default: FormatAuto.
	Format Format
}

Config holds file-specific configuration.

type Format

type Format int

Format specifies the file format.

const (
	// FormatJSON parses the file as flat JSON key:value pairs.
	FormatJSON Format = iota
	// FormatYAML parses the file as flat YAML key:value pairs.
	FormatYAML
	// FormatAuto detects the format from the file extension (.json, .yaml, .yml).
	FormatAuto
)

type Provider

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

Provider implements the poya Provider interface using file watching.

func New

func New(cfg Config) (*Provider, error)

New creates a new file provider that watches the given file.

func (*Provider) Close

func (p *Provider) Close() error

Close releases file provider resources.

func (*Provider) Get

func (p *Provider) Get(_ context.Context, key string) (string, error)

Get retrieves the current value for a key from the file.

func (*Provider) Watch

func (p *Provider) Watch(ctx context.Context, keys []string, onChange func(key string, value string)) error

Watch monitors the file for changes using fsnotify. On each change, it re-reads the file and calls onChange for any key whose value changed.

Jump to

Keyboard shortcuts

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