Documentation
¶
Overview ¶
Package autoconfig contains a client for the auto-configuration streaming service.
This abstracts away the protocol details so that the Relay implementation only needs to know what environments it should add, update, or remove.
Index ¶
Constants ¶
const ( // PutEvent is the SSE event name corresponding to PutMessageData. PutEvent = "put" // PatchEvent is the SSE event name corresponding to PatchMessageData. PatchEvent = "patch" // DeleteEvent is the SSE event name corresponding to DeleteMessageData. DeleteEvent = "delete" // ReconnectEvent is the SSE event name for a message that forces a stream reconnect. ReconnectEvent = "reconnect" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeleteMessageData ¶
type DeleteMessageData struct { // Path is currently always "environments/$ENVID". Path string `json:"path"` // Version is a number that must be greater than the last known version of the environment. Version int `json:"version"` }
DeleteMessageData is the JSON data for an SSE message that removes an environment.
type MessageHandler ¶
type MessageHandler interface { // AddEnvironment is called when the stream has provided a configuration for an environment // that StreamManager has not seen before. This can happen due to either a "put" or a "patch". AddEnvironment(params envfactory.EnvironmentParams) // UpdateEnvironment is called when the stream has provided a new configuration for an // existing environment. This can happen due to either a "put" or a "patch". UpdateEnvironment(params envfactory.EnvironmentParams) // ReceivedAllEnvironments is called when StreamManager has received a "put" event and has // finished calling AddEnvironment or UpdateEnvironment for every environment in the list (and // DeleteEnvironment for any previously existing environments that are no longer in the list). // We use this at startup time to determine when Relay has acquired a complete configuration. ReceivedAllEnvironments() // DeleteEnvironment is called when an environment should be removed, due to either a "delete" // message, or a "put" that no longer contains that environment. DeleteEnvironment(id config.EnvironmentID) // KeyExpired is called when a key that was previously provided in EnvironmentParams.ExpiringSDKKey // has now expired. Relay should disconnect any clients currently using that key and reject any // future requests that use it. KeyExpired(id config.EnvironmentID, oldKey config.SDKKey) }
MessageHandler defines the methods that StreamManager will call when it receives messages from the auto-configuration stream.
type PatchMessageData ¶
type PatchMessageData struct { // Path is currently always "environments/$ENVID". Path string `json:"path"` // Data is the environment representation. Data envfactory.EnvironmentRep `json:"data"` }
PatchMessageData is the JSON data for an SSE message that adds or updates a single environment.
type PutContent ¶
type PutContent struct { // Environments is a map of environment representations. Environments map[config.EnvironmentID]envfactory.EnvironmentRep `json:"environments"` }
PutContent is the environent map within PutMessageData.
type PutMessageData ¶
type PutMessageData struct { // Path is currently always "/" for this message type. Path string `json:"path"` // Data contains the environment map. Data PutContent `json:"data"` }
PutMessageData is the JSON data for an SSE message that provides a full set of environments.
type StreamManager ¶
type StreamManager struct {
// contains filtered or unexported fields
}
StreamManager manages the auto-configuration SSE stream.
That includes managing the stream connection itself (reconnecting as needed, the same as the SDK streams), and also maintaining the last known state of information received from the stream so that it can determine whether an update is really an update (that is, checking version numbers and diffing the contents of a "put" event against the previous state).
Relay provides an implementation of the MessageHandler interface which will be called for all changes that it needs to know about.
func NewStreamManager ¶
func NewStreamManager( key config.AutoConfigKey, streamURI string, handler MessageHandler, httpConfig httpconfig.HTTPConfig, initialRetryDelay time.Duration, loggers ldlog.Loggers, ) *StreamManager
NewStreamManager creates a StreamManager, but does not start the connection.
func (*StreamManager) Close ¶
func (s *StreamManager) Close()
Close permanently shuts down the stream.
func (*StreamManager) Start ¶
func (s *StreamManager) Start() <-chan error
Start causes the StreamManager to start trying to connect to the auto-config stream. The returned channel receives nil for a successful connection, or an error if it has permanently failed.