guldan

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2017 License: BSD-3-Clause Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Guldan Go Client

API

NewGuldanClient() *GuldanClient

创建guldan客户端实例,如果没有特殊需求,不建议使用

GetInstance() *GuldanClient

获取guldan客户端单例,没有特殊需求请使用这个方法获取实例

func (c *GuldanClient) SetAddress(address string)

设置guldan地址,默认guldan地址为国内的guldan地址,如果需要访问国外或者代理服务需要设置设置地址

func (c *GuldanClient) SetRole(role string)

设置使用该客户端的角色,默认为client,该字段将可以在webui中展示

func (c *GuldanClient) SetItemExpireInterval(interval int32)

设置每个多久和服务端同步一次配置,该配置项当且仅当使用了Watch/WatchPublic时有效,默认时间为5秒

func (c *GuldanClient) SetMissCache(interval int32)

设置不存在数据的cache时间,可以减少对远端服务器不必要的请求,默认为关闭该特性

func (c *GuldanClient) SetPrinter(printer PrintCallback)

可以通过设置printer来调试访问guldan异常,一般不需要设置

func (c *GuldanClient) Get(gid, token string, cached bool, gray bool) (string, error)

主动获取配置

参数
  • gid 你的配置唯一ID,比如"public.hello.world"
  • token 你的用户唯一Token,如果是公开的,可以传"",也可以使用GetPublic
  • cached 表示你是否会从本地cache中去该配置,如果设置成false,每次调用这个接口都将发生一次网络请求,如果设置true将会优先取本地缓存,如果缓存不存在走网络
  • gray 表示是否获取灰度配置,如果不是灰度发布,请填false
返回值
  • string 你的配置内容,如果异常或不存在或无权限,该字段为nil
  • error 异常信息,这个string字段不是nil,这个字段必然nil,反之亦然

func (c *GuldanClient) GetPublic(gid string, cached bool, gray bool) (string, error)

Get接口的拿公开配置的封装,参数以及返回同Get

func (c *GuldanClient) RawGet(gid, token string, cached bool, gray bool) (*Item, error)

Get接口的底层实现,参数同Get,返回值第一个返回值为对应的配置项结构体,没有特殊情况不推荐使用

func (c *GuldanClient) Watch(gid, token string, gray bool, notify NotifyCallback, checker CheckCallback) error

设置订阅配置变更,只有设置了Watch才会后台实时更新配置,需要注意的一点是在使用Get/GetPublic时设置了cached=true,但没有使用Watch/WatchPublic将无法实时更新本地的配置

参数
  • gid 你的配置唯一ID,比如"public.hello.world"
  • token 你的用户唯一Token,如果是公开的,可以传"",也可以使用GetPublic
  • gray 表示是否获取灰度配置,如果不是灰度发布,请填false
  • notify 配置变更回调,如果设置为nil,将不会通知你,但是依然会更新本地的配置,也就是你下次Get/GetPublic是可以获取到最新配置的
  • checker 配置内容检查器,主要用于防止有人不小心改错了配置同时又发布的情况,可以通过checker在本地验证是否符合业务的要求,如果设置为nil,将不会对检查返回的配置内容,如果不为nil,如果在该回调中返回true将会将配置缓存在本地,如果返回false,将不会在本地缓存该变更
返回值
  • error 成功该返回值为nil,否则为相关错误

func (c *GuldanClient) WatchPublic(gid string, gray bool, notify NotifyCallback, checker CheckCallback) error

Watch接口的订阅空开配置的封装,参数以及返回同Watch

func (c *GuldanClient) CachedCount() int

返回本地返回的缓存配置项数

特殊Error

特殊错误主要以下3中都是由于用户导致的 其他的error都为系统导致的 比如断网/服务端宕机之类的

ErrGuldanNotFound

表示要获取的配置不存在

ErrGuldanForbidden

表示你没有权限访问该配置或者你的token写错了

ErrGuldanBadConfigFormat

表示配置符合你的要求 只有在Watch/WatchPublic设置了参数checker的时候在notify中出现,且只有的checker返回error时会出现

Documentation

Index

Constants

View Source
const (
	GULDAN_CLIENT_VERSION                    = "0.1.5"
	GULDAN_CLIENT_ITEM_EXPIRE_INTERVAL int32 = 5
	GULDAN_DEFAULT_ADDRESS                   = "http://localhost:7888"
)
View Source
const (
	ErrGuldanNotFound        = GuldanError("not found")
	ErrGuldanForbidden       = GuldanError("forbidden")
	ErrGuldanBadConfigFormat = GuldanError("bad config format")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckCallback

type CheckCallback func(string) bool

type GuldanClient

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

func GetInstance

func GetInstance() *GuldanClient

func NewGuldanClient

func NewGuldanClient() *GuldanClient

func (*GuldanClient) CachedCount

func (c *GuldanClient) CachedCount() int

func (*GuldanClient) Get

func (c *GuldanClient) Get(gid, token string, cached bool, gray bool) (string, error)

func (*GuldanClient) GetPublic

func (c *GuldanClient) GetPublic(gid string, cached bool, gray bool) (string, error)

func (*GuldanClient) RawGet

func (c *GuldanClient) RawGet(gid, token string, cached bool, gray bool) (*Item, error)

func (*GuldanClient) SetAddress

func (c *GuldanClient) SetAddress(address string)

func (*GuldanClient) SetItemExpireInterval

func (c *GuldanClient) SetItemExpireInterval(interval int32)

func (*GuldanClient) SetMissCache

func (c *GuldanClient) SetMissCache(interval int32)

func (*GuldanClient) SetPrinter

func (c *GuldanClient) SetPrinter(printer PrintCallback)

func (*GuldanClient) SetRole

func (c *GuldanClient) SetRole(role string)

func (*GuldanClient) Watch

func (c *GuldanClient) Watch(gid, token string, gray bool, notify NotifyCallback, checker CheckCallback) error

func (*GuldanClient) WatchPublic

func (c *GuldanClient) WatchPublic(gid string, gray bool, notify NotifyCallback, checker CheckCallback) error

type GuldanError

type GuldanError string

func (GuldanError) Error

func (e GuldanError) Error() string

type Item

type Item struct {
	ID      string
	Group   string
	Project string
	Name    string
	Value   string
	Token   string
	Version string
	Gray    bool
	Checker CheckCallback
	Notify  NotifyCallback
}

type MissItem

type MissItem struct {
	Err     error
	Expired time.Time
}

func NewMissItem

func NewMissItem(err error, interval int32) *MissItem

type NotifyCallback

type NotifyCallback func(error, string, string)

type PrintCallback

type PrintCallback func(string)

Jump to

Keyboard shortcuts

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