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 /notifications/v2?appId=&cluster=¬ifications=[...] (long polling)
GET /notifications?... (v1 alias)
GET /services/config (meta service discovery)
Index ¶
- Constants
- 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) 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 ¶
const ( DefaultAppID = "SampleApp" DefaultCluster = "default" )
Default dimensions used by the shortcut APIs (Set / Publish / Lookup).
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 and returns it. Always pair with Close (or use StartT in tests).
func (*Server) Config ¶
Config returns the live configurations of ns (Default 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) NotificationID ¶
NotificationID returns the current notification id (release sequence number) of ns (Default dimensions); 0 when never published.
func (*Server) NotificationIDWith ¶
NotificationIDWith is NotificationID for explicit (appId, cluster).
func (*Server) Publish ¶
Publish re-publishes ns (Default 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 (Default dimensions).
func (*Server) ReleaseKeyWith ¶
ReleaseKeyWith is ReleaseKey for explicit (appId, cluster).
func (*Server) Set ¶
Set publishes namespace ns (DefaultAppID/DefaultCluster) with kv. 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"]). 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.
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 pattern: start the embedded server, publish namespaces, and inspect what any Apollo client would see through the HTTP endpoints.
|
Package main demonstrates the typical miniapollo usage pattern: start the embedded server, publish namespaces, and inspect what any Apollo client would see through the HTTP endpoints. |