Documentation
¶
Index ¶
- Constants
- Variables
- func GetFormat(namespace string) string
- func GetLocalIP() string
- func IsProperties(namespace string) bool
- type ApolloAPI
- type ApolloClient
- type App
- func (app *App) GetContent(namespace string) (string, error)
- func (app *App) GetItems() (Items, error)
- func (app *App) GetItemsInNamespace(namespace string) (Items, error)
- func (app *App) GetNamespaceFromApollo(namespace string) (Items, error)
- func (app *App) GetReleaseKeys() map[string]string
- func (app *App) GetValue(key string) (string, error)
- func (app *App) GetValueInNamespace(key string, namespace string) (string, error)
- func (app *App) Stop()
- func (app *App) UseCache(c Cache) *App
- func (app *App) UseClient(client ApolloAPI) *App
- func (app *App) UseLogger(l Logger) *App
- func (app *App) Watch(namespaces ...string) (<-chan Notification, <-chan error)
- type Cache
- type FileCache
- type Items
- type Logger
- type LoggerFunc
- type Lunar
- type MemoryCache
- type Namespace
- type Node
- type Notification
- type Notifications
- type Option
- type Options
Constants ¶
const ( AuthorizationFormat = "Apollo %s:%s" Delimiter = "\n" )
Variables ¶
var Printf = LoggerFunc(log.Printf)
Printf is a logger which wraps log.Printf
Functions ¶
func IsProperties ¶ added in v0.3.0
IsProperties checks if the format of namespace is properties
Types ¶
type ApolloAPI ¶
type ApolloAPI interface {
GetCachedItems(namespace string) (Items, error)
GetNamespace(namespace string, releaseKey string) (*Namespace, error)
GetNotifications(ns Notifications) (Notifications, error)
}
ApolloAPI is the interface of apollo api
type ApolloClient ¶
type ApolloClient struct {
Options // inherited options
AppID string
Client *http.Client
ClientIP string
}
ApolloClient is the implementation of apollo client.
func NewApolloClient ¶
func NewApolloClient(appID string, opts ...Option) *ApolloClient
NewApolloClient creates a apollo client
func (*ApolloClient) GetCachedItems ¶
func (c *ApolloClient) GetCachedItems(namespace string) (Items, error)
GetCachedItems gets cached configs from apollo
func (*ApolloClient) GetNamespace ¶
func (c *ApolloClient) GetNamespace(namespace string, releaseKey string) (*Namespace, error)
GetNamespace gets realtime namespace data from apollo
func (*ApolloClient) GetNotifications ¶
func (c *ApolloClient) GetNotifications(ns Notifications) (Notifications, error)
GetNotifications gets notifications from apollo
type App ¶
type App struct {
Options // inherited options
ID string // app id
Client ApolloAPI // the apollo client
Cache Cache
// contains filtered or unexported fields
}
App represents a single application, an application has a unique app id and manage multiple namespaces.
func (*App) GetContent ¶
GetContent gets the content of given namespace, if the format is properties then will return json string
func (*App) GetItemsInNamespace ¶
GetItemsInNamespace gets all the items in given namespace.
func (*App) GetNamespaceFromApollo ¶
GetNamespaceFromApollo gets realtime data in given namespace from apollo and update local cache. This is the most basic method.
func (*App) GetReleaseKeys ¶ added in v0.2.0
GetReleaseKeys gets namespace and release key map
func (*App) GetValueInNamespace ¶
GetValueInNamespace gets value of key in given namespace
type Cache ¶
type Cache interface {
GetItems(namespace string) Items
SetItems(namespace string, items Items) error
GetKeys() []string
Delete(namespace string) error
Drain()
}
Cache is the cache interface
type FileCache ¶
type FileCache struct {
AppID string
Folder string // root folder
Perm os.FileMode
// contains filtered or unexported fields
}
FileCache is cache stored in files.
func NewFileCache ¶
NewFileCache creates a FileCache
type Items ¶
Items is items under namespace
type LoggerFunc ¶
type LoggerFunc func(string, ...interface{})
LoggerFunc is a bridge between Logger and any third party logger
func (LoggerFunc) Printf ¶
func (f LoggerFunc) Printf(msg string, args ...interface{})
Printf implements Logger interface
type Lunar ¶
type Lunar interface {
GetValue(key string) (string, error)
GetValueInNamespace(key string, namespace string) (string, error)
GetItems() (Items, error)
GetItemsInNamespace(namespace string) (Items, error)
GetContent(namespace string) (string, error)
GetReleaseKeys() map[string]string // key: namespace, value: release key
}
Lunar is the interface of lunar
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is cache stored in memory, it's the default cache for use
func (*MemoryCache) Delete ¶
func (c *MemoryCache) Delete(namespace string) error
Delete deletes given namespace
func (*MemoryCache) Drain ¶ added in v0.2.0
func (c *MemoryCache) Drain()
Drain deletes the whole cache
func (*MemoryCache) GetItems ¶
func (c *MemoryCache) GetItems(namespace string) Items
GetItems gets items from cache
func (*MemoryCache) GetKeys ¶
func (c *MemoryCache) GetKeys() []string
GetKeys gets all the keys (namespaces)
type Namespace ¶
type Namespace struct {
AppID string `json:"appId"`
Cluster string `json:"cluster"`
Name string `json:"namespaceName"`
Items Items `json:"configurations"`
ReleaseKey string `json:"releaseKey"`
}
Namespace is apollo namespace data
type Node ¶ added in v0.4.0
Node is a tree node
func (*Node) AddChildren ¶ added in v0.4.0
AddChildren adds children node if it's not existing
type Notification ¶
type Notification struct {
Namespace string `json:"namespaceName"`
NotificationID int `json:"notificationId"`
}
Notification is the definition of notification
type Notifications ¶
type Notifications []Notification
Notifications is a set of notifications
func (Notifications) String ¶
func (ns Notifications) String() string
String converts Notifications to json string
type Option ¶
type Option func(*Options)
Option is for setting options
func WithAccessKeySecret ¶ added in v0.5.0
WithAccessKeySecret sets access key secret
func WithClientTimeout ¶
WithClientTimeout sets client timeout
func WithLongPollInterval ¶
WithLongPollInterval sets long poll interval