Help us shape the future of Go! Take the 2026 Go Developer Survey

xii

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: MIT Imports: 4 Imported by: 1

README

xii

My take on 12 Factor

Usage

AsBool

development, err := xii.AsBool("DEVELOPMENT", xii.BoolOpts{DefaultValue: false})
if err != nil {
	log.Fatal(err)
}
log.Printf("[xii] %-30s == %v\n", "DEVELOPMENT", development)

AsInt

port, err := xii.AsInt("PORT", xii.IntOpts{DefaultValue: 8080})
if err != nil {
	log.Fatal(err)
}
log.Printf("[xii] %-30s == %d\n", "PORT", port)

AsString

appRoot, err := xii.AsString("APPROOT", xii.StringOpts{DefaultValue: "./"})
if err != nil {
	log.Fatal(err)
}
log.Printf("[xii] %-30s == %q\n", "APPROOT", appRoot)

Documentation

Overview

Package xii contains helpers for 12 Factor.

Index

Constants

View Source
const (
	ExtraSpaces    = constError("must not contain leading or trailing spaces")
	InvalidBoolean = constError("must be either true or false")
	InvalidInteger = constError("must be a valid integer")
	IsBlank        = constError("must not be blank")
	NotExported    = constError("must be exported")
)

Errors used by the package.

Variables

This section is empty.

Functions

func AsBool

func AsBool(key string, opts BoolOpts) (bool, error)

AsBool retrieves a boolean value from the environment. Returns an error if the value is missing or invalid.

func AsInt

func AsInt(key string, opts IntOpts) (int, error)

AsInt is retrieves an integer value from the environment. Returns an error if the value is missing or invalid.

func AsString

func AsString(key string, opts StringOpts) (string, error)

AsString retrieves a string from the environment. Returns an error if the string is not set.

func GetBool added in v0.3.0

func GetBool(opts BoolOpts, keys ...string) (keyFound string, val bool, err error)

GetBool searches the environment for a list of keys. Returns the matching key's name and value. Returns an error if the key is not set or the value is invalid.

func GetInt added in v0.3.0

func GetInt(opts IntOpts, keys ...string) (keyFound string, val int, err error)

GetInt searches the environment for a list of keys. Returns the matching key's name and value. Returns an error if the key is not set or the value is invalid.

func GetString added in v0.3.0

func GetString(opts StringOpts, keys ...string) (keyFound string, val string, err error)

GetString searches the environment for a list of keys. Returns the matching key's name and value. Returns an error if the key is not set or the value is invalid.

func SearchEnv added in v0.3.0

func SearchEnv(keys ...string) (key, val string, err error)

SearchEnv searches the environment for a list of keys. Returns the matching key's name and value. Returns an error if the key is not set or the value is invalid.

Types

type BoolOpts

type BoolOpts struct {
	Required     bool
	DefaultKey   string
	DefaultValue bool
	Help         string // short help message if required and not found
}

BoolOpts specifies if a value is required or has a default value.

type IntOpts

type IntOpts struct {
	Required     bool
	DefaultKey   string
	DefaultValue int
	Help         string // short help message if required and not found
}

IntOpts is

type StringOpts

type StringOpts struct {
	Required     bool
	DefaultKey   string
	DefaultValue string
	Help         string // short help message if required and not found
}

StringOpts is

Jump to

Keyboard shortcuts

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