Documentation
¶
Overview ¶
Package miniapollo provides an embedded Apollo configuration server for unit tests, in the spirit of miniredis: it speaks enough of the real Apollo config-service protocol that an actual Apollo client can be pointed at it.
Supported Apollo endpoints (see README for the full compatibility matrix):
GET /configs/{appId}/{cluster}/{namespace}
GET /configfiles/{appId}/{cluster}/{namespace} (k=v properties text)
GET /configfiles/json/{appId}/{cluster}/{namespace} (configurations as JSON,
agollo first-sync form)
GET /configfiles/raw/{appId}/{cluster}/{namespace} (file content as-is)
GET /notifications/v2?appId=&cluster=¬ifications=[...] (long polling)
GET /notifications?... (v1 alias)
GET /services/config (meta service discovery)
Index ¶
- type Server
- func (s *Server) Close() error
- func (s *Server) Config(ns string) (map[string]string, bool)
- func (s *Server) ConfigWith(appID, cluster, ns string) (map[string]string, bool)
- func (s *Server) Host() string
- func (s *Server) LoadDir(dir string) ([]string, error)
- func (s *Server) LoadDirWith(appID, cluster, dir string) ([]string, error)
- func (s *Server) LoadFile(file string) (string, error)
- func (s *Server) LoadFileWith(appID, cluster, file string) (string, error)
- func (s *Server) NotificationID(ns string) int64
- func (s *Server) NotificationIDWith(appID, cluster, ns string) int64
- func (s *Server) Publish(ns string)
- func (s *Server) PublishWith(appID, cluster, ns string)
- func (s *Server) ReleaseKey(ns string) (string, bool)
- func (s *Server) ReleaseKeyWith(appID, cluster, ns string) (string, bool)
- func (s *Server) Set(ns string, kv map[string]string)
- func (s *Server) SetContent(ns, content string)
- func (s *Server) SetContentWith(appID, cluster, ns, content string)
- func (s *Server) SetPollTimeout(d time.Duration)
- func (s *Server) SetWith(appID, cluster, ns string, kv map[string]string)
- func (s *Server) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the embedded Apollo configuration server. It is safe for concurrent use.
func NewServer ¶
NewServer starts a mini Apollo server listening on 127.0.0.1 with a random port. All shortcut APIs (Set / SetContent / Publish / Config / ReleaseKey / NotificationID / LoadDir / LoadFile / ...) publish under the given (appID, cluster):
m, _ := miniapollo.NewServer("shop", "dev")
m.Set("application", map[string]string{"rpc.timeout": "100"})
// served at /configs/shop/dev/application
Either value must be non-empty. Always pair with Close (or use StartT in tests).
func (*Server) Config ¶
Config returns the live configurations of ns (server's dimensions), or ok=false when it was never set. The map is a copy.
func (*Server) ConfigWith ¶
ConfigWith is Config for explicit (appId, cluster).
func (*Server) LoadDir ¶ added in v1.0.1
LoadDir publishes every recognized config file in dir as a namespace under the server's dimensions. The file's base name is the namespace name:
application.properties -> namespace "application" (parsed: key=value lines) application.yml -> namespace "application.yml" (raw file as content) application.yaml -> namespace "application.yaml" application.json -> namespace "application.json" *.txt -> namespace "<name>.txt"
Sub-directories, dot-files and files with other extensions are skipped. It returns the namespaces loaded, in sorted order. Each file is published immediately (a fresh release each), so clients polling right after LoadDir see them all — and long-pollers parked on those namespaces are woken.
m, _ := miniapollo.NewServer("shop", "dev")
ns, err := m.LoadDir("./configs") // []{"application", "layout.yml", ...}
func (*Server) LoadDirWith ¶ added in v1.0.1
LoadDirWith is LoadDir for explicit (appId, cluster).
func (*Server) LoadFile ¶ added in v1.0.1
LoadFile publishes a single config file under the server's dimensions, with the same namespace-naming rules as LoadDir. Returns the namespace the file was published as.
func (*Server) LoadFileWith ¶ added in v1.0.1
LoadFileWith is LoadFile for explicit (appId, cluster).
func (*Server) NotificationID ¶
NotificationID returns the current notification id (release sequence number) of ns (server's dimensions); 0 when never published.
func (*Server) NotificationIDWith ¶
NotificationIDWith is NotificationID for explicit (appId, cluster).
func (*Server) Publish ¶
Publish re-publishes ns (server's dimensions) without changing values: a new releaseKey and a bumped notification id, waking long pollers. Useful to simulate "edited and released again" in tests.
func (*Server) PublishWith ¶
PublishWith is Publish for explicit (appId, cluster).
func (*Server) ReleaseKey ¶
ReleaseKey returns the current releaseKey of ns (server's dimensions).
func (*Server) ReleaseKeyWith ¶
ReleaseKeyWith is ReleaseKey for explicit (appId, cluster).
func (*Server) Set ¶
Set publishes namespace ns with kv under the server's dimensions (the ones given to NewServer / StartT). It auto-publishes a new release, like a portal publish would.
func (*Server) SetContent ¶
SetContent publishes a file-type namespace from a raw string body (stored as configurations["content"]) under the server's dimensions. Use this for real YAML/JSON blobs.
func (*Server) SetContentWith ¶
SetContentWith is SetContent for explicit (appId, cluster).
func (*Server) SetPollTimeout ¶
SetPollTimeout overrides how long /notifications holds requests with no changes. Default 30s (real Apollo default). Tests usually want ~100ms.
func (*Server) SetWith ¶
SetWith publishes a namespace under explicit (appId, cluster) with kv. File-type namespaces (.yml/.yaml/.json/.txt) get their map flattened into a single "content" entry, exactly like real Apollo delivers them.
func (*Server) URL ¶
URL returns the base URL, e.g. "http://127.0.0.1:49152". Point your client's meta server / APOLLO_META here.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
agollo
command
Package main demonstrates a REAL agollo v5 client connecting to the embedded miniapollo server — no real Apollo, no docker required.
|
Package main demonstrates a REAL agollo v5 client connecting to the embedded miniapollo server — no real Apollo, no docker required. |
|
basic
command
Package main demonstrates the typical miniapollo usage patterns: start the embedded server, publish namespaces, load a config directory, and inspect what any Apollo client would see through the HTTP endpoints.
|
Package main demonstrates the typical miniapollo usage patterns: start the embedded server, publish namespaces, load a config directory, and inspect what any Apollo client would see through the HTTP endpoints. |