boltstore

package module
v0.0.2 Latest Latest
Warning

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

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

README

gorilla-boltstore

GitHub pkg.go.dev Build Status Go Report Card

A session store for gorilla sessions backed by bbolt.

License

Copyright 2020 Markus W Mahlberg

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.

Documentation

Index

Examples

Constants

View Source
const DefaultBucketname = "_boltstore_sessions"

DefaultBucketname is unsurprisingly the default name of the bucket in which the sessions are stored.

Variables

View Source
var (
	// ErrInsufficientKeys is returned by New if no key were given for encryption
	// and/or signing of the cookies.
	ErrInsufficientKeys = errors.New("No keys or keypairs were given")

	// ErrSessionNotStored is returned by Get if there was a valid session,
	// but no data was found in the database.
	ErrSessionNotStored = errors.New("session not found in store")
)

Functions

func New

func New(db *bolt.DB, opts ...SessionStoreOption) (sessions.Store, error)

New creates a new session store for gorilla/sessions backed by "go.etcd.io/bbolt". The configured bucket is also created.

Returns a new session store or nil and an error if an error occurred. If no keys were given, the error returned is ErrInsufficientKeys.

Types

type IDGeneratorFunc

type IDGeneratorFunc func(*http.Request) (string, error)

An IDGeneratorFunc is used to generate a unique session ID.

Example
package main

import (
	"fmt"
	"net/http"

	boltstore "github.com/mwmahlberg/gorilla-boltstore"
)

func main() {
	gen := boltstore.IDGeneratorFunc(func(_ *http.Request) (string, error) {
		return "foo", nil
	})
	id, _ := gen(nil)
	fmt.Println(id)
}
Output:

foo

func DefaultIDGenerator

func DefaultIDGenerator() IDGeneratorFunc

DefaultIDGenerator is the default implementation of IDGeneratorFunc. It generates a UUID V4 string.

type SessionStoreOption

type SessionStoreOption func(s *store) error

A SessionStoreOption sets parameters for the session store.

func IDGenerator

func IDGenerator(f IDGeneratorFunc) SessionStoreOption

IDGenerator sets the function that is used to generate unique IDs for each session.

By default, a UUID V4 is used to generate unique IDs.

func Keys

func Keys(keyPairs ...[]byte) SessionStoreOption

Keys sets the key pairs for encryting and signing the secure cookies set.

func SessionBucket

func SessionBucket(name string) SessionStoreOption

SessionBucket sets the name of the boltdb bucket in which the sessions are stored.

func SessionOptions

func SessionOptions(options *sessions.Options) SessionStoreOption

SessionOptions sets the options for the sessions.

Jump to

Keyboard shortcuts

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