goconf

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2017 License: MIT Imports: 7 Imported by: 0

README

goconf

GoDoc Build Status Coverage Status Go Report Card

Combine yaml and environment config

Features

Installation

go get gopkg.in/plimble/goconf.v1

Env format

type SampleA struct {
	A               string // PREFIX_A
	CamelCase       bool // PREFIX_CAMELCASE
	ManualOverride1 string `envconfig:"manual_override_1"` // PREFIX_MANUAL_OVERRIDE_1
	SplitWord1      string `split_words:"true"` // SPLIT_WORD1
	ID              string // PREFIX_ID
	DefaultValue    string `envconfig:"DEFAULT_VALUE"` // PREFIX_DEFAULT_VALUE
}

Yaml format

type SampleA struct {
	A               string `json:"abc"` // abc
	CamelCase       bool `yaml:"cc"` // cc
	ManualOverride1 string // manualoverride1
	SplitWord1      string // splitword1
	ID              string // id
	DefaultValue    string // defaultvalue
}

Example


type Sample struct {
  Value string
}

var bytes = `
value: v1
`

sample := &Sample{}
// Parse Order: yaml bytes -> yaml file -> env
err = goconf.Parse(sample,
    WithEnv("prefix"),
    WithYamlFromBytes(bytes),
    WithYaml("path.yml"),
)

Watch Config


goconf.WatchYamlFile("path.yml", sample, func() error {
  fmt.Println("event on chane")
  return nil
})

// or ignore event
goconf.WatchYamlFile("path.yml", sample, nil)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(v interface{}, options ...Option) error

func ReloadYaml

func ReloadYaml(path string, v interface{}) error

func ReloadYamlFromBytes

func ReloadYamlFromBytes(bytes []byte, v interface{}) error

func WatchYamlFile

func WatchYamlFile(path string, v interface{}, onChange OnChange)

Types

type OnChange

type OnChange func() error

type Option

type Option func(o *opts)

func WithEnv

func WithEnv(prefix string) Option

func WithYaml

func WithYaml(path string) Option

func WithYamlFromBytes

func WithYamlFromBytes(yaml []byte) Option

Jump to

Keyboard shortcuts

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