dynamocity

package module
v0.0.1-alpha-5 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

dynamocity

Dynamocity is a helpful library for doing things with DynamoDB in Go using the AWS Go SDK V2.

Rationale

From the standard go library time.RFC3339Nano documentation

The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.

Subsequently, because the existing AWS Go SDK V2 uses time.RFC3339Nano, it is not suitable to use time.Time as a Dynamo DB Sort Key in a string attribute type.

The reason why dynamocity.NanoTime exists is because it provides an implementation dynamodbattribute.Marshaler, dynamodbattribute.Unmarshaller which enforces fixed nanosecond precision when marshalling for DynamoDB, making it safe for use as a DynamoDB range key.

Prerequisites

Getting Started

Execute the following to provide an explanation of tasks that are commonly used for development.

make help

The output explains the common make targets and what they do:

    Perform common development tasks
    Usage: make [TARGET]
    Targets:
      clean     Clean removes the vendor directory, go.mod, and go.sum files
      prepare   Sets up a go.mod, go.sum and downloads all vendor dependencies
      test      Starts a dynamo local dynamo container and runs unit and integration tests

Documentation

Overview

Package dynamocity provides helpful types for working with DynamoDB

OverrideEndpointResolver is a utility resolver for replacing the endpoint for a dynamo service to use http://localhost:8000 for testing with a dynamodb-local.

Index

Constants

View Source
const FlexibleNanoFmt = time.RFC3339Nano

FlexibleNanoFmt is the standard library time.RFC3339Nano, which applies a flexible compatible nanosecond precision marshalling and unmarshalling capability. However, when marshalling the standard library time.RFC3339Nano format removes trailing zeros from the seconds field, and thus may not sort correctly once formatted.

Therefore, this format is unsafe for marshalling to dynamo or JSON if the resultant value is expected to be sortable by string.

View Source
const StrictMillisFmt = "2006-01-02T15:04:05.000Z07:00"

StrictMillisFmt applies a strict millisecond precision marshalling of a dynamocity.NanoTime. This ensures that trailing zeros are never stripped. The standard library time.RFC3339Nano format removes trailing zeros from the seconds field, and thus may not sort correctly once formatted.

Unmarshalling using StrictMillisFmt will result in errors if the string does not strictly match the RFC3339 format with millisecond precision. For example: `2006-01-02T15:04:05.000Z07:00`

View Source
const StrictNanoFmt = "2006-01-02T15:04:05.000000000Z07:00"

StrictNanoFmt applies a strict nanosecond precision marshalling of a dynamocity.NanoTime. This ensures that trailing zeros are never stripped. The standard library time.RFC3339Nano format removes trailing zeros from the seconds field, and thus may not sort correctly once formatted.

Unmarshalling using StrictNanoFmt will result in errors if the string does not strictly match the RFC3339 format with fixed nanosecond precision. For example: `2006-01-02T15:04:05.000000000Z07:00`

View Source
const StrictSecondsFmt = time.RFC3339

StrictSecondsFmt is the standard library time.RFC3339, which applies a strict second precision marshalling and unmarshalling capability.

Unmarshalling using StrictSecondsFmt will result in errors if the string does not strictly match the time.RFC3339 format. For example: `2006-01-02T15:04:05Z07:00`

Variables

This section is empty.

Functions

func BetweenEndInc

func BetweenEndInc(t, startExclusive, endInclusive time.Time) bool

BetweenEndInc will return true if this dynamocity.MillisTime is after the start and before or equal to the end

func BetweenExclusive

func BetweenExclusive(t, startExclusive, endExclusive time.Time) bool

BetweenExclusive will return true if this dynamocity.MillisTime is after the start and before to the end

func BetweenInclusive

func BetweenInclusive(t, start, end time.Time) bool

BetweenInclusive will return true if this dynamocity.MillisTime is after or equal to the start and before or equal to the end

func BetweenStartInc

func BetweenStartInc(t, startInclusive, endExclusive time.Time) bool

BetweenStartInc will return true if this dynamocity.MillisTime is after or equal to the start and before the end

func MakeEndpointResolver

func MakeEndpointResolver(services map[string]string) aws.EndpointResolver

MakeEndpointResolver is a factory function for creating an aws.EndpointResolver

Types

type MillisTime

type MillisTime time.Time

MillisTime represents a sortable strict RFC3339 Timestamp with fixed millisecond precision, making it string sortable. MillisTime implements dynamodbattribute.Marshaler, dynamodbattribute.Unmarshaller The standard library time.RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.

func (MillisTime) MarshalDynamoDBAttributeValue

func (t MillisTime) MarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

MarshalDynamoDBAttributeValue implements the dynamodb.Marshaler interface to marshal a dynamocity.MillisTime into a DynamoDB AttributeValue string value with specific millisecond precision

func (MillisTime) MarshalJSON

func (t MillisTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to marshal RFC3339 timestamps with millisecond precision

func (MillisTime) String

func (t MillisTime) String() string

String implements the fmt.Stringer interface to supply a native String representation for a value in RFC3339 Format with millisecond precision

func (MillisTime) Time

func (t MillisTime) Time() time.Time

Time is a handler func to return an instance of dynamocity.MillisTime as time.Time

func (*MillisTime) UnmarshalDynamoDBAttributeValue

func (t *MillisTime) UnmarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

UnmarshalDynamoDBAttributeValue implements the dynamodb.Unmarshaler interface to unmarshal a dynamodb.AttributeValue into a dynamocity.MillisTime. This unmarshal is flexible on millisecond precision

func (*MillisTime) UnmarshalJSON

func (t *MillisTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to marshal RFC3339 timestamps with millisecond precision

type NanoTime

type NanoTime time.Time

NanoTime represents a sortable strict RFC3339 Timestamp with fixed nanosecond precision, making it string sortable. NanoTime implements dynamodbattribute.Marshaler, dynamodbattribute.Unmarshaller The standard library time.RFC3339Nano format removes trailing zeros from the fractional seconds field and thus may not sort correctly once formatted.

func (NanoTime) MarshalDynamoDBAttributeValue

func (t NanoTime) MarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

MarshalDynamoDBAttributeValue implements the dynamodb.Marshaler interface to marshal a dynamocity.NanoTime into a DynamoDB AttributeValue string value with specific nanosecond precision

func (NanoTime) MarshalJSON

func (t NanoTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to marshal RFC3339 timestamps with nanosecond precision

func (NanoTime) String

func (t NanoTime) String() string

String implements the fmt.Stringer interface to supply a native String representation for a value in RFC3339 Format with nanosecond precision

func (NanoTime) Time

func (t NanoTime) Time() time.Time

Time is a handler func to return an instance of dynamocity.NanoTime as time.Time

func (*NanoTime) UnmarshalDynamoDBAttributeValue

func (t *NanoTime) UnmarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

UnmarshalDynamoDBAttributeValue implements the dynamodb.Unmarshaler interface to unmarshal a dynamodb.AttributeValue into a dynamocity.NanoTime. This unmarshal is flexible on nanosecond precision

func (*NanoTime) UnmarshalJSON

func (t *NanoTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to marshal RFC3339 timestamps with nanosecond precision

type OverrideEndpointResolver

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

OverrideEndpointResolver is an endpoint resolver for providing overridden endpoints for AWS services Overriding the endpoints for services is helpful for testing, including running dynamodb-local

func (*OverrideEndpointResolver) ResolveEndpoint

func (o *OverrideEndpointResolver) ResolveEndpoint(service, region string) (aws.Endpoint, error)

ResolveEndpoint implements the EndpointResolver interface which resolves an endpoint for a service endpoint id and region.

type SecondsTime

type SecondsTime time.Time

SecondsTime represents a sortable strict RFC3339 Timestamp with fixed second precision, making it string sortable. SecondsTime implements dynamodbattribute.Marshaler, dynamodbattribute.Unmarshaller specifically for the time.RFC3339 format which does not permit fractional seconds; however, once this format is marshalled it may be sorted correctly in a string value

func (SecondsTime) MarshalDynamoDBAttributeValue

func (t SecondsTime) MarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

MarshalDynamoDBAttributeValue implements the dynamodb.Marshaler interface to marshal a dynamocity.SecondsTime into a DynamoDB AttributeValue string value with specific second precision

func (SecondsTime) MarshalJSON

func (t SecondsTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to marshal RFC3339 timestamps with second precision

func (SecondsTime) String

func (t SecondsTime) String() string

String implements the fmt.Stringer interface to supply a native String representation for a value in time.RFC3339 Format with second precision

func (SecondsTime) Time

func (t SecondsTime) Time() time.Time

Time is a handler func to return an instance of dynamocity.SecondsTime as time.Time

func (*SecondsTime) UnmarshalDynamoDBAttributeValue

func (t *SecondsTime) UnmarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error

UnmarshalDynamoDBAttributeValue implements the dynamodb.Unmarshaler interface to unmarshal a dynamodb.AttributeValue into a dynamocity.SecondsTime. This unmarshal is flexible on fractional second precision

func (*SecondsTime) UnmarshalJSON

func (t *SecondsTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to marshal RFC3339 timestamps with second precision

Directories

Path Synopsis
internal
testutils
Package testutils provides utility types for supporting testing time.
Package testutils provides utility types for supporting testing time.

Jump to

Keyboard shortcuts

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