tote

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2019 License: MIT Imports: 12 Imported by: 1

README

Tote

Build Status GoDoc

Description

A configuration fetching framework to take some of the pain out of reading config files in go.

Usage

By default tote reads from a file defined by the environment variable TOTE_CONFIG_FILE.

In this example let's say you've exported TOTE_CONFIG_FILE=./config.yaml and the contents of ./config.yaml is as follows:

database:
    port: 1234
appname: my-test-app

* Refer to the go-yaml/yaml for more information about the mapping between your struct and the yaml file.

package main

import (
    "fmt"

    "github.com/daihasso/tote"
)

type MyConfig struct {
    Database struct {
        Port int
    }
    AppName string
}

func main() {
    myConfig := MyConfig{}
    tote.ReadConfig(&myConfig)

    fmt.Println("Database port:", myConfig.Database.Port)
    fmt.Println("App name:", myConfig.Name)
}
Database port: 1234
App name: my-test-app

Defining Multiple Search Paths

You can define any number of potential search paths (with mixed backends) via the AddPaths option like so:

tote.ReadConfig(
    &myConfig, tote.AddPaths("config.yaml", "s3://my-bucket/config.yaml"),
)

The provided paths will be searched in order with the first found taking precedence. (If the environment variable TOTE_CONFIG_FILE is specified it will always take precedence over the other defined paths)

S3 Compatibility

Usage

By default tote is only configured to check on disk for files but it is built to support S3 as well. If you'd like to search for a config in S3 as well simply use the WithS3Client option like so:

    tote.ReadConfig(
        myConfig, tote.WithS3Client(myS3Client),
    )
Disabling S3

If you're not using S3 and are concerned by the added bulk of the s3 libraries (I don't blame you, it's YUUUGE) just build your binary with the build flag nos3 like so:

go build . -tags nos3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadConfig

func ReadConfig(config interface{}, allOptions ...Option) error

ReadConfig reads in yaml data at provided paths into the provided interface.

Types

type Option

type Option func(*options)

Option is an option for reading a config.

func AddEmbedded

func AddEmbedded(key string, in interface{}) Option

AddEmbedded adds a struct (in) that's embedded under some key.

func AddPaths

func AddPaths(paths ...string) Option

AddPaths adds the provided paths to the search paths which will be checked in the order provided.

func OverrideEnvVarPrefix

func OverrideEnvVarPrefix(prefix string) Option

OverrideEnvVarPrefix overrides the defaultEnvironmentPrefix used in finding environment variables that override config values.

func WithPathReader

func WithPathReader(pathReader *peechee.PathReader) Option

WithPathReader lets you override the internal PathReader with one you've defined seperately if needed.

func WithS3Client

func WithS3Client(s3Client s3iface.S3API) Option

WithS3Client adds an S3Client to the PathReader so that it can correctly grab data for S3 paths.

Jump to

Keyboard shortcuts

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