Documentation
¶
Index ¶
- Constants
- Variables
- func SyncInterval(interval time.Duration) controllerOption
- type Cache
- func (c *Cache) Copy() *Cache
- func (c *Cache) Del(ns, typ, key string) error
- func (c *Cache) Diff(that *Cache) (add, update, del []*RawConf)
- func (c *Cache) Exist(ns string) bool
- func (c *Cache) Get(ns, typ, key string) ([]byte, error)
- func (c *Cache) Keys(ns, typ string) ([]string, error)
- func (c *Cache) Set(ns, typ, key string, value []byte)
- type Controller
- func (c *Controller) Add(namespace, typ, key string, value []byte) error
- func (c *Controller) Del(namespace, typ, key string) error
- func (c *Controller) Dependencies() *DependenciesController
- func (c *Controller) Exist(namespace, typ, key string) bool
- func (c *Controller) Get(namespace, typ, key string) ([]byte, error)
- func (c *Controller) GetCache(namespace, typ, key string) ([]byte, error)
- func (c *Controller) Instances() *InstancesController
- func (c *Controller) Keys(namespace, typ string) ([]string, error)
- func (c *Controller) KeysCached(namespace, typ string) ([]string, error)
- func (c *Controller) ProxyConfigs() *ProxyConfigsController
- func (c *Controller) RegisterEventHandler(handler EventHandler)
- func (c *Controller) Start() error
- func (c *Controller) Stop()
- func (c *Controller) Update(namespace, typ, key string, value []byte) error
- type Dependencies
- type DependenciesController
- func (c *DependenciesController) Add(dependency *Dependency) error
- func (c *DependenciesController) Delete(svc string) error
- func (c *DependenciesController) Exist(svc string) bool
- func (c *DependenciesController) Get(svc string) (*Dependency, error)
- func (c *DependenciesController) GetAll() (Dependencies, error)
- func (c *DependenciesController) GetAllCache() (Dependencies, error)
- func (c *DependenciesController) GetCache(svc string) (*Dependency, error)
- func (c *DependenciesController) RegisterEventHandler(handler DependencyEventHandler)
- func (c *DependenciesController) Update(dependency *Dependency) error
- type Dependency
- type DependencyEvent
- type DependencyEventHandler
- type Event
- type EventHandler
- type EventType
- type Instance
- type InstanceEvent
- type InstanceEventHandler
- type Instances
- type InstancesController
- func (c *InstancesController) Add(inst *Instance) error
- func (c *InstancesController) Delete(id string) error
- func (c *InstancesController) Exist(id string) bool
- func (c *InstancesController) Get(id string) (*Instance, error)
- func (c *InstancesController) GetAll() (Instances, error)
- func (c *InstancesController) GetAllCache() (Instances, error)
- func (c *InstancesController) GetCache(id string) (*Instance, error)
- func (c *InstancesController) Update(inst *Instance) error
- type Metadata
- type ProxyConfig
- type ProxyConfigEvent
- type ProxyConfigEventHandler
- type ProxyConfigs
- type ProxyConfigsController
- func (c *ProxyConfigsController) Add(cfg *ProxyConfig) error
- func (c *ProxyConfigsController) Delete(svc string) error
- func (c *ProxyConfigsController) Exist(svc string) bool
- func (c *ProxyConfigsController) Get(svc string) (*ProxyConfig, error)
- func (c *ProxyConfigsController) GetAll() (ProxyConfigs, error)
- func (c *ProxyConfigsController) GetAllCache() (ProxyConfigs, error)
- func (c *ProxyConfigsController) GetCache(svc string) (*ProxyConfig, error)
- func (c *ProxyConfigsController) RegisterEventHandler(handler ProxyConfigEventHandler)
- func (c *ProxyConfigsController) Update(cfg *ProxyConfig) error
- type RawConf
- type Store
- type SubscribableStore
Constants ¶
const ( NamespaceService = "service" TypeServiceProxyConfig = "proxy-config" TypeServiceDependency = "dependency" NamespaceSamaritan = "samaritan" TypeSamaritanInstance = "instance" )
Variables ¶
var ( ErrNotExist = errors.New("config not exist") ErrExist = errors.New("config is exist") )
var InterestedNSAndType = map[string][]string{ NamespaceService: {TypeServiceProxyConfig, TypeServiceDependency}, NamespaceSamaritan: {TypeSamaritanInstance}, }
Functions ¶
func SyncInterval ¶
Types ¶
type Controller ¶
Controller is used to store configuration information.
func NewController ¶
func NewController(store Store, opts ...controllerOption) *Controller
NewController return a new Controller.
func (*Controller) Add ¶
func (c *Controller) Add(namespace, typ, key string, value []byte) error
Add add config data by namespace, type and key.
func (*Controller) Del ¶
func (c *Controller) Del(namespace, typ, key string) error
Del del config data by namespace, type and key.
func (*Controller) Dependencies ¶
func (c *Controller) Dependencies() *DependenciesController
func (*Controller) Exist ¶
func (c *Controller) Exist(namespace, typ, key string) bool
Exist return true if config data is exist.
func (*Controller) Get ¶
func (c *Controller) Get(namespace, typ, key string) ([]byte, error)
Get return config data by namespace, type and key.
func (*Controller) GetCache ¶
func (c *Controller) GetCache(namespace, typ, key string) ([]byte, error)
GetCache return config data by namespace, type and key from cache.
func (*Controller) Instances ¶
func (c *Controller) Instances() *InstancesController
func (*Controller) Keys ¶
func (c *Controller) Keys(namespace, typ string) ([]string, error)
Keys return all key by namespace and type.
func (*Controller) KeysCached ¶
func (c *Controller) KeysCached(namespace, typ string) ([]string, error)
Keys return all key by namespace and type from cache.
func (*Controller) ProxyConfigs ¶
func (c *Controller) ProxyConfigs() *ProxyConfigsController
func (*Controller) RegisterEventHandler ¶
func (c *Controller) RegisterEventHandler(handler EventHandler)
RegisterEventHandler registers a handler to handle config event.
type Dependencies ¶
type Dependencies []*Dependency
Dependencies is a slice of Dependency, impl the sort.Interface.
func (Dependencies) Len ¶
func (d Dependencies) Len() int
func (Dependencies) Less ¶
func (d Dependencies) Less(i, j int) bool
func (Dependencies) Swap ¶
func (d Dependencies) Swap(i, j int)
type DependenciesController ¶
func (*DependenciesController) Add ¶
func (c *DependenciesController) Add(dependency *Dependency) error
func (*DependenciesController) Delete ¶
func (c *DependenciesController) Delete(svc string) error
func (*DependenciesController) Exist ¶
func (c *DependenciesController) Exist(svc string) bool
func (*DependenciesController) Get ¶
func (c *DependenciesController) Get(svc string) (*Dependency, error)
func (*DependenciesController) GetAll ¶
func (c *DependenciesController) GetAll() (Dependencies, error)
func (*DependenciesController) GetAllCache ¶
func (c *DependenciesController) GetAllCache() (Dependencies, error)
func (*DependenciesController) GetCache ¶
func (c *DependenciesController) GetCache(svc string) (*Dependency, error)
func (*DependenciesController) RegisterEventHandler ¶
func (c *DependenciesController) RegisterEventHandler(handler DependencyEventHandler)
func (*DependenciesController) Update ¶
func (c *DependenciesController) Update(dependency *Dependency) error
type Dependency ¶
type Dependency struct { Metadata ServiceName string `json:"service_name"` Dependencies []string `json:"dependencies"` }
Dependency is a wrapper of dependency info of service.
type DependencyEvent ¶
DependencyEvent represents a dependency config event.
type DependencyEventHandler ¶
type DependencyEventHandler func(event *DependencyEvent)
DependencyEventHandler is used to handle the dependency event.
type Instance ¶
type InstanceEvent ¶
InstanceEvent represents an instance config event.
type InstanceEventHandler ¶
type InstanceEventHandler func(event *InstanceEvent)
InstanceEventHandler is used to handle the instance event.
type InstancesController ¶
type InstancesController struct {
// contains filtered or unexported fields
}
func (*InstancesController) Add ¶
func (c *InstancesController) Add(inst *Instance) error
func (*InstancesController) Delete ¶
func (c *InstancesController) Delete(id string) error
func (*InstancesController) Exist ¶
func (c *InstancesController) Exist(id string) bool
func (*InstancesController) GetAll ¶
func (c *InstancesController) GetAll() (Instances, error)
func (*InstancesController) GetAllCache ¶
func (c *InstancesController) GetAllCache() (Instances, error)
func (*InstancesController) GetCache ¶
func (c *InstancesController) GetCache(id string) (*Instance, error)
func (*InstancesController) Update ¶
func (c *InstancesController) Update(inst *Instance) error
type ProxyConfig ¶
type ProxyConfig struct { Metadata ServiceName string `json:"service_name"` Config *service.Config `json:"config"` }
ProxyConfig is a wrapper of service.Config.
type ProxyConfigEvent ¶
type ProxyConfigEvent struct { Type EventType ProxyConfig *ProxyConfig }
ProxyConfigEvent represents an event config event.
type ProxyConfigEventHandler ¶
type ProxyConfigEventHandler func(event *ProxyConfigEvent)
ProxyConfigEventHandler is used to handle proxy config event.
type ProxyConfigs ¶
type ProxyConfigs []*ProxyConfig
ProxyConfigs is a slice of ProxyConfig, impl the sort.Interface.
func (ProxyConfigs) Len ¶
func (c ProxyConfigs) Len() int
func (ProxyConfigs) Less ¶
func (c ProxyConfigs) Less(i, j int) bool
func (ProxyConfigs) Swap ¶
func (c ProxyConfigs) Swap(i, j int)
type ProxyConfigsController ¶
type ProxyConfigsController struct {
// contains filtered or unexported fields
}
func (*ProxyConfigsController) Add ¶
func (c *ProxyConfigsController) Add(cfg *ProxyConfig) error
func (*ProxyConfigsController) Delete ¶
func (c *ProxyConfigsController) Delete(svc string) error
func (*ProxyConfigsController) Exist ¶
func (c *ProxyConfigsController) Exist(svc string) bool
func (*ProxyConfigsController) Get ¶
func (c *ProxyConfigsController) Get(svc string) (*ProxyConfig, error)
func (*ProxyConfigsController) GetAll ¶
func (c *ProxyConfigsController) GetAll() (ProxyConfigs, error)
func (*ProxyConfigsController) GetAllCache ¶
func (c *ProxyConfigsController) GetAllCache() (ProxyConfigs, error)
func (*ProxyConfigsController) GetCache ¶
func (c *ProxyConfigsController) GetCache(svc string) (*ProxyConfig, error)
func (*ProxyConfigsController) RegisterEventHandler ¶
func (c *ProxyConfigsController) RegisterEventHandler(handler ProxyConfigEventHandler)
func (*ProxyConfigsController) Update ¶
func (c *ProxyConfigsController) Update(cfg *ProxyConfig) error
type RawConf ¶
RawConf represents a raw configuration.
func NewRawConf ¶
NewRawConf return a new RawConf.
type Store ¶
type Store interface { Get(namespace, typ, key string) ([]byte, error) Add(namespace, typ, key string, value []byte) error Update(namespace, typ, key string, value []byte) error Del(namespace, typ, key string) error Exist(namespace, typ, key string) bool GetKeys(namespace, typ string) ([]string, error) Start() error Stop() }
The store is a kv store.
type SubscribableStore ¶
type SubscribableStore interface { Store Subscribe(namespace string) error UnSubscribe(namespace string) error Event() <-chan struct{} }
SubscribableStore allows you to subscribe to the namespace you are interested in, and will send a notification when there is some change in the namespace.