conf

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package conf defines utils to simplify configuration management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadAndUpdateFile

func LoadAndUpdateFile(path string, data interface{}) error

LoadAndUpdateFile reads the config fileat path and updates it, meaning that it adds new options, removes old ones, and update it by calling the Update method of data if it implements the interface Updater.

If no file is found at path, it is created and initialized with the default values.

An error is returned only if the config file cannot be written.

func LoadFile

func LoadFile(path string, data interface{}) error

LoadFile reads the file at path, parses its json content and fills the struct with the content of the file.

func LoadFiles

func LoadFiles(data interface{}, paths ...string) error

LoadFiles tries to load all the given paths in the given order.

If a path does not exist, it is ignored.

It returns an error only if the content of a file is invalid, i.e. it cannot be unmarshaled by json.

func SaveFile

func SaveFile(path string, data interface{}) error

SaveFile writes the given data serialized in JSON in the given path.

Types

type Updater

type Updater interface {
	Update()
}

Updater is the interface that can be implemented by config structs. If it is implemented, Update() is called by LoadAndUpdateFile(). It allows one to modify the data and persist those changes, for example to change default values.

Jump to

Keyboard shortcuts

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