config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config manages user preferences stored as JSON5/JSON files.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("invalid config value")

ErrInvalidValue indicates a config value that fails validation.

View Source
var ErrUnknownKey = errors.New("unknown config key")

ErrUnknownKey indicates an invalid config key.

Functions

func CachePath

func CachePath() (string, error)

CachePath returns the full path to the template cache file.

func Dir

func Dir() (string, error)

Dir returns the memelink config directory. Respects XDG_CONFIG_HOME; defaults to $HOME/.config/memelink.

func KnownKeys

func KnownKeys() []string

KnownKeys returns a sorted list of valid config key names.

func Path

func Path() (string, error)

Path returns the full path to the config file.

func Save

func Save(path string, cfg *Config) error

Save writes config as pretty-printed JSON atomically.

func WithConfig

func WithConfig(ctx context.Context, cfg *Config) context.Context

WithConfig stores a Config in the context.

Types

type Config

type Config struct {
	DefaultFormat string `json:"default_format,omitempty"`
	DefaultFont   string `json:"default_font,omitempty"`
	DefaultLayout string `json:"default_layout,omitempty"`
	Safe          *bool  `json:"safe,omitempty"`
	AutoCopy      *bool  `json:"auto_copy,omitempty"`
	AutoOpen      *bool  `json:"auto_open,omitempty"`
	Preview       *bool  `json:"preview,omitempty"`
	CacheTTL      string `json:"cache_ttl,omitempty"`
}

Config holds user preferences.

func FromContext

func FromContext(ctx context.Context) *Config

FromContext retrieves the Config from the context.

func Load

func Load(path string) (*Config, error)

Load reads config from the JSON5 file at path. Returns an empty Config if the file does not exist.

func (*Config) CacheTTLDuration

func (cfg *Config) CacheTTLDuration() time.Duration

CacheTTLDuration parses CacheTTL as a time.Duration. Returns 24h on empty or invalid values.

func (*Config) Get

func (cfg *Config) Get(key string) (string, bool)

Get returns the string value for a config key and whether it is set.

func (*Config) Set

func (cfg *Config) Set(key, value string) error

Set sets a config key to a value after validation.

func (*Config) Unset

func (cfg *Config) Unset(key string) error

Unset removes a config key (resets to zero/nil).

Jump to

Keyboard shortcuts

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