config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default top-level configuration.
	DefaultConfig = Config{
		GlobalConfig: DefaultGlobalConfig,
		EtcdConfig:   DefaultEtcdConfig,
	}

	// DefaultGlobalConfig is the default global configuration.
	DefaultGlobalConfig = GlobalConfig{
		RemoteHostPattern:   ".*",
		BasicAuthentication: BasicAuthentication{},
	}

	// DefaultEtcdConfig is the default Etcd configuration.
	DefaultEtcdConfig = EtcdConfig{
		Endpoints:            []string{"127.0.0.1:2379"},
		DialTimeout:          etcdDefaultDialTimeout,
		DialKeepAliveTime:    etcdDefaultKeepAliveTime,
		DialKeepAliveTimeout: etcdDefaultKeepAliveTimeOut,
	}
)

Functions

func Load

func Load(in string) error

Load parses the YAML input s into a Config

func LoadFile

func LoadFile(in string) error

LoadFile parses the given YAMl file into a Config.

func OnConfigChange

func OnConfigChange(run func(in fsnotify.Event))

OnConfigChange defines the function be called when config file was change.

func Set

func Set(fp string, l log.Logger) error

Set sets logger and loads Config from the given file path.

func SetConfig

func SetConfig(newConf *Config)

SetConfig updates the value of configuration. newConf should be a copy of m.config instance.

func SetConfigPath

func SetConfigPath(in string)

SetConfigPath sets the path of config file

func SetConfigPermissions

func SetConfigPermissions(perm os.FileMode)

SetConfigPermissions sets the permissions for the config file.

func SetLogger

func SetLogger(l log.Logger)

SetLogger sets the manager's log instance.

func Show

func Show()

Show returns the represent of Config. For debug purpose only

func WatchConfig

func WatchConfig()

WatchConfig detects file changes and reloads config.

func Write

func Write() error

Write writes the currnet configuration to a file

Types

type BasicAuthentication

type BasicAuthentication struct {
	// Usename, Password to implement HTTP basic authentication
	Username string `yaml:"username"`
	Password Secret `yaml:"password"`
}

BasicAuthentication - HTTP Basic authentication.

type Config

type Config struct {
	GlobalConfig GlobalConfig `yaml:"global"`
	EtcdConfig   EtcdConfig   `yaml:"etcd"`
}

Config is the top-level configuration for Faythe's config file.

func Get

func Get() *Config

Get returns Config instance.

func (*Config) String

func (c *Config) String() string

String represents Configuration instance as string.

func (*Config) UnmarshalYAML

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

UnmarshalYAML implements the yaml.Unmarshaler interface

type EtcdConfig

type EtcdConfig struct {
	// Endpoints is a list of URLs.
	Endpoints []string `yaml:"endpoints"`

	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval time.Duration `yaml:"auto_sync_interval,omitempty"`

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration `yaml:"dial_timeout,omitempty"`

	// DialKeepAliveTime is the time after which client pings the server to see if
	// transport is alive.
	DialKeepAliveTime time.Duration `yaml:"dial_keep_alive_time,omitempty"`

	// DialKeepAliveTimeout is the time that the client waits for a response for the
	// keep-alive probe. If the response is not received in this time, the connection is closed.
	DialKeepAliveTimeout time.Duration `yaml:"dial_keep_alive_timeout,omitempty"`

	// MaxCallSendMsgSize is the client-side request send limit in bytes.
	// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024).
	// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallSendMsgSize int `yaml:"max_call_send_msg_size,omitempty"`

	// MaxCallRecvMsgSize is the client-side response receive limit.
	// If 0, it defaults to "math.MaxInt32", because range response can
	// easily exceed request send limits.
	// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallRecvMsgSize int `yaml:"max_call_recv_msg_size,omitempty"`

	// TLS holds the client secure credentials, if any.
	TLS *tls.Config `yaml:"tls,omitempty"`

	// Username is a user name for authentication.
	Username string `yaml:"username,omitempty"`

	// Password is a password for authentication.
	Password Secret `yaml:"password,omitempty"`

	// RejectOldCluster when set will refuse to create a client against an outdated cluster.
	RejectOldCluster bool `yaml:"reject_old_cluster,omitempty"`

	// PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs).
	PermitWithoutStream bool `yaml:"permit_without_stream,omitempty"`
}

EtcdConfig stores Etcd related configurations.

func (*EtcdConfig) UnmarshalYAML

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

UnmarshalYAML implements the yaml.Unmarshaler interface

type GlobalConfig

type GlobalConfig struct {
	// RemoteHostPattern can define an optional regexp pattern to be matched:
	//
	// - {name} matches anything until the next dot.
	//
	// - {name:pattern} matches the given regexp pattern.
	RemoteHostPattern string `yaml:"remote_host_pattern,omitempty"`
	// BasicAuthentication - HTTP Basic authentication.
	BasicAuthentication BasicAuthentication `yaml:"basic_auth,omitempty"`
}

GlobalConfig configures values that are used to config Faythe HTTP server

func (*GlobalConfig) UnmarshalYAML

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

UnmarshalYAML implements the yaml.Unmarshaler interface

type Manager

type Manager struct {
	Config *Config
	// contains filtered or unexported fields
}

Manager is a configuration manager. It maintains a global configuration, fetchs values to populate.

func NewManager

func NewManager() *Manager

NewManager returns initialized Manager instance

func (*Manager) Get

func (m *Manager) Get() *Config

Get returns Config instance.

func (*Manager) Load

func (m *Manager) Load(in string) error

Load parses the YAML input s into a Config

func (*Manager) LoadFile

func (m *Manager) LoadFile(in string) error

LoadFile parses the given YAMl file into a Config.

func (*Manager) OnConfigChange

func (m *Manager) OnConfigChange(run func(in fsnotify.Event))

OnConfigChange defines the function be called when config file was change.

func (*Manager) Set

func (m *Manager) Set(fp string, l log.Logger) error

Set sets logger and loads Config from the given file path.

func (*Manager) SetConfig

func (m *Manager) SetConfig(newConf *Config)

SetConfig updates the value of configuration. newConf should be a copy of m.config instance.

func (*Manager) SetConfigPath

func (m *Manager) SetConfigPath(in string)

SetConfigPath sets the path of config file

func (*Manager) SetConfigPermissions

func (m *Manager) SetConfigPermissions(perm os.FileMode)

SetConfigPermissions sets the permissions for the config file.

func (*Manager) SetLogger

func (m *Manager) SetLogger(l log.Logger)

SetLogger sets the manager's log instance.

func (*Manager) Show

func (m *Manager) Show()

Show returns the represent of Config. For debug purpose only

func (*Manager) WatchConfig

func (m *Manager) WatchConfig()

WatchConfig detects file changes and reloads config.

func (*Manager) Write

func (m *Manager) Write() error

Write writes the current configuration to a file.

type Secret

type Secret string

Secret special type for storing secrets

func (Secret) MarshalYAML

func (s Secret) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Secrets.

func (*Secret) UnmarshalYAML

func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Secrets.

Jump to

Keyboard shortcuts

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