Documentation ¶
Index ¶
- Constants
- Variables
- func Get(key string, opts ...GetOption) string
- func Init(configServerURL, appID string, opts ...Option) (err error)
- func InitWithConfigFile(configFilePath string, opts ...Option) (err error)
- func InitWithDefaultConfigFile(opts ...Option) error
- func Start() <-chan *LongPollerError
- func Stop()
- func ToStringE(i interface{}) (string, error)
- func Watch() <-chan *ApolloResponse
- func WatchNamespace(namespace string, stop chan bool) <-chan *ApolloResponse
- type Agollo
- type ApolloClient
- type ApolloClientOption
- type ApolloResponse
- type Balancer
- type Change
- type ChangeType
- type Changes
- type Config
- type ConfigServer
- type Configurations
- type Doer
- type GetConfigServersFunc
- type GetOption
- type GetOptions
- type Header
- type Logger
- type LoggerOption
- type LongPollerError
- type Notification
- type Notifications
- type NotificationsOption
- type NotificationsOptions
- type Option
- func AccessKey(accessKey string) Option
- func AutoFetchOnCacheMiss() Option
- func BackupFile(backupFile string) Option
- func Cluster(cluster string) Option
- func ConfigServerRefreshIntervalInSecond(refreshIntervalInSecond time.Duration) Option
- func DefaultNamespace(defaultNamespace string) Option
- func EnableHeartBeat(b bool) Option
- func EnableSLB(b bool) Option
- func FailTolerantOnBackupExists() Option
- func HeartBeatInterval(i time.Duration) Option
- func LongPollerInterval(i time.Duration) Option
- func PreloadNamespaces(namespaces ...string) Option
- func WithApolloClient(c ApolloClient) Option
- func WithBalancer(b Balancer) Option
- func WithClientOptions(opts ...ApolloClientOption) Option
- func WithLogger(l Logger) Option
- type Options
- type SignatureContext
- type SignatureFunc
Constants ¶
View Source
const ( AUTHORIZATION_FORMAT = "Apollo %s:%s" DELIMITER = "\n" HTTP_HEADER_AUTHORIZATION = "Authorization" HTTP_HEADER_TIMESTAMP = "Timestamp" )
View Source
const ( // ENV_APOLLO_ACCESS_KEY 默认从环境变量中读取Apollo的AccessKey // 会被显示传入的AccessKey所覆盖 ENV_APOLLO_ACCESS_KEY = "APOLLO_ACCESS_KEY" )
Variables ¶
View Source
var (
ErrNoConfigServerAvailable = errors.New("no config server availbale")
)
Functions ¶
func InitWithConfigFile ¶
func Start ¶
func Start() <-chan *LongPollerError
func Watch ¶
func Watch() <-chan *ApolloResponse
func WatchNamespace ¶
func WatchNamespace(namespace string, stop chan bool) <-chan *ApolloResponse
Types ¶
type Agollo ¶
type Agollo interface { Start() <-chan *LongPollerError Stop() Get(key string, opts ...GetOption) string GetNameSpace(namespace string) Configurations Watch() <-chan *ApolloResponse WatchNamespace(namespace string, stop chan bool) <-chan *ApolloResponse Options() Options }
type ApolloClient ¶
type ApolloClient interface { Apply(opts ...ApolloClientOption) Notifications(configServerURL, appID, clusterName string, notifications []Notification) (int, []Notification, error) // 该接口会直接从数据库中获取配置,可以配合配置推送通知实现实时更新配置。 GetConfigsFromNonCache(configServerURL, appID, cluster, namespace string, opts ...NotificationsOption) (int, *Config, error) // 该接口会从缓存中获取配置,适合频率较高的配置拉取请求,如简单的每30秒轮询一次配置。 GetConfigsFromCache(configServerURL, appID, cluster, namespace string) (Configurations, error) // 该接口从MetaServer获取ConfigServer列表 GetConfigServers(metaServerURL, appID string) (int, []ConfigServer, error) }
func NewApolloClient ¶
func NewApolloClient(opts ...ApolloClientOption) ApolloClient
type ApolloClientOption ¶
type ApolloClientOption func(*apolloClient)
func WithAccessKey ¶ added in v1.1.12
func WithAccessKey(accessKey string) ApolloClientOption
func WithConfigType ¶
func WithConfigType(configType string) ApolloClientOption
func WithDoer ¶
func WithDoer(d Doer) ApolloClientOption
func WithIP ¶
func WithIP(ip string) ApolloClientOption
func WithSignatureFunc ¶ added in v1.2.10
func WithSignatureFunc(sf SignatureFunc) ApolloClientOption
type ApolloResponse ¶
type ApolloResponse struct { Namespace string OldValue Configurations NewValue Configurations Changes Changes Error error }
type Balancer ¶ added in v1.1.4
func NewAutoFetchBalancer ¶ added in v1.1.4
func NewRoundRobin ¶ added in v1.1.4
type Change ¶ added in v1.0.5
type Change struct { Type ChangeType Key string Value interface{} }
type ChangeType ¶ added in v1.0.5
type ChangeType string
const ( ChangeTypeAdd ChangeType = "add" ChangeTypeUpdate ChangeType = "update" ChangeTypeDelete ChangeType = "delete" )
type Changes ¶ added in v1.0.5
type Changes []Change
type Config ¶
type Config struct { AppID string `json:"appId"` // appId: "AppTest", Cluster string `json:"cluster"` // cluster: "default", NamespaceName string `json:"namespaceName"` // namespaceName: "TEST.Namespace1", Configurations Configurations `json:"configurations"` // configurations: {Name: "Foo"}, ReleaseKey string `json:"releaseKey"` // releaseKey: "20181017110222-5ce3b2da895720e8" }
type ConfigServer ¶ added in v1.1.4
type Configurations ¶
type Configurations map[string]interface{}
func GetNameSpace ¶
func GetNameSpace(namespace string) Configurations
func (Configurations) Different ¶ added in v1.0.5
func (old Configurations) Different(new Configurations) Changes
type GetConfigServersFunc ¶ added in v1.1.4
type GetConfigServersFunc func(metaServerURL, appID string) (int, []ConfigServer, error)
type GetOptions ¶
type Header ¶ added in v1.2.10
func DefaultSignatureFunc ¶ added in v1.2.10
func DefaultSignatureFunc(ctx *SignatureContext) Header
type Logger ¶
type Logger interface {
Log(kvs ...interface{})
}
func NewLogger ¶
func NewLogger(opts ...LoggerOption) Logger
type LoggerOption ¶
type LoggerOption func(*logger)
func LoggerWriter ¶
func LoggerWriter(w io.Writer) LoggerOption
type LongPollerError ¶
type Notification ¶
type Notifications ¶
type Notifications []Notification
func (Notifications) String ¶
func (n Notifications) String() string
type NotificationsOption ¶
type NotificationsOption func(*NotificationsOptions)
func ReleaseKey ¶
func ReleaseKey(releaseKey string) NotificationsOption
type NotificationsOptions ¶
type NotificationsOptions struct {
ReleaseKey string
}
type Option ¶
type Option func(*Options)
func AutoFetchOnCacheMiss ¶
func AutoFetchOnCacheMiss() Option
func BackupFile ¶
func ConfigServerRefreshIntervalInSecond ¶ added in v1.1.4
func DefaultNamespace ¶
func EnableHeartBeat ¶ added in v1.2.12
func FailTolerantOnBackupExists ¶
func FailTolerantOnBackupExists() Option
func HeartBeatInterval ¶ added in v1.2.12
func LongPollerInterval ¶
func PreloadNamespaces ¶
func WithApolloClient ¶
func WithApolloClient(c ApolloClient) Option
func WithBalancer ¶ added in v1.1.4
func WithClientOptions ¶ added in v1.2.6
func WithClientOptions(opts ...ApolloClientOption) Option
func WithLogger ¶
type Options ¶
type Options struct { AppID string // appid Cluster string // 默认的集群名称,默认:default DefaultNamespace string // Get时默认使用的命名空间,如果设置了该值,而不在PreloadNamespaces中,默认也会加入初始化逻辑中 PreloadNamespaces []string // 预加载命名空间,默认:为空 ApolloClient ApolloClient // apollo HTTP api实现 Logger Logger // 日志实现类,可以设置自定义实现或者通过NewLogger()创建并设置有效的io.Writer,默认: ioutil.Discard AutoFetchOnCacheMiss bool // 自动获取非预设以外的Namespace的配置,默认:false LongPollerInterval time.Duration // 轮训间隔时间,默认:1s BackupFile string // 备份文件存放地址,默认:.agollo FailTolerantOnBackupExists bool // 服务器连接失败时允许读取备份,默认:false Balancer Balancer // ConfigServer负载均衡 EnableSLB bool // 启用ConfigServer负载均衡 RefreshIntervalInSecond time.Duration // ConfigServer刷新间隔 ClientOptions []ApolloClientOption // 设置apollo HTTP api的配置项 EnableHeartBeat bool // 是否允许兜底检查,默认:false HeartBeatInterval time.Duration // 兜底检查间隔时间,默认:300s }
type SignatureContext ¶ added in v1.2.10
type SignatureFunc ¶ added in v1.2.10
type SignatureFunc func(ctx *SignatureContext) Header
Source Files ¶
Click to show internal directories.
Click to hide internal directories.