goarchaius

package module
v0.0.0-...-0c60762 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

Go-Archaius

Build Status This is a dynamic configuration client for Go-Chassis which helps in configuration management for micro-services developed using Go-Chassis sdk. The main objective of this client is to pull or sync the configuration from config-sources for a particular micro-service.

Sources

This Go-Archaius client supports multiple sources for the configuration.

  1. Command Line Sources - You can give the configurations key and values in the command lines arguments while starting the microservice.

  2. Environment Variable Sources - You can specify the sources of conifguration in Environment variable.

  3. External Sources - You can also specify the configuration sources to be some external config server from where the client can pull the configuration.

  4. Files Sources - You can specify some specific files from where client can read the configuration for the microservices.

You can also specify multiple sources at a same time. Go-Archaius client keeps all the sources marked with their precendence, in case if two sources have same config then source with higher precendence will be selected.

Refresh Mechanism

Go-Archaius client support 2 types of refresh mechanism:

  1. Web-Socket Based - In this client makes an web socket connection with the config server and keeps getting an events whenever any data changes.
refreshMode: 0
  1. Pull Configuration - In this type client keeps polling the configuration from the config server at regular intervals.
refreshMode: 1

Configuration for Go-Archaius client.

You can configure the client to pull the configuration from external config server, the server ip address and basic parameters can be added in chassis.yaml

 config:
   client:
     serverUri: http://XX:YYY   #Config Server IP
     tenantName:  default #This configuration is for local environment, for paas platform there is a auth plugin for authentication. If dont provide the tenant name it will take default values.
     refreshMode: 1  # 配置动态刷新模式,0为configcenter在发生变化时主动推送,1为client端周期拉取,其他值均为非法,不会去连配置中心
     refreshInterval: 30 #refreshMode配置为1时,client端主动从配置中心拉取配置的周期,单位秒
     autodiscovery: false
     api:  #Optional
       version: v3

Documentation

Overview

Package goarchaius provides you a list of interface which helps in communciation with config-center

Index

Constants

View Source
const (
	//UnsuccessfulArchaiusInit is of type string
	UnsuccessfulArchaiusInit = "issue with go-archaius initialization"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigFactory

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

ConfigFactory is a struct which stores configuration information

func (*ConfigFactory) AddByDimensionInfo

func (arc *ConfigFactory) AddByDimensionInfo(dimensionInfo string) (map[string]string, error)

AddByDimensionInfo adds a NewDimensionInfo of which configurations needs to be taken

func (*ConfigFactory) AddSource

func (arc *ConfigFactory) AddSource(source core.ConfigSource) error

AddSource return all values of different sources

func (*ConfigFactory) DeInit

func (arc *ConfigFactory) DeInit() error

DeInit return all values of different sources

func (*ConfigFactory) GetConfigurationByKey

func (arc *ConfigFactory) GetConfigurationByKey(key string) interface{}

GetConfigurationByKey return all values of different sources

func (*ConfigFactory) GetConfigurationByKeyAndDimensionInfo

func (arc *ConfigFactory) GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key string) interface{}

GetConfigurationByKeyAndDimensionInfo get the value for a key in a particular dimensionInfo

func (*ConfigFactory) GetConfigurations

func (arc *ConfigFactory) GetConfigurations() map[string]interface{}

GetConfigurations dump complete configuration managed by config-client

Only return highest priority key value:-
1. ConfigFile 		2. Environment Variable
3. Commandline Argument	4. Config Center configuration
config-center value being the highest priority

func (*ConfigFactory) GetConfigurationsByDimensionInfo

func (arc *ConfigFactory) GetConfigurationsByDimensionInfo(dimensionInfo string) map[string]interface{}

GetConfigurationsByDimensionInfo dump complete configuration managed by config-client Only return Config Center configurations.

func (*ConfigFactory) GetValue

func (arc *ConfigFactory) GetValue(key string) cast.Value

GetValue an abstraction to return key's value in respective type

func (*ConfigFactory) GetValueByDI

func (arc *ConfigFactory) GetValueByDI(dimensionInfo, key string) cast.Value

GetValueByDI an abstraction to return key's value in respective type based on dimension info which is provided by user

func (*ConfigFactory) Init

func (arc *ConfigFactory) Init() error

Init intiates the Configurationfatory

func (*ConfigFactory) IsKeyExist

func (arc *ConfigFactory) IsKeyExist(key string) bool

IsKeyExist check existence of key

func (*ConfigFactory) RegisterListener

func (arc *ConfigFactory) RegisterListener(listenerObj core.EventListener, keys ...string) error

RegisterListener Function to Register all listener for different key changes

func (*ConfigFactory) UnRegisterListener

func (arc *ConfigFactory) UnRegisterListener(listenerObj core.EventListener, keys ...string) error

UnRegisterListener remove listener

func (*ConfigFactory) Unmarshal

func (arc *ConfigFactory) Unmarshal(obj interface{}) error

Unmarshal function is used in the case when user want his yaml file to be unmarshalled to structure pointer Unmarshal function accepts a pointer and in called function anyone can able to get the data in passed object Unmarshal only accepts a pointer values Unmarshal returns error if obj values are 0. nil and value type. Procedure:

  1. Unmarshal first checks the passed object type using reflection.
  2. Based on type Unmarshal function will check and set the values ex: If type is basic types like int, string, float then it will assigb directly values, If type is map, ptr and struct then it will again send for unmarshal untill it find the basic type and set the values

type ConfigurationFactory

type ConfigurationFactory interface {
	// Init ConfigurationFactory
	Init() error
	// dump complete configuration managed by config-client based on priority
	// (1. Config Center 2. Commandline Argument 3.Environment Variable  4.ConfigFile , 1 with highest priority
	GetConfigurations() map[string]interface{}
	// dump complete configuration managed by config-client for Config Center based on dimension info.
	GetConfigurationsByDimensionInfo(dimensionInfo string) map[string]interface{}
	// add the dimension info for other services
	AddByDimensionInfo(dimensionInfo string) (map[string]string, error)
	// return all values of different sources
	GetConfigurationByKey(key string) interface{}
	// check for existence of key
	IsKeyExist(string) bool
	// unmarshal data on user define structure
	Unmarshal(structure interface{}) error
	// Add custom sources
	AddSource(core.ConfigSource) error
	//Function to Register all listener for different key changes, each key could be a regular expression
	RegisterListener(listenerObj core.EventListener, key ...string) error
	// remove listener
	UnRegisterListener(listenerObj core.EventListener, key ...string) error
	// DeInit
	DeInit() error
	// an abstraction to return key's value in respective type
	GetValue(key string) cast.Value
	// return values of config-center source based on key and dimension info
	GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key string) interface{}
	// an abstraction to return key's value in respective type based on dimension info which is provided by user
	GetValueByDI(dimensionInfo, key string) cast.Value
}

ConfigurationFactory is a list of Interface for Config Center

func NewConfigFactory

func NewConfigFactory(log lager.Logger) (ConfigurationFactory, error)

NewConfigFactory creates a new configuration object for Config center

Directories

Path Synopsis
Package core provides a list of interface for Dispatcher and ConfigMgr
Package core provides a list of interface for Dispatcher and ConfigMgr
cast
Package cast provides the typeCasting of an object
Package cast provides the typeCasting of an object
config-manager
Package configmanager provides functions to communicate to Config-Center Package configmanager provides deserializer
Package configmanager provides functions to communicate to Config-Center Package configmanager provides deserializer
event-system
Package eventsystem provides the different Listeners
Package eventsystem provides the different Listeners
* Created by on 2017/7/19.
* Created by on 2017/7/19.
sources
commandline-source
Package commandlinesource created on 2017/6/22.
Package commandlinesource created on 2017/6/22.
configcenter-source
Package configcentersource created on 2017/6/22.
Package configcentersource created on 2017/6/22.
enviromentvariable-source
Package envconfigsource created on 2017/6/22.
Package envconfigsource created on 2017/6/22.
file-source
Package filesource created on 2017/6/22.
Package filesource created on 2017/6/22.

Jump to

Keyboard shortcuts

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