dynastore

package module
v0.0.0-...-28d8558 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

README

dynastore

AWS DynamoDB store for Gorilla Toolkit using AWS library. Includes support for DynamoDB's TTL feature.

Uses the official AWS library, github.com/aws/aws-sdk-go/aws

Installation
go get github.com/savaki/dynastore/...
Environment Variables

dynastore uses the common AWS environment variables:

  • AWS_DEFAULT_REGION or AWS_REGION
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

dynastore will also use AWS roles if they are available. In that case, only AWS_DEFAULT_REGION or AWS_REGION need be set.

Alternately, AWS settings can be specified using Options:

  • dynastore.AWSConfig(*aws.Config)
  • dynastore.DynamoDB(*dynamodb.DynamoDB)
Tables

dynastore provides a utility to create/delete the dynamodb table.

Create Table
dynastore -table your-table-name -read 5 -write 5 
Delete Table

Use the -delete flag to indicate the tables should be deleted instead.

dynastore -table your-table-name -delete 

Example

// Create Store
store, err := dynastore.New(dynastore.Path("/"), dynastore.HTTPOnly())
if err != nil {
  log.Fatalln(err)
}

// Get Session
session, err := store.Get(req, "session-key")
if err != nil {
  log.Fatalln(err)
}

// Add a Value
session.Values["hello"] = "world"

// Save Session
err := session.Save(req, w)
if err != nil {
  log.Fatalln(err)
}

// Delete Session
session.Options.MaxAge = -1
err := session.Save(req, w)
if err != nil {
  log.Fatalln(err)
}

Documentation

Overview

Copyright 2017 Matt Ho

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// DefaultTableName is the default table name used by the dynamodb store
	DefaultTableName = "dynastore"

	// DefaultTTLField contains the default name of the ttl field
	DefaultTTLField = "ttl"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option provides options to creating a dynastore

func AWSConfig

func AWSConfig(config *aws.Config) Option

AWSConfig allows the complete AWS configuration to be specified

func Codecs

func Codecs(codecs ...securecookie.Codec) Option

Codecs uses the specified codecs to encrypt the cookie data

func Domain

func Domain(v string) Option

Domain sets the default session option of the same name

func DynamoDB

func DynamoDB(ddb *dynamodb.DynamoDB) Option

DynamoDB allows a pre-configured dynamodb client to be supplied

func HTTPOnly

func HTTPOnly() Option

HTTPOnly sets the default session option HttpOnly; HTTP is all capped to satisfy golint

func MaxAge

func MaxAge(v int) Option

MaxAge sets the default session option of the same name

func Output

func Output(w io.Writer) Option

Output

func Path

func Path(v string) Option

Path sets the default session option of the same name

func Secure

func Secure() Option

Secure sets the default session option of the same name

func SessionOptions

func SessionOptions(options sessions.Options) Option

SessionOptions allows the default session options to be specified in a single command

func TTLField

func TTLField(ttlField string) Option

TTLField sets the field used to store the ttl value

func TableName

func TableName(tableName string) Option

TableName allows a custom table name to be specified

type Store

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

Store provides an implementation of the gorilla sessions.Store interface backed by DynamoDB

func New

func New(opts ...Option) (*Store, error)

New instantiates a new Store that implements gorilla's sessions.Store interface

func (*Store) Get

func (store *Store) Get(req *http.Request, name string) (*sessions.Session, error)

Get should return a cached session.

func (*Store) New

func (store *Store) New(req *http.Request, name string) (*sessions.Session, error)

New should create and return a new session.

Note that New should never return a nil session, even in the case of an error if using the Registry infrastructure to cache the session.

func (*Store) Save

func (store *Store) Save(req *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save should persist session to the underlying store implementation.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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