fdv2proto

package
v7.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fdv2proto defines protocol-level data types for Flag Delivery V2.

Index

Constants

View Source
const (
	// ChangeTypePut represents an object being upserted.
	ChangeTypePut = ChangeType("put")

	// ChangeTypeDelete represents an object being deleted.
	ChangeTypeDelete = ChangeType("delete")
)
View Source
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")
)
View Source
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")
)
View Source
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

func (c *ChangeSet) Changes() []Change

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.

func (*ChangeSet) Selector added in v7.8.0

func (c *ChangeSet) Selector() Selector

Selector identifies the version of the changes.

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 Error

type Error struct {
	PayloadID string `json:"payloadId"`
	Reason    string `json:"reason"`
}

Error represents an error event.

func (Error) Name

func (e Error) 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 EventName

type EventName string

EventName is the name of the event.

type Goodbye

type Goodbye struct {
	Reason      string `json:"reason"`
	Silent      bool   `json:"silent"`
	Catastrophe bool   `json:"catastrophe"`
}

Goodbye represents a goodbye event.

func (Goodbye) Name

func (g Goodbye) Name() EventName

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.

func (PutObject) Name

func (p PutObject) Name() EventName

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

func NewSelector(state string, version int) Selector

NewSelector creates a new Selector from a state string and version.

func NoSelector

func NoSelector() Selector

NoSelector returns an empty Selector.

func (Selector) IsDefined added in v7.8.0

func (s Selector) IsDefined() bool

IsDefined returns true if the Selector has a value.

func (Selector) MarshalJSON added in v7.8.0

func (s Selector) MarshalJSON() ([]byte, error)

MarshalJSON marshals a Selector to JSON.

func (Selector) Name added in v7.8.0

func (s Selector) Name() EventName

func (Selector) State

func (s Selector) State() string

State returns the state string of the Selector. This cannot be called if the Selector is nil.

func (*Selector) UnmarshalJSON

func (s *Selector) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a Selector from JSON.

func (Selector) Version

func (s Selector) Version() int

Version returns the version of the Selector. This cannot be called if the Selector is nil.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL