config

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config handles config files, -config, and env vars at startup.

Index

Constants

View Source
const (
	DEFAULT_CONFIG_FILES = "/etc/spinc/spinc.yaml,~/.spinc.yaml"
	DEFAULT_ADDR         = "http://127.0.0.1:32308"
	DEFAULT_TIMEOUT      = 5000 // 5s
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Cmd  string   `arg:"positional"`
	Args []string `arg:"positional"`
}

Command represents a command (start, stop, etc.) and its values.

type CommandLine

type CommandLine struct {
	Options
	Command
}

CommandLine represents options (--addr, etc.) and commands (start, etc.). The caller is expected to copy and use the embedded structs separately, like:

var o config.Options = cmdLine.Options
var c config.Command = cmdLine.Command

Some commands and options are mutually exclusive, like --ping and --version. Others can be used together, like --addr and --timeout with any command.

func ParseCommandLine

func ParseCommandLine(def Options) CommandLine

ParseCommandLine parses the command line and env vars. Command line options override env vars. Default options are used unless overridden by env vars or command line options. Defaults are usually parsed from config files.

type Options

type Options struct {
	Addr    string `arg:"env:SPINC_ADDR" yaml:"addr"`
	Config  string `arg:"env:SPINC_CONFIG"`
	Debug   bool   `arg:"env:SPINC_DEBUG" yaml:"debug"`
	Env     string `arg:"env:SPINC_ENV" yaml:"env"`
	Help    bool
	Timeout uint `arg:"env:SPINC_TIMEOUT" yaml:"timeout"`
	Version bool
}

Options represents typical command line options: --addr, --config, etc.

func ParseConfigFiles

func ParseConfigFiles(files string, debug bool) Options

Jump to

Keyboard shortcuts

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