Documentation
¶
Overview ¶
Package fdv2proto defines protocol-level data types for Flag Delivery V2.
Index ¶
- Constants
- func ToStorableItems(deltas []Change) ([]ldstoretypes.Collection, error)
- type Change
- type ChangeSet
- type ChangeSetBuilder
- func (c *ChangeSetBuilder) AddDelete(kind ObjectKind, key string, version int)
- func (c *ChangeSetBuilder) AddPut(kind ObjectKind, key string, version int, object json.RawMessage)
- func (c *ChangeSetBuilder) Finish(selector Selector) (*ChangeSet, error)
- func (c *ChangeSetBuilder) NoChanges() *ChangeSet
- func (c *ChangeSetBuilder) Reset()
- func (c *ChangeSetBuilder) Start(intent ServerIntent) error
- type ChangeType
- type DeleteObject
- type Error
- type Event
- type EventName
- type Goodbye
- type IntentCode
- type ObjectKind
- type Payload
- type PollingPayload
- type PutObject
- type RawEvent
- type Selector
- type ServerIntent
Constants ¶
const ( // ChangeTypePut represents an object being upserted. ChangeTypePut = ChangeType("put") // ChangeTypeDelete represents an object being deleted. ChangeTypeDelete = ChangeType("delete") )
const ( // IntentTransferFull means the server intends to send a full data set. IntentTransferFull = IntentCode("xfer-full") // IntentTransferChanges means the server intends to send only the necessary changes to bring // an existing data set up-to-date. IntentTransferChanges = IntentCode("xfer-changes") // IntentNone means the server intends to send no data (payload is up to date). IntentNone = IntentCode("none") )
const ( // EventPutObject specifies that an object should be added to the data set with upsert semantics. EventPutObject = EventName("put-object") // EventDeleteObject specifies that an object should be removed from the data set. EventDeleteObject = EventName("delete-object") // EventServerIntent specifies the server's intent. EventServerIntent = EventName("server-intent") // EventPayloadTransferred specifies that that all data required to bring the existing data set to // a new version has been transferred. EventPayloadTransferred = EventName("payload-transferred") // EventHeartbeat keeps the connection alive. EventHeartbeat = EventName("heart-beat") // EventGoodbye specifies that the server is about to close the connection. EventGoodbye = EventName("goodbye") // EventError specifies that an error occurred while serving the connection. EventError = EventName("error") )
const ( // FlagKind is a flag. FlagKind = ObjectKind("flag") // SegmentKind is a segment. SegmentKind = ObjectKind("segment") )
Variables ¶
This section is empty.
Functions ¶
func ToStorableItems ¶
func ToStorableItems(deltas []Change) ([]ldstoretypes.Collection, error)
ToStorableItems converts a list of FDv2 events to a list of collections suitable for insertion into a data store.
Types ¶
type Change ¶ added in v7.8.0
type Change struct {
Action ChangeType
Kind ObjectKind
Key string
Version int
Object json.RawMessage
}
Change represents a change to a piece of data, such as an update or deletion.
type ChangeSet ¶ added in v7.8.0
type ChangeSet struct {
// contains filtered or unexported fields
}
ChangeSet represents a list of changes to be applied.
func (*ChangeSet) Changes ¶ added in v7.8.0
Changes returns the individual changes that should be applied according to the intent.
func (*ChangeSet) IntentCode ¶ added in v7.8.0
func (c *ChangeSet) IntentCode() IntentCode
IntentCode represents the intent of the changeset.
type ChangeSetBuilder ¶ added in v7.8.0
type ChangeSetBuilder struct {
// contains filtered or unexported fields
}
ChangeSetBuilder is a helper for constructing a ChangeSet.
func NewChangeSetBuilder ¶ added in v7.8.0
func NewChangeSetBuilder() *ChangeSetBuilder
NewChangeSetBuilder creates a new ChangeSetBuilder, which is empty by default.
func (*ChangeSetBuilder) AddDelete ¶ added in v7.8.0
func (c *ChangeSetBuilder) AddDelete(kind ObjectKind, key string, version int)
AddDelete adds a deletion to the changeset.
func (*ChangeSetBuilder) AddPut ¶ added in v7.8.0
func (c *ChangeSetBuilder) AddPut(kind ObjectKind, key string, version int, object json.RawMessage)
AddPut adds a new object to the changeset.
func (*ChangeSetBuilder) Finish ¶ added in v7.8.0
func (c *ChangeSetBuilder) Finish(selector Selector) (*ChangeSet, error)
Finish identifies a changeset with a selector, and returns the completed changeset. It clears any existing changes, while preserving the current intent, so that the builder can be reused.
func (*ChangeSetBuilder) NoChanges ¶ added in v7.8.0
func (c *ChangeSetBuilder) NoChanges() *ChangeSet
NoChanges represents an intent that the current data is up-to-date and doesn't require changes.
func (*ChangeSetBuilder) Reset ¶ added in v7.9.0
func (c *ChangeSetBuilder) Reset()
Reset clears any existing changes, while preserving the current intent.
func (*ChangeSetBuilder) Start ¶ added in v7.8.0
func (c *ChangeSetBuilder) Start(intent ServerIntent) error
Start begins a new change set with a given intent.
type ChangeType ¶ added in v7.8.0
type ChangeType string
ChangeType specifies if an object is being upserted or deleted.
type DeleteObject ¶
type DeleteObject struct {
Version int `json:"version"`
Kind ObjectKind `json:"kind"`
Key string `json:"key"`
}
DeleteObject specifies the deletion of a particular object.
func (DeleteObject) Name ¶
func (d DeleteObject) Name() EventName
type Event ¶
type Event interface {
// Name returns the name of the event.
Name() EventName
}
Event represents an event that can be sent by the server.
type Goodbye ¶
type Goodbye struct {
Reason string `json:"reason"`
Silent bool `json:"silent"`
Catastrophe bool `json:"catastrophe"`
}
Goodbye represents a goodbye event.
type IntentCode ¶
type IntentCode string
IntentCode represents the various intents that can be sent by the server.
type ObjectKind ¶
type ObjectKind string
ObjectKind represents the kind of object.
func (ObjectKind) ToFDV1 ¶
func (o ObjectKind) ToFDV1() (datakinds.DataKindInternal, bool)
ToFDV1 converts the object kind to an FDv1 data kind. If there is no equivalent, it returns an ErrUnknownKind.
type Payload ¶
type Payload struct {
// It would be nice if we had the same value available in both so we could
// use that as the key consistently throughout the the process.
ID string `json:"id"`
Target int `json:"target"`
Code IntentCode `json:"code"`
Reason string `json:"reason"`
}
Payload represents a payload delivered in a streaming response.
type PollingPayload ¶
type PollingPayload struct {
// Note: the first event in a PollingPayload should be a Payload.
Events []RawEvent `json:"events"`
}
PollingPayload represents a payload that is delivered in a polling response.
type PutObject ¶
type PutObject struct {
Version int `json:"version"`
Kind ObjectKind `json:"kind"`
Key string `json:"key"`
Object json.RawMessage `json:"object"`
}
PutObject specifies the addition of a particular object with upsert semantics.
type RawEvent ¶
type RawEvent struct {
Name EventName `json:"name"`
Data json.RawMessage `json:"data"`
}
RawEvent is a partially deserialized event that allows the the event name to be extracted before the rest of the event is deserialized.
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector represents a particular snapshot of data.
func NewSelector ¶
NewSelector creates a new Selector from a state string and version.
func (Selector) MarshalJSON ¶ added in v7.8.0
MarshalJSON marshals a Selector to JSON.
func (Selector) State ¶
State returns the state string of the Selector. This cannot be called if the Selector is nil.
func (*Selector) UnmarshalJSON ¶
UnmarshalJSON unmarshals a Selector from JSON.
type ServerIntent ¶
type ServerIntent struct {
Payload Payload
}
ServerIntent represents the server's intent.
func (ServerIntent) MarshalJSON ¶ added in v7.8.0
func (s ServerIntent) MarshalJSON() ([]byte, error)
MarshalJSON marshals a ServerIntent to JSON. The intent object has only one payload but the protocol allows for >= 1, so this creates an array.
func (ServerIntent) Name ¶
func (ServerIntent) Name() EventName
func (*ServerIntent) UnmarshalJSON ¶ added in v7.8.0
func (s *ServerIntent) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a ServerIntent from JSON. The intent is required to have at least one payload (at index 0) at this time.