go_config_centor

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 13 Imported by: 0

README

go_config_centor

基于zookeeper的配置中心

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Center

type Center struct {
	*viper.Viper
	// contains filtered or unexported fields
}

func NewCenter

func NewCenter(Name string) (center *Center)

func (*Center) GetKafkaAddresses added in v1.0.2

func (c *Center) GetKafkaAddresses() (addrArr []string, err error)

func (*Center) GetZKHosts added in v1.1.0

func (c *Center) GetZKHosts() (addrArr []string, err error)

func (*Center) Open added in v1.0.2

func (c *Center) Open(options ...Option) (msg []string, err error)

type Config added in v1.2.0

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

func Open added in v1.2.0

func Open(path string, options *Options) (config *Config, err error)

func (*Config) Close added in v1.2.0

func (c *Config) Close() error

func (*Config) GetCommon added in v1.2.0

func (c *Config) GetCommon() *model.CommonConfig

func (*Config) Set added in v1.2.0

func (c *Config) Set(in interface{}) (err error)

func (*Config) SetCommon added in v1.2.0

func (c *Config) SetCommon(common *model.CommonConfig) (err error)

func (*Config) Unmarshal added in v1.2.0

func (c *Config) Unmarshal(out interface{}) (err error)

type ConfigType added in v1.2.0

type ConfigType int
const (
	ConfigTypeFile ConfigType = iota
	ConfigTypeZookeeper
	ConfigTypeConsul
)

type FileConfig added in v1.0.5

type FileConfig struct {
	*viper.Viper
	// contains filtered or unexported fields
}

func (*FileConfig) Debug added in v1.0.6

func (f *FileConfig) Debug() bool

func (*FileConfig) GetZKHosts added in v1.0.5

func (f *FileConfig) GetZKHosts() []string

type Option added in v1.1.0

type Option interface {
	// contains filtered or unexported methods
}

type OptionLocalConfigPath added in v1.1.0

type OptionLocalConfigPath string

配置文件存储位置

type OptionOnlineMode added in v1.1.0

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

开启在线配置中心

func NewOptionOnlineMode added in v1.1.0

func NewOptionOnlineMode(remoteDir, zkConfigPath string) (o *OptionOnlineMode)

type OptionZKConfigPath added in v1.1.0

type OptionZKConfigPath string

type Options added in v1.2.0

type Options struct {
	Type  ConfigType
	Hosts []string
}

func DefaultOptions added in v1.2.0

func DefaultOptions() (options *Options)

type PostgreSQLConfig added in v1.0.2

type PostgreSQLConfig struct {
	Write SQLConfig
	Read  []SQLConfig
}

type PublicConfig added in v1.1.0

type PublicConfig struct {
	Redis RedisConfig
}
func (c *Center) Update() (err error) {
	err = c.prepareConfig(c.viper, path.Join(c.RemotePath, c.name), c.localPathName())

	if c.enablePublicConfig {
		err = c.prepareConfig(c.publicViper, path.Join(centerPrefix, publicConfigName), c.publicLocalPathName())
		c.SetPublicDefault()

		//同步线上公共配置
		err = c.syncPublic()
		if err != nil {
			err = fmt.Errorf("[config center]sync public config fail:\n%w", err)
			log.Error(err)
		}
	}

	return
}

type RedisConfig added in v1.0.2

type RedisConfig struct {
	Type       string
	MasterName string
	// A seed list of host:port addresses of cluster nodes.
	Addrs []string

	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 8 retries.
	MaxRedirects int

	// Enables read-only commands on slave nodes.
	ReadOnly bool
	// Allows routing read-only commands to the closest master or slave node.
	// It automatically enables ReadOnly.
	RouteByLatency bool
	// Allows routing read-only commands to the random master or slave node.
	// It automatically enables ReadOnly.
	RouteRandomly bool

	Password string

	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	// PoolSize applies per cluster node and not for the whole cluster.
	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
}

type SQLConfig added in v1.0.2

type SQLConfig struct {
	Host     string
	Port     int
	User     string
	Password string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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