config

package
v0.10.11 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 14 Imported by: 17

Documentation

Overview

Package config provides config structures, and a mechanism that merges sources such that the global config file, a project local config file and command line flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Edit

func Edit() error

Edit opens the project local config file with an editor. If the local config file is missing, Edit creates a new local config file. $EDITOR is used as an editor if it is configured. Else, Vim is used.

func EditGlobal added in v0.8.0

func EditGlobal() error

EditGlobal is the same as Edit, but edit the global config.

Types

type Config

type Config struct {
	Default *Default `toml:"default"`
	Meta    *Meta    `toml:"meta"`
	REPL    *REPL    `toml:"repl"`
	Server  *Server  `toml:"server"`
	Log     *Log     `toml:"log"`
	Request *Request `toml:"request"`
}

Each TOML key must be equal the field name in the lower-case. It is a limitation of spf13/viper.

func Get

func Get(fs *pflag.FlagSet) (*Config, error)

Get returns the config which loaded from the global and local config files, and command line flags passed as an argument. Note that fs must have been parsed.

The order of priority is flags > local > global.

func (*Config) Validate added in v0.8.0

func (c *Config) Validate() error

Validate defines invalid conditions and validates whether c has invalid condtions. For example, in the case of CLI mode, c must have package, service and call values. Validate returns ValidationError if some conditions are invalid.

type Default

type Default struct {
	ProtoPath []string `toml:"protoPath"`
	ProtoFile []string `toml:"protoFile"`
	Package   string   `toml:"package"`
	Service   string   `toml:"service"`
}
type Header map[string][]string

type Log

type Log struct {
	Prefix string `toml:"prefix"`
}

type Meta

type Meta struct {
	ConfigVersion string `toml:"configVersion"`
	AutoUpdate    bool   `toml:"autoUpdate"`
	UpdateLevel   string `toml:"updateLevel"`
}

type REPL

type REPL struct {
	PromptFormat      string `toml:"promptFormat"`
	InputPromptFormat string `toml:"inputPromptFormat"`

	ColoredOutput bool `toml:"coloredOutput"`

	Silent         bool   `toml:"silent"`
	SplashTextPath string `toml:"splashTextPath"`

	// TODO: Split history files between projects.
	HistorySize int `toml:"historySize"`
}

type Request

type Request struct {
	Header      Header `toml:"header"`
	Web         bool   `toml:"web"`
	CACertFile  string `toml:"caCertFile"`
	CertFile    string `toml:"certFile"`
	CertKeyFile string `toml:"certKeyFile"`
}

type Server

type Server struct {
	Host       string `toml:"host"`
	Port       string `toml:"port"`
	Reflection bool   `toml:"reflection"`
	TLS        bool   `toml:"tls"`
	Name       string `toml:"name"`
}

type ValidationError added in v0.8.0

type ValidationError struct {
	Err *multierror.Error
}

ValidationError contains errors that describes invalid config conditions.

func (*ValidationError) Error added in v0.8.0

func (e *ValidationError) Error() string

Error returns ValidationError's error text.

Jump to

Keyboard shortcuts

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