config

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHost is the default host of the GitHub
	DefaultHost     = "github.com"
	DefaultLogLevel = "warn"
)

Variables

View Source
var (
	ErrEmptyValue        = errors.New("empty value")
	ErrInvalidOptionName = errors.New("invalid option name")
)
View Source
var (
	TrueOption      = BoolOption("yes")
	FalseOption     = BoolOption("no")
	EmptyBoolOption = BoolOption("")
)

Functions

func OptionNames

func OptionNames() []string

func SaveConfig

func SaveConfig(w io.Writer, config *Config) error

Types

type BoolOption

type BoolOption string

func (BoolOption) Bool

func (c BoolOption) Bool() bool

func (*BoolOption) Decode

func (c *BoolOption) Decode(repl string) error

Decode implements the interface `envdecode.Decoder`

func (BoolOption) MarshalYAML

func (c BoolOption) MarshalYAML() (interface{}, error)

MarshalYAML implements the interface `yaml.Marshaler`

func (BoolOption) String

func (c BoolOption) String() string

func (*BoolOption) UnmarshalYAML

func (c *BoolOption) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the interface `yaml.Unmarshaler`

type Config

type Config struct {
	context.Context `yaml:"-"`
	Log             LogConfig      `yaml:"log,omitempty"`
	VRoot           PathListOption `yaml:"root,omitempty" env:"GOGH_ROOT"`
	GitHub          GitHubConfig   `yaml:"github,omitempty"`
}

Config holds configuration file values.

func DefaultConfig

func DefaultConfig() *Config

func GetEnvarConfig

func GetEnvarConfig() (config *Config, err error)

func LoadConfig

func LoadConfig(r io.Reader) (config *Config, err error)

func LoadKeyring added in v1.3.3

func LoadKeyring() *Config

func MergeConfig

func MergeConfig(base *Config, override ...*Config) *Config

func (*Config) GitHubHost

func (c *Config) GitHubHost() string

func (*Config) GitHubToken

func (c *Config) GitHubToken() string

func (*Config) GitHubUser

func (c *Config) GitHubUser() string

func (*Config) LogDate

func (c *Config) LogDate() bool

func (*Config) LogFlags

func (c *Config) LogFlags() int

func (*Config) LogLevel

func (c *Config) LogLevel() string

func (*Config) LogLongFile

func (c *Config) LogLongFile() bool

func (*Config) LogMicroSeconds

func (c *Config) LogMicroSeconds() bool

func (*Config) LogShortFile

func (c *Config) LogShortFile() bool

func (*Config) LogTime

func (c *Config) LogTime() bool

func (*Config) LogUTC

func (c *Config) LogUTC() bool

func (*Config) PrimaryRoot

func (c *Config) PrimaryRoot() string

func (*Config) Root

func (c *Config) Root() []string

func (*Config) Stderr

func (c *Config) Stderr() io.Writer

func (*Config) Stdin

func (c *Config) Stdin() io.Reader

func (*Config) Stdout

func (c *Config) Stdout() io.Writer

type GitHubConfig

type GitHubConfig struct {
	Token string `yaml:"-" env:"GOGH_GITHUB_TOKEN"`
	User  string `yaml:"user,omitempty" env:"GOGH_GITHUB_USER"`
	Host  string `yaml:"host,omitempty" env:"GOGH_GITHUB_HOST"`
}

type LogConfig

type LogConfig struct {
	Level        string     `yaml:"level,omitempty" env:"GOGH_LOG_LEVEL"`
	Date         BoolOption `yaml:"date" env:"GOGH_LOG_DATE"`                 // the date in the local time zone: 2009/01/23
	Time         BoolOption `yaml:"time" env:"GOGH_LOG_TIME"`                 // the time in the local time zone: 01:23:23
	MicroSeconds BoolOption `yaml:"microseconds" env:"GOGH_LOG_MICROSECONDS"` // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	LongFile     BoolOption `yaml:"longfile" env:"GOGH_LOG_LONGFILE"`         // full file name and line number: /a/b/c/d.go:23
	ShortFile    BoolOption `yaml:"shortfile" env:"GOGH_LOG_SHORTFILE"`       // final file name element and line number: d.go:23. overrides Llongfile
	UTC          BoolOption `yaml:"utc" env:"GOGH_LOG_UTC"`                   // if Ldate or Ltime is set, use UTC rather than the local time zone
}

type OptionAccessor

type OptionAccessor struct {
	// contains filtered or unexported fields
}

func Option

func Option(optionName string) (*OptionAccessor, error)

func (OptionAccessor) Get

func (a OptionAccessor) Get(cfg *Config) string

func (OptionAccessor) Put

func (a OptionAccessor) Put(cfg *Config, value string) error

func (OptionAccessor) Unset

func (a OptionAccessor) Unset(cfg *Config) error

type PathListOption

type PathListOption []string

func (*PathListOption) Decode

func (c *PathListOption) Decode(repl string) error

Decode implements the interface `envdecode.Decoder`

func (PathListOption) MarshalYAML

func (c PathListOption) MarshalYAML() (interface{}, error)

MarshalYAML implements the interface `yaml.Marshaler`

func (*PathListOption) UnmarshalYAML

func (c *PathListOption) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the interface `yaml.Unmarshaler`

Jump to

Keyboard shortcuts

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