comconf

package module
v0.0.0-...-b568010 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 4 Imported by: 0

README

comconf

Opinionated, simple configuration management.

Documentation

Overview

comconf is my very opinionated configuration management

Index

Constants

View Source
const MainFile = "config.toml"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfManager

type ConfManager[T any] struct {
	Configuration T
	// contains filtered or unexported fields
}

The ConfManager handles an existing configuration data type.

func New

func New[T any](namespace string, defaults T) (*ConfManager[T], error)

New attempts to load a configuration file based on its namespace.

If the configuration file is empty, the defaults are used.

func (*ConfManager[T]) Directory

func (c *ConfManager[T]) Directory() (string, error)

Directory returns the path to the configurable's configuration directory.

The configuration directory is determined by os.UserConfigDir() and the configurable's name.

func (*ConfManager[T]) Load

func (c *ConfManager[T]) Load(defaults T) error

Load attempts to load the existing configuration file.

If the file is empty, the defaults are used.

func (*ConfManager[T]) OpenFile

func (c *ConfManager[T]) OpenFile(name string) (*os.File, error)

OpenFile returns a file handler to the file specified by name, located inside the configurable's directory.

If the directory or its parents do not exist, they will be created. If a file does not exist, it will be opened for writing.

func (*ConfManager[T]) Save

func (c *ConfManager[T]) Save() error

Save writes the configuration to disk as a TOML file.

func (*ConfManager[T]) SaveExit

func (c *ConfManager[T]) SaveExit()

SaveExit saves the configuration file.

If an error occurs, log.Fatal is called, otherwise os.Exit(0)

Jump to

Keyboard shortcuts

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