grc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 14 Imported by: 2

README

grc

grc (golang remote configuration) is a distribute service config and discovery center.

Features

Backend supported
  • Memory - debug only
  • ETCD
  • Consul
  • ZooKeeper
  • Redis

Dashboard

Install
  • Update config file dashboard/config.yaml

  • Run dashboard

docker run -d -p 8000:80 -v :/etc/config.yaml appootb/grc-dashboard

  • [Optional] run dashboard and etcd with docker-compose

docker-compose.yml

version: '3'
services:
  etcd:
    image: quay.io/coreos/etcd:v3.3.25
    environment:
      - ETCDCTL_API=3
    command:
      - "/usr/local/bin/etcd"
      - "--name"
      - "s1"
      - "--data-dir"
      - "/etcd-data"
      - "--listen-client-urls"
      - "http://0.0.0.0:2379"
      - "--advertise-client-urls"
      - "http://0.0.0.0:2379"
      - "--listen-peer-urls"
      - "http://0.0.0.0:2380"
      - "--initial-advertise-peer-urls"
      - "http://0.0.0.0:2380"
      - "--initial-cluster"
      - "s1=http://0.0.0.0:2380"
      - "--initial-cluster-token"
      - "tkn"
      - "--initial-cluster-state"
      - "new"
    ports:
      - "2379:2379"

  dashboard:
    image: appootb/grc-dashboard
    ports:
      - "8000:80"
    volumes:
      - "./dashboard/config.yaml:/etc/config.yaml"

Example

  1. Initialize grc instance
grc, _ = grc.New(WithDebugProvider(),
	WithConfigAutoCreation(),
	WithBasePath("/test"))
  1. Define configuration structure
type Config struct {
	//
	// Static configs, won't been changed when process running
	// Internal type
	IV  int                         `comment:"comment for dashboard" default:"1"`
	// Pointer
	PIV *int                        `comment:"comment for dashboard" default:"10"`
	// Map
	MV  map[string]int              `comment:"comment for dashboard" default:"a:1,b:2"`
	EMV map[string]map[string]int32 `comment:"comment for dashboard" default:"a_1:bb_2:1,cc_2:2;b_1:dd_2:19,ee_2:20"`
	// Slice
	AV  []bool                      `comment:"comment for dashboard" default:"false,true"`
	EAV [][]string                  `comment:"comment for dashboard" default:"a_1,b_1,c_1;a_2,b_2,c_2"`

	//
	// Dynamic configs, should be updated automatically
	DIV grc.Int   `comment:"comment for dashboard" default:"2"`
	DMV grc.Map   `comment:"comment for dashboard" default:"a_1:bb_2:1,cc_2:2;b_1:dd_2:19,ee_2:20"`
	DAV grc.Array `comment:"comment for dashboard" default:"a_1,b_1,c_1;a_2,b_2,c_2"`
}
  1. Register service configuration
var cfg Config
err := grc.RegisterConfig("Service_Name", &cfg)
if err != nil {
	// TODO
}
  1. That's all, use cfg directly which is concurrency safe.

Documentation

Index

Constants

View Source
const (
	ExceedDeepLevel = "grc: only support two level map/array"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

func (*Array) ArrayAt

func (t *Array) ArrayAt(i int) *embedArray

func (*Array) AtomicUpdate

func (t *Array) AtomicUpdate(v string)

func (*Array) Bools

func (t *Array) Bools() []*embedBool

func (*Array) Changed

func (t *Array) Changed(evt UpdateEvent)

func (*Array) Floats

func (t *Array) Floats() []*embedFloat

func (*Array) Ints

func (t *Array) Ints() []*embedInt

func (*Array) Len

func (t *Array) Len() int

func (*Array) String

func (t *Array) String() string

func (*Array) Strings

func (t *Array) Strings() []*embedString

func (*Array) Uints

func (t *Array) Uints() []*embedUint

type Bool

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

func (*Bool) AtomicUpdate

func (t *Bool) AtomicUpdate(v string)

func (*Bool) Bool

func (t *Bool) Bool() bool

func (*Bool) Changed

func (t *Bool) Changed(evt UpdateEvent)

func (*Bool) String

func (t *Bool) String() string

type Callback

type Callback interface {
	RegChan() chan<- *CallbackFunc
	EvtChan() chan<- DynamicType
}

type CallbackFunc

type CallbackFunc struct {
	Val DynamicType
	Evt UpdateEvent
}

type DynamicType

type DynamicType interface {
	// AtomicUpdate updates value.
	AtomicUpdate(v string)

	// Changed will be invoked if value updated.
	Changed(evt UpdateEvent)
}

DynamicType interface.

type Float

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

func (*Float) AtomicUpdate

func (t *Float) AtomicUpdate(v string)

func (*Float) Changed

func (t *Float) Changed(evt UpdateEvent)

func (*Float) Float32

func (t *Float) Float32() float32

func (*Float) Float64

func (t *Float) Float64() float64

func (*Float) String

func (t *Float) String() string

type Int

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

func (*Int) AtomicUpdate

func (t *Int) AtomicUpdate(v string)

func (*Int) Changed

func (t *Int) Changed(evt UpdateEvent)

func (*Int) Int

func (t *Int) Int() int

func (*Int) Int8

func (t *Int) Int8() int8

func (*Int) Int16

func (t *Int) Int16() int16

func (*Int) Int32

func (t *Int) Int32() int32

func (*Int) Int64

func (t *Int) Int64() int64

func (*Int) String

func (t *Int) String() string

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type Map

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

func (*Map) ArrayVal

func (t *Map) ArrayVal(key string) *embedArray

func (*Map) AtomicUpdate

func (t *Map) AtomicUpdate(v string)

func (*Map) BoolVal

func (t *Map) BoolVal(key string) *embedBool

func (*Map) Changed

func (t *Map) Changed(evt UpdateEvent)

func (*Map) FloatVal

func (t *Map) FloatVal(key string) *embedFloat

func (*Map) HasKey

func (t *Map) HasKey(key string) bool

func (*Map) IntVal

func (t *Map) IntVal(key string) *embedInt

func (*Map) Keys

func (t *Map) Keys() *embedArray

func (*Map) Len

func (t *Map) Len() int

func (*Map) MapVal

func (t *Map) MapVal(key string) *embedMap

func (*Map) String

func (t *Map) String() string

func (*Map) StringVal

func (t *Map) StringVal(key string) *embedString

func (*Map) UintVal

func (t *Map) UintVal(key string) *embedUint

type Node

type Node struct {
	TTL      time.Duration     `json:"ttl,omitempty"`
	UniqueID int64             `json:"unique_id,omitempty"`
	Service  string            `json:"service,omitempty"`
	Address  string            `json:"address,omitempty"`
	Weight   int               `json:"weight,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

func (Node) String

func (n Node) String() string

type NodeOption

type NodeOption func(*Node)

func WithNodeMetadata

func WithNodeMetadata(md map[string]string) NodeOption

func WithNodeTTL

func WithNodeTTL(ttl time.Duration) NodeOption

func WithNodeWeight

func WithNodeWeight(weight int) NodeOption

func WithOpsConfig

func WithOpsConfig() NodeOption

type Nodes

type Nodes map[string]*Node

type Option

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

Option interface sets options such as provider, autoCreation, etc.

func WithBasePath

func WithBasePath(path string) Option

func WithCallbackManger

func WithCallbackManger(mgr Callback) Option

func WithConfigAutoCreation

func WithConfigAutoCreation() Option

func WithContext

func WithContext(ctx context.Context) Option

func WithDebugProvider

func WithDebugProvider() Option

func WithEtcdProvider

func WithEtcdProvider(ctx context.Context, endPoints []string, username, password string) Option

func WithProvider

func WithProvider(provider backend.Provider) Option

type RemoteConfig

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

func New

func New(opts ...Option) (*RemoteConfig, error)

func (*RemoteConfig) GetNodes

func (rc *RemoteConfig) GetNodes(service string) Nodes

func (*RemoteConfig) RegisterConfig

func (rc *RemoteConfig) RegisterConfig(service string, v interface{}) error

func (*RemoteConfig) RegisterNode

func (rc *RemoteConfig) RegisterNode(service, nodeAddr string, opts ...NodeOption) (int64, error)

type StaticType

type StaticType interface {
	// Set value.
	Set(v string)
}

StaticType interface.

type String

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

func (*String) AtomicUpdate

func (t *String) AtomicUpdate(v string)

func (*String) Changed

func (t *String) Changed(evt UpdateEvent)

func (*String) String

func (t *String) String() string

type Uint

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

func (*Uint) AtomicUpdate

func (t *Uint) AtomicUpdate(v string)

func (*Uint) Changed

func (t *Uint) Changed(evt UpdateEvent)

func (*Uint) String

func (t *Uint) String() string

func (*Uint) Uint

func (t *Uint) Uint() uint

func (*Uint) Uint8

func (t *Uint) Uint8() uint8

func (*Uint) Uint16

func (t *Uint) Uint16() uint16

func (*Uint) Uint32

func (t *Uint) Uint32() uint32

func (*Uint) Uint64

func (t *Uint) Uint64() uint64

type UpdateEvent

type UpdateEvent func()

Directories

Path Synopsis
dashboard module

Jump to

Keyboard shortcuts

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