fdv2proto

package
v7.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 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 (
	// 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(events []Event) []ldstoretypes.Collection

ToStorableItems converts a list of FDv2 events to a list of collections suitable for insertion into a data store.

Types

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 ErrUnknownKind

type ErrUnknownKind struct {
	// contains filtered or unexported fields
}

ErrUnknownKind represents that a given ObjectKind had no FDv1 equivalent DataKind.

func (*ErrUnknownKind) Error

func (e *ErrUnknownKind) Error() string

func (*ErrUnknownKind) Is

func (e *ErrUnknownKind) Is(err error) bool

Is returns true if the error is an ErrUnknownKind.

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

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 PayloadTransferred

type PayloadTransferred struct {
	State   string `json:"state"`
	Version int    `json:"version"`
}

PayloadTransferred represents the fact that all payload objects have been sent.

func (PayloadTransferred) Name

func (p PayloadTransferred) Name() EventName

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  any        `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 a nil Selector, representing the lack of one. It is here only for readability at call sites.

func (*Selector) IsSet

func (s *Selector) IsSet() bool

IsSet returns true if the Selector is not nil.

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 {
	// Payloads is a list of payloads, defined to be at least length 1.
	Payloads []Payload `json:"payloads"`
}

ServerIntent represents the server's intent.

func (ServerIntent) Name

func (ServerIntent) Name() EventName

Jump to

Keyboard shortcuts

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