gconfig

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 5 Imported by: 3

README

gconfig 配置中心

支持存储

  • consul

使用方法

import (
	"github.com/ZR233/gconfig"
	"github.com/ZR233/gconfig/consul"
) 

db, err := consul.NewDBConsul(nil)
if err != nil {
    panic(err)
}

cfg := gconfig.NewConfig(db)
PostgreSql, err := cfg.GetPostgreSQL()
if err != nil {
    panic(err)
}
Redis, err := cfg.GetRedis()
if err != nil {
    panic(err)
}
Hbase, err := cfg.GetHbase()
if err != nil {
    panic(err)
}
Zookeeper, err := cfg.GetZookeeper()
if err != nil {
    panic(err)
}
//自定义配置
var MyConfig struct{
    Name string
    Detail string
}
configPath := "test/myconfig"
err = db.Unmarshal(configPath, &MyConfig)
if err != nil {
    panic(err)
}

Documentation

Index

Constants

View Source
const (
	Key_Postgresql = "common/postgresql"
	Key_Redis      = "common/redis"
	Key_Zookeeper  = "common/zookeeper"
	Key_Hbase      = "common/hbase"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

func NewConfig

func NewConfig(db DB) *Config

func (*Config) GetHbase

func (c *Config) GetHbase() (cfg *Hbase, err error)

func (*Config) GetKafkaAddrs added in v1.1.3

func (c *Config) GetKafkaAddrs(zkCfg *Zookeeper) (addrs []string, err error)

func (*Config) GetPostgreSQL

func (c *Config) GetPostgreSQL() (cfg *SqlCluster, err error)

func (*Config) GetRedis

func (c *Config) GetRedis() (cfg *Redis, err error)

func (*Config) GetZookeeper

func (c *Config) GetZookeeper() (cfg *Zookeeper, err error)

func (*Config) Watch added in v1.1.4

func (c *Config) Watch(onChanged func(err error)) (err error)

type DB

type DB interface {
	Unmarshal(keyPath string, o interface{}) (err error)
	Get(keyPath string) (data []byte, version uint64, err error)
	Watch(keyPath string, ValuePtr interface{}, onChanged func(err error)) (err error)
}

type Hbase

type Hbase struct {
	Thrift  string `yaml:"thrift"`
	Thrift2 string `yaml:"thrift2"`
}

type Redis

type Redis struct {
	Password   string   `yaml:"password"`
	Addrs      []string `yaml:"addrs"`
	Mastername string   `yaml:"mastername"`
	DB         int      `yaml:"-"`
}

type Sql

type Sql struct {
	Host     string `yaml:"host"`
	Password string `yaml:"password"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	DBName   string `yaml:"-"`
}

type SqlCluster

type SqlCluster struct {
	Write Sql   `yaml:"write"`
	Read  []Sql `yaml:"read"`
}

type Zookeeper

type Zookeeper struct {
	Hosts []string `yaml:"hosts"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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