gonfigure

package module
v0.0.0-...-2ef5314 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2015 License: MIT Imports: 2 Imported by: 10

README

GO-N-FIGURE

GoDoc

Minimalistic configuration helper for your Go projects.

Example

var portProperty   = gonfigure.NewEnvProperty("PORT", "8080")
var domainProperty = gonfigure.NewRequiredEnvProperty("DOMAIN")

type Config struct {
  Port   string
  Domain string
}

func NewConfig() Config {
  return Config{
    Port:   portProperty.Value(),
    // If the $DOMAIN env variable is not set, this call will panic
    Domain: domainProperty.Value(),
  }
}

Documentation

Overview

Package gonfigure helps creating configuration structs.

The intended usage would be a simple struct that calls Value() on a fields initialization. E.g.

var portProperty   = gonfigure.NewEnvProperty("PORT", "8080")
var domainProperty = gonfigure.NewRequiredEnvProperty("DOMAIN")

type Config struct {
	Port   string
	Domain string
}

func NewConfig() Config {
	return Config{
		Port:   portProperty.Value(),
		// If the $DOMAIN env variable is not set, this call will panic
		Domain: domainProperty.Value(),
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Property

type Property interface {
	Value() string
}

Property can be used to fetch default values for configuration properties.

func NewEnvProperty

func NewEnvProperty(envVariableName string, fallbackValue string) Property

NewEnvProperty returns a Property that gets its value from the specified environment variable. If the environment vatiable is not set the fallback value will be used instead

func NewRequiredEnvProperty

func NewRequiredEnvProperty(envVariableName string) Property

NewRequiredEnvProperty returns a Property that gets its value from the specified environment variable. Panics if the variable is not set.

Jump to

Keyboard shortcuts

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