config

package
v0.0.0-...-ee9fa08 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceService       = "service"
	TypeServiceProxyConfig = "proxy-config"
	TypeServiceDependency  = "dependency"

	NamespaceSamaritan    = "samaritan"
	TypeSamaritanInstance = "instance"
)

Variables

View Source
var (
	ErrNotExist = errors.New("config not exist")
	ErrExist    = errors.New("config is exist")
)

Functions

func SyncInterval

func SyncInterval(interval time.Duration) controllerOption

Types

type Cache

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

func NewCache

func NewCache() *Cache

func (*Cache) Copy

func (c *Cache) Copy() *Cache

func (*Cache) Del

func (c *Cache) Del(ns, typ, key string) error

func (*Cache) Diff

func (c *Cache) Diff(that *Cache) (add, update, del []*RawConf)

func (*Cache) Exist

func (c *Cache) Exist(ns string) bool

func (*Cache) Get

func (c *Cache) Get(ns, typ, key string) ([]byte, error)

func (*Cache) Keys

func (c *Cache) Keys(ns, typ string) ([]string, error)

func (*Cache) Set

func (c *Cache) Set(ns, typ, key string, value []byte)

type Controller

type Controller struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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.

func (*Controller) Start

func (c *Controller) Start() error

Start start the controller.

func (*Controller) Stop

func (c *Controller) Stop()

Stop stop the controller.

func (*Controller) Update

func (c *Controller) Update(namespace, typ, key string, value []byte) error

Update update config data by namespace, type and key.

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

type DependenciesController struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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 (*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.

func (*Dependency) Verify

func (d *Dependency) Verify() error

Verify this dependency.

type DependencyEvent

type DependencyEvent struct {
	ServiceName string
	Add         []string
	Del         []string
}

DependencyEvent represents a dependency config event.

type DependencyEventHandler

type DependencyEventHandler func(event *DependencyEvent)

DependencyEventHandler is used to handle the dependency event.

type Event

type Event struct {
	Type   EventType
	Config *RawConf
}

Event represents a raw config event.

func NewEvent

func NewEvent(typ EventType, config *RawConf) *Event

NewEvent return a new Event.

type EventHandler

type EventHandler func(event *Event)

EventHandler is used to handle the event.

type EventType

type EventType uint8

EventType indicates the type of event.

const (
	EventAdd EventType = iota + 1
	EventUpdate
	EventDelete
)

The following shows the available event types.

type Instance

type Instance struct {
	Metadata
	ID            string `json:"id"`
	Hostname      string `json:"hostname"`
	IP            string `json:"ip"`
	Port          int    `json:"port"`
	Version       string `json:"version"`
	BelongService string `json:"belong_service"`
}

func (*Instance) Verify

func (i *Instance) Verify() error

type InstanceEvent

type InstanceEvent struct {
	Type     EventType
	Instance *Instance
}

InstanceEvent represents an instance config event.

type InstanceEventHandler

type InstanceEventHandler func(event *InstanceEvent)

InstanceEventHandler is used to handle the instance event.

type Instances

type Instances []*Instance

func (Instances) Len

func (i Instances) Len() int

func (Instances) Less

func (i Instances) Less(a, b int) bool

func (Instances) Swap

func (i Instances) Swap(a, b int)

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) Get

func (c *InstancesController) Get(id string) (*Instance, error)

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 Metadata

type Metadata struct {
	CreateTime time.Time `json:"create_time,omitempty"`
	UpdateTime time.Time `json:"update_time,omitempty"`
}

type ProxyConfig

type ProxyConfig struct {
	Metadata
	ServiceName string          `json:"service_name"`
	Config      *service.Config `json:"config"`
}

ProxyConfig is a wrapper of service.Config.

func (*ProxyConfig) Verify

func (c *ProxyConfig) Verify() error

Verify this ProxyConfig.

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 (*ProxyConfigsController) Delete

func (c *ProxyConfigsController) Delete(svc string) error

func (*ProxyConfigsController) Exist

func (c *ProxyConfigsController) Exist(svc string) bool

func (*ProxyConfigsController) Get

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

type RawConf struct {
	Namespace string
	Type      string
	Key       string
	Value     []byte
}

RawConf represents a raw configuration.

func NewRawConf

func NewRawConf(namespace, typ, key string, value []byte) *RawConf

NewRawConf return a new RawConf.

func (*RawConf) Copy

func (c *RawConf) Copy() *RawConf

func (*RawConf) Equal

func (c *RawConf) Equal(that *RawConf) bool

Equal return true if input RawConf is equal with current RawConf.

func (*RawConf) Hashcode

func (c *RawConf) Hashcode() uint32

Hashcode return the hashcode of this 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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