Git Product home page Git Product logo

guldan-go's Introduction

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时会出现

guldan-go's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.