config

package module
Version: v0.0.0-...-121804b Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: MIT Imports: 8 Imported by: 3

README

config

Build Status Go Report Card

A small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP.

Example

func main() {
	c := config.New("config.json")

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var value string
		c.Get("value", &value)
		fmt.Fprintf(w, "Value: %s", value)
	})

	http.ListenAndServe(":3000", nil)
}

Reload config on SIGHUP

API

func New(file string) *Config

Constructor that initializes a Config object and sets up the SIGHUP watcher.

func (config *Config) Get(key string, v interface{}) error

Takes the path to a JSON file, the name of the configuration option, and a pointer to the variable where the config value will be stored. v can be a pointer to a string, bool, or float64.

func (config *Config) Reload()

Reloads the config. Happens automatically on SIGHUP.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config represents a configuration file.

func New

func New(filename string) *Config

New creates a new Config object.

func (*Config) Get

func (config *Config) Get(key string, v interface{}) error

Get retreives a Config option into a passed in pointer or returns an error.

func (*Config) Reload

func (config *Config) Reload() error

Reload clears the config cache.

Source Files

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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