dynamodb

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const KeyName = "breaker_name"

KeyName is the name of the DynamoDB Hash Key Attribute

Variables

This section is empty.

Functions

func CreateCircuitInformationTable

func CreateCircuitInformationTable(ctx context.Context, client DynamoClient, tableName string, opts ...CreateCircuitInformationTableOption) (*ddb.CreateTableOutput, error)

CreateCircuitInformationTable is a helper for creating a table to store Circuit Breaker Information (a.k.a., circuitry.CircuitInformation) in DynamoDB

func WithDynamoBackend

func WithDynamoBackend(client DynamoClient, locker DynamoLocker, circuitInformationTableName, lockTableName string, lockOpts ...ddblock.ClientOption) circuitry.SettingsOption

WithDynamoBackend can be used to configure a circuitry.FactorySettings object to use DynamoDB as the backend.

Types

type Backend

type Backend struct {
	Client                          DynamoClient
	LockClient                      DynamoLocker
	CircuitTableName, LockTableName string
	AcquireLockOpts                 []ddblock.AcquireLockOption
	ReleaseLockOpts                 []ddblock.ReleaseLockOption
}

Backend provides the StorageBackender interface wrapper for DynamoDB support

func (*Backend) Lock

func (b *Backend) Lock(ctx context.Context, name string) (sync.Locker, error)

Lock created in DynamoDB using the LockTableName table

func (*Backend) Retrieve

func (b *Backend) Retrieve(ctx context.Context, name string) (circuitry.CircuitInformation, error)

Retrieve CircuitInformation in DynamoDB from the specified CircuitTableName table

func (*Backend) Store

Store CircuitInformation in DynamoDB in the specified CircuitTableName table

type CreateCircuitInformationTableOption

type CreateCircuitInformationTableOption func(*CreateCircuitInformationTableOptions)

CreateCircuitInformationTableOption configures the CreateCircuitInformationTable function behaviour

func CreateTableWithBillingMode

func CreateTableWithBillingMode(mode ddbtypes.BillingMode) CreateCircuitInformationTableOption

CreateTableWithBillingMode will configure the BillingMode for the new DynamoDB table

func CreateTableWithProvisionedThroughput

func CreateTableWithProvisionedThroughput(throughput *ddbtypes.ProvisionedThroughput) CreateCircuitInformationTableOption

CreateTableWithProvisionedThroughput will configure the ProvisionedThroughput for the new DynamoDB table

func CreateTableWithTags

func CreateTableWithTags(tags []ddbtypes.Tag) CreateCircuitInformationTableOption

CreateTableWithTags adds tags to the table creation call

type CreateCircuitInformationTableOptions

type CreateCircuitInformationTableOptions struct {
	BillingMode           ddbtypes.BillingMode
	ProvisionedThroughput *ddbtypes.ProvisionedThroughput
	Tags                  []ddbtypes.Tag
}

CreateCircuitInformationTableOptions has the options supported for creating the CircuitInformation table

type DynamoClient

type DynamoClient interface {
	GetItem(ctx context.Context, params *ddb.GetItemInput, optFns ...func(*ddb.Options)) (*ddb.GetItemOutput, error)
	PutItem(ctx context.Context, params *ddb.PutItemInput, optFns ...func(*ddb.Options)) (*ddb.PutItemOutput, error)
	UpdateItem(ctx context.Context, params *ddb.UpdateItemInput, optFns ...func(*ddb.Options)) (*ddb.UpdateItemOutput, error)
	DeleteItem(ctx context.Context, params *ddb.DeleteItemInput, optFns ...func(*ddb.Options)) (*ddb.DeleteItemOutput, error)
	CreateTable(ctx context.Context, params *ddb.CreateTableInput, optFns ...func(*ddb.Options)) (*ddb.CreateTableOutput, error)
}

DynamoClient defines the necessary attributes for a DynamoDB client for the purpose of testing and mocks

type DynamoLock

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

DynamoLock wraps a DynamoDB Lock from cirello.io/dynamolock/v2 in a sync.Locker interface

func (*DynamoLock) Lock

func (l *DynamoLock) Lock()

Lock does nothing as the lock has alrady been acquired at this point

func (*DynamoLock) Unlock

func (l *DynamoLock) Unlock()

Unlock releases the backend lock

type DynamoLocker

type DynamoLocker interface {
	AcquireLockWithContext(ctx context.Context, key string, opts ...ddblock.AcquireLockOption) (*ddblock.Lock, error)
	CreateTableWithContext(ctx context.Context, tableName string, opts ...ddblock.CreateTableOption) (*ddb.CreateTableOutput, error)
	ReleaseLockWithContext(ctx context.Context, lockItem *ddblock.Lock, opts ...ddblock.ReleaseLockOption) (bool, error)
}

DynamoLocker defines the necessary attributes for a DynamoDB Lock implementation

type LocalBackendError

type LocalBackendError struct {
	Err     error
	Message string
}

LocalBackendError wraps errors operating locally before speaking to the DynamoDB server

func (*LocalBackendError) Error

func (e *LocalBackendError) Error() string

func (*LocalBackendError) Unwrap

func (e *LocalBackendError) Unwrap() error

type OperationType

type OperationType int

OperationType is used to quickly identify the kind of operation the backend is performing

const (
	// OpGetItem represents the GetItem Operation
	OpGetItem OperationType = iota
	// OpUpdateItem represents the UpdateItem Operation
	OpUpdateItem
	// OpAcquireLock represents the AcquireLock Operation
	OpAcquireLock
	// OpReleaseLock represents the ReleaseLock Operation
	OpReleaseLock
	// OpCreateTable represents the CreateTable Operation
	OpCreateTable
)

func (OperationType) String

func (t OperationType) String() string

type RemoteBackendError

type RemoteBackendError struct {
	Err       error
	TableName string
	Operation OperationType
}

RemoteBackendError wraps errors from aws-sdk-v2 and the DynamoDB Client

func (*RemoteBackendError) Error

func (e *RemoteBackendError) Error() string

func (*RemoteBackendError) Unwrap

func (e *RemoteBackendError) Unwrap() error

Jump to

Keyboard shortcuts

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