config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(flagSet *flag.FlagSet, cfg Configurator, options ...Option) error

Init initializes Configure cfg from command line flags with options

func IsExitError

func IsExitError(err error) (code int, ok bool)

Types

type BaseConfig

type BaseConfig struct {

	// Core represents core common fields
	Core struct {
		Mode      Mode            `json:"mode"`
		ID        int             `json:"id"`
		FPS       int             `json:"fps"`
		Log       LogConfig       `json:"log"`
		MQ        MQConfig        `json:"mq"`
		Discovery DiscoveryConfig `json:"discovery"`
	} `json:"core"`
	// contains filtered or unexported fields
}

BaseConfig implments Configurator

func (*BaseConfig) GetDiscovery

func (c *BaseConfig) GetDiscovery() (name, source string)

GetDiscovery implements Configurator GetDiscovery method

func (*BaseConfig) Read

func (c *BaseConfig) Read(self Configurator, r io.Reader) error

Read implements Configurator Read method

func (*BaseConfig) SetSource

func (c *BaseConfig) SetSource(source string)

SetSource implements Configurator SetSource method

func (BaseConfig) Write

func (c BaseConfig) Write(self Configurator, w io.Writer) error

Write implements Configurator Write method

type Configurator

type Configurator interface {
	// Read reads config from reader r
	Read(Configurator, io.Reader) error
	// Write writes config to writer w
	Write(Configurator, io.Writer) error
	// SetSource sets source of config
	SetSource(string)
	// GetDiscovery returns configuration of discovery
	GetDiscovery() (name, source string)
}

Configurator represents generic config of application

type Discoverable

type Discoverable interface {
	// DiscoveredContent returns a discovered data
	DiscoveredContent() ([]byte, error)
}

Discoverable represents a discoverable configurator

type DiscoveryConfig

type DiscoveryConfig struct {
	Name   string `json:"name"`
	Source string `json:"source"`
}

DiscoveryConfig ...

type LogConfig

type LogConfig struct {
	// Level of log
	Level string `json:"level"`
	// Prefix to preappend to each log message
	Prefix string `json:"prefix"`

	// Writers specified multi-writers, like:
	//	[
	//		"console",
	//		"file://path/to/filename?suffix=.txt"
	//	]
	Writers []string `json:"writers"`
}

LogConfig represents configuration of log

type MQConfig

type MQConfig struct {
	Name   string `json:"name"`
	Source string `json:"source"`
}

MQConfig ...

type Mode

type Mode int

Process running mode

const (
	Dev Mode = iota
	Preview
	Prod
)

func (Mode) MarshalJSON

func (mode Mode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler MarshalJSON method

func (*Mode) UnmarshalJSON

func (mode *Mode) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler UnmarshalJSON method

type Option

type Option func(*option)

Option is the option for Init

func WithDefaultSource

func WithDefaultSource(source string) Option

WithDefaultSource specify default config source

func WithInput

func WithInput(flag, usage string) Option

WithInput specify command line flag name and usage for config input

func WithOutput

func WithOutput(flag, usage string) Option

WithOutput specify command line flag name and usage for config output

func WithVersion

func WithVersion(flag, usage string) Option

WithVersion specify command line flag name and usage for version

Jump to

Keyboard shortcuts

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