serialized

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: MIT Imports: 10 Imported by: 2

README

Serialized.io Go client

GoDoc Go Report Card License MIT

Provides access to the Serialized.io REST API.

Installation

go get github.com/marcusolsson/serialized-go

Usage

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    serialized "github.com/marcusolsson/serialized-go"
)

func main() {
    var (
        accessKey       = os.Getenv("SERIALIZED_ACCESS_KEY")
        secretAccessKey = os.Getenv("SERIALIZED_SECRET_ACCESS_KEY")
    )

    client := serialized.NewClient(
        serialized.WithAccessKey(accessKey),
        serialized.WithSecretAccessKey(secretAccessKey),
    )

    err := client.Feed(context.Background(), "order", 0, func(entry *serialized.FeedEntry) {
        for _, event := range entry.Events {
            if event.Type == "OrderPaidEvent" {
                fmt.Printf("The order with ID %s was paid\n", entry.AggregateID)
            }
        }
    })
    if err != nil {
        log.Fatal(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAggregateNotFound = errors.New("aggregate not found")

ErrAggregateNotFound is returned when no events exist for a given aggregate ID.

Functions

func WithAccessKey

func WithAccessKey(key string) func(*Client)

WithAccessKey sets the Client access key for authentication.

func WithBaseURL

func WithBaseURL(rawurl string) func(*Client)

WithBaseURL sets the Client base URL.

func WithPollInterval

func WithPollInterval(d time.Duration) func(*Client)

WithPollInterval sets the interval used for polling the API.

func WithSecretAccessKey

func WithSecretAccessKey(key string) func(*Client)

WithSecretAccessKey sets the Client secret access key for authentication.

Types

type Action

type Action struct {
	ActionType ActionType `json:"actionType,omitempty"`
	TargetURI  string     `json:"targetUri,omitempty"`
	Body       string     `json:"body,omitempty"`
}

Action defines a react action.

type ActionType

type ActionType string

ActionType represents a reaction action.

const (
	ActionTypeHTTPPost  ActionType = "HTTP_POST"
	ActionTypeSlackPost ActionType = "SLACK_POST"
)

Available action types.

type Aggregate

type Aggregate struct {
	ID      string   `json:"aggregateId"`
	Version int      `json:"aggregateVersion"`
	Type    string   `json:"aggregateType"`
	Events  []*Event `json:"events"`
}

Aggregate holds a Serialized.io Aggregate.

type Client

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

Client for the Serialized.io API.

func NewClient

func NewClient(opts ...func(*Client)) *Client

NewClient return a new Serialized.io Client.

func (*Client) AggregateExists

func (c *Client) AggregateExists(ctx context.Context, aggType, aggID string) (bool, error)

AggregateExists returns whether a specific aggregate exists.

func (*Client) AggregatedProjection

func (c *Client) AggregatedProjection(ctx context.Context, name string) (*Projection, error)

AggregatedProjection returns an aggregated projection for the given aggregate.

func (*Client) CreateProjectionDefinition

func (c *Client) CreateProjectionDefinition(ctx context.Context, d *ProjectionDefinition) error

CreateProjectionDefinition creates a new reaction definition.

func (*Client) CreateReactionDefinition

func (c *Client) CreateReactionDefinition(ctx context.Context, r *ReactionDefinition) error

CreateReactionDefinition registers a new reaction definition.

func (*Client) DeleteProjectionDefinition

func (c *Client) DeleteProjectionDefinition(ctx context.Context, name string) error

DeleteProjectionDefinition deletes a projection definition.

func (*Client) DeleteReaction

func (c *Client) DeleteReaction(ctx context.Context, id string) error

DeleteReaction deletes a reaction with a given ID.

func (*Client) Feed

func (c *Client) Feed(ctx context.Context, name string, seq int64, fn func(*FeedEntry)) error

Feed runs the given function for every feed entry. This call blocks until the provided context is cancelled.

func (*Client) FeedSequenceNumber

func (c *Client) FeedSequenceNumber(ctx context.Context, feedName string) (int64, error)

FeedSequenceNumber returns current sequence number at head for a given feed.

func (*Client) Feeds

func (c *Client) Feeds(ctx context.Context) ([]string, error)

Feeds returns all feed types.

func (*Client) ListAggregatedProjections

func (c *Client) ListAggregatedProjections(ctx context.Context) ([]*Projection, error)

ListAggregatedProjections lists all single projections.

func (*Client) ListProjectionDefinitions

func (c *Client) ListProjectionDefinitions(ctx context.Context) ([]*ProjectionDefinition, error)

ListProjectionDefinitions lists all definitions.

func (*Client) ListReactionDefinitions

func (c *Client) ListReactionDefinitions(ctx context.Context) ([]*ReactionDefinition, error)

ListReactionDefinitions returns all registered reactions.

func (*Client) ListSingleProjections

func (c *Client) ListSingleProjections(ctx context.Context, name string) ([]*Projection, error)

ListSingleProjections lists all single projections.

func (*Client) LoadAggregate

func (c *Client) LoadAggregate(ctx context.Context, aggType, aggID string) (*Aggregate, error)

LoadAggregate loads all events for a single aggregate.

func (*Client) ProjectionDefinition

func (c *Client) ProjectionDefinition(ctx context.Context, name string) (*ProjectionDefinition, error)

ProjectionDefinition returns a projection definition by name.

func (*Client) ReactionDefinition

func (c *Client) ReactionDefinition(ctx context.Context, id string) (*ReactionDefinition, error)

ReactionDefinition returns a reaction definition with a given ID.

func (*Client) SingleProjection

func (c *Client) SingleProjection(ctx context.Context, projName, aggID string) (*Projection, error)

SingleProjection returns a single projection for the given aggregate.

func (*Client) Store

func (c *Client) Store(ctx context.Context, aggType, aggID string, version int64, events ...*Event) error

Store saves events for a given aggregate. All events must refer to the same aggregate id.

type Event

type Event struct {
	ID            string          `json:"eventId"`
	Type          string          `json:"eventType"`
	Data          json.RawMessage `json:"data,omitempty"`
	EncryptedData string          `json:"encryptedData,omitempty"`
}

Event holds a Serialized.io event.

type EventHandler

type EventHandler struct {
	EventType string      `json:"eventType,omitempty"`
	Functions []*Function `json:"functions,omitempty"`
}

EventHandler contains the functions for modifying the current state of a projection.

type Feed

type Feed struct {
	Entries []*FeedEntry `json:"entries"`
	HasMore bool         `json:"hasMore"`
}

Feed holds a Serialized.io feed.

type FeedEntry

type FeedEntry struct {
	SequenceNumber int64
	AggregateID    string
	Timestamp      int64
	Events         []*Event
}

FeedEntry holds a Serialized.io feed entry.

type Function

type Function struct {
	Function       string      `json:"function,omitempty"`
	TargetSelector string      `json:"targetSelector,omitempty"`
	EventSelector  string      `json:"eventSelector,omitempty"`
	TargetFilter   string      `json:"targetFilter,omitempty"`
	EventFilter    string      `json:"eventFilter,omitempty"`
	RawData        interface{} `json:"rawData,omitempty"`
}

Function contains the templates for modifying projections.

type Projection

type Projection struct {
	ID   string          `json:"projectionId,omitempty"`
	Data json.RawMessage `json:"data,omitempty"`
}

Projection represents a model used to present your event data.

type ProjectionDefinition

type ProjectionDefinition struct {
	Name     string          `json:"projectionName,omitempty"`
	Feed     string          `json:"feedName,omitempty"`
	Handlers []*EventHandler `json:"handlers,omitempty"`
}

ProjectionDefinition contains the logic for how to build a projection.

type ReactionDefinition

type ReactionDefinition struct {
	Name               string   `json:"reactionName,omitempty"`
	Feed               string   `json:"feedName,omitempty"`
	ReactOnEventType   string   `json:"reactOnEventType,omitempty"`
	CancelOnEventTypes []string `json:"cancelOnEventTypes,omitempty"`
	TriggerTimeField   string   `json:"triggerTimeField,omitempty"`
	Offset             string   `json:"offset,omitempty"`
	Action             *Action  `json:"action,omitempty"`
}

ReactionDefinition holds a Serialized.io Reaction.

Directories

Path Synopsis
cmd
example

Jump to

Keyboard shortcuts

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