grc

package module
v0.0.0-...-90d6374 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: MIT Imports: 14 Imported by: 0

README

grc

Usage

Remote Configuration

Define the configuration structure with default values

type TestConfig struct {
	IntVal   int               `json:"int_val" default:"8080"`
	StrVal   string            `default:"test"`
	SliceVal []int             `default:"1,2,3,4,ee"`
	MapVal   map[string]string `default:"a:aa,b:bb,c,d"`
}

Create grc instance

rc, err := grc.New(context.TODO(), grc.EtcdV3, "127.0.0.1:2379", "username", "password")
if err != nil {
	//return
}

Subscribe configuration

path := "/test/conf"
err := rc.SubscribeConf(path, TestConfig{})
if err != nil {
	//return
}

Use configuration

conf := rc.GetConf(path).(TestConfig)
  • The return type of rc.GetConf(path) is the same as the second parameter passed into rc.SubscribeConf.
  • The type can also be a pointor:
err := rc.SubscribeConf(path, &TestConfig{})
if err != nil {
	//return
}

conf := rc.GetConf(path).(*TestConfig)
Service Discovery

Register node

node := "127.0.0.1:6600"
path := "/test/service/a"
err := rc.RegisterNode(path, node, time.Second*5)
if err != nil {
	//return
}

Get service nodes

nodes := rc.GetService(path)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownProvider = errors.New("unknown provider type")
	ErrNotRegistered   = errors.New("service or config not registered")
	ErrInvalidDuration = errors.New("invalid ttl")
)

Functions

func Decode

func Decode(data string, item interface{}) interface{}

Types

type ProviderType

type ProviderType string
const (
	Debug  ProviderType = backend.Debug
	EtcdV3              = backend.EtcdV3
)

type RemoteConfig

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

func New

func New(ctx context.Context, typ ProviderType, endPoint, user, password string) (*RemoteConfig, error)

func NewWithProvider

func NewWithProvider(ctx context.Context, provider backend.Provider) (*RemoteConfig, error)

func (*RemoteConfig) GetConf

func (rc *RemoteConfig) GetConf(path string) interface{}

func (*RemoteConfig) GetService

func (rc *RemoteConfig) GetService(path string) []string

Get specified service nodes

func (*RemoteConfig) RegisterNode

func (rc *RemoteConfig) RegisterNode(path, nodeID string, ttl time.Duration) error

Register node for service discovery

func (*RemoteConfig) SubscribeConf

func (rc *RemoteConfig) SubscribeConf(path string, val interface{}) error

Subscribe remote config

func (*RemoteConfig) SubscribeService

func (rc *RemoteConfig) SubscribeService(path string) error

Subscribe specified service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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