disconf_client

package module
v0.0.0-...-7a391fe Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

README

go disconf 客户端


1.使用说明

  • 传一个结构体的指针,支持数据类型(支持int、int64、string、bool、float32、float64)

  • 支持两种tag:conf、auto

  • 支持默认参数(WithRetryTimes(3)、WithRetrySleepSeconds(5)、WithDownloadDir(./disconf/download/)、WithIgnore)

  • tag conf 是属性文件中的名称,如果加了auto:"true"表示该属性在disconf服务端更新之后,客户端会自动加载

  • example

  type Conf struct {
	UserName string `conf:"mysql.username"`
	Password string `conf:"mysql.password" auto:"true"`
	A        int    `conf:"a" auto:"true"`
	TextGBK  string `conf:"textGBK" auto:"true"`
}
conf := &Conf{UserName: "root", Password: "dsdhjhj"}
	if err := NewConf(
		"127.0.0.1",
		"disconf_demo",
		"222",
		"dev",
		true,
		false,
		conf,
		WithDownloadDir("./disconf/download/")); err != nil {
		t.Fatalf("new conf [err:%v]", err)
	}
	for {
	       fmt.Println("a", conf.Password)
	       time.Sleep(5 * time.Second)
		}

整体架构

avatar


特性
1.  支持自定义配置文件下载路径

2.  支持配置文件和配置项

3.  支持可配置的只加载本地配置

4.  不需要重启更改配置文件或配置项

5.  应用程序无感知

Documentation

Index

Constants

View Source
const (
	RETRY_TIMES          = 3
	RETRY_SLEEP_SECONDS  = 5
	DEFAULT_DOWNLOAD_DIR = "./disconf/download/"
	COMMA_SPLIT          = ","
	SUFFIX_PREFIX_URL    = "?app=%v&env=%v&version=%v"
	SUFFIX_KEY           = "&key=%v"
)
View Source
const (
	EMPTY_STRING             = ""
	PREFIX_HTTP              = "http://"
	PREFIX_HTTPS             = "https://"
	DISCONF_STORE_ACTION     = "/api/config/list"
	DISCONF_ITEM_ACTION      = "/api/config/item"
	DISCONF_FILE_ACTION      = "/api/config/file"
	DISCONF_ZOO_HOSTS_ACTION = "/api/zoo/hosts"
	STRING_TRUE              = "true"
	ZOO_SUCCESS_STATUS       = 1
)
View Source
const (
	FILE_PROPERTIES   = ".properties"
	DISCONF_TYPE_FILE = 0
	DISCONF_TYPE_ITEM = 1
	COMMA_STRING      = ","
	CONF_TAG          = "conf"
	AUTO_TAG          = "auto"
	AUTO_TRUE         = "true"
	INIT_CONF         = "initConf"
	AUTO_CONF         = "autoConf"
	STRING_STR        = "string"
	INT64_STR         = "int64"
	INT_STR           = "int"
	FLOAT32_STR       = "float32"
	BOOL_STR          = "bool"
	FLOAT64_STR       = "float64"
	ERR_TYPE_VALUE    = "unknown type"
)
View Source
const (
	RE_CONNECT_TIMES = 3
	ZK_TIMEOUT       = 5
	GO_TIMEOUT       = 3
	PORT             = "8080"
)

Variables

This section is empty.

Functions

func ContainString

func ContainString(str, content string) bool

func NewConf

func NewConf(serverHost, app, version, env string, enableRemote, debug bool, conf interface{}, opts ...ClientOption) error

Types

type Client

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

type ClientOption

type ClientOption func(*Client)

func WithDownloadDir

func WithDownloadDir(downloadDir string) ClientOption

func WithIgnore

func WithIgnore(ignore string) ClientOption

func WithRetrySleepSeconds

func WithRetrySleepSeconds(retrySleepSeconds int) ClientOption

func WithRetryTimes

func WithRetryTimes(retryTimes int) ClientOption

type Fetcher

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

type IFetcher

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

type IWatch

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

type Result

type Result struct {
	Id      int    `json:"id"`
	Genre   int    `json:"type"`
	Status  int    `json:"status"`
	Name    string `json:"name"`
	Value   string `json:"value"`
	AppId   int    `json:"appId"`
	Version string `json:"version"`
	EnvId   int    `json:"envId"`
}

type Store

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

type Watch

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

Jump to

Keyboard shortcuts

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