gconfig

package module
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 9 Imported by: 0

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(savePath string) *Config

func (*Config) GetHbase

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

func (*Config) GetKafkaAddrs

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) Unmarshal added in v2.0.2

func (c *Config) Unmarshal(value interface{}) (err error)

func (*Config) UseConsul added in v2.0.3

func (c *Config) UseConsul(config *api.Config) *Config

func (*Config) Watch

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)
	Set(keyPath string, in interface{}) (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