couchbasestore

package module
v0.0.0-...-926989e Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2015 License: MIT Imports: 8 Imported by: 0

README

GoDoc couchbasestore

Gorilla's Session store implementation with Couchbase backend.

Gorilla's Sessions and their sessions store interface can be found at https://github.com/gorilla/sessions

Currently, this package supports storing sessions in only one bucket. In case your application demands to keep sessions in different buckets, implement a container that will have couchbasestore as the underlying struct.

Couchbasestore is NOT thread-safe.

This package is backwards compatible with the original package by Srinath. The original can be found at https://github.com/srinathgs/couchbasestore

Installation

Install this package as you would usually install any Go package.

Run go get github.com/drathier/couchbasestore from terminal. It gets installed in $GOPATH

Example

package main

import (
    "fmt"
    "github.com/couchbase/go-couchbase"
    "github.com/drathier/couchbasestore"
    "github.com/gorilla/mux"
    "net/http"
    "os"
)

// ignoring error values
var bucket, _ = couchbase.GetBucket(os.Getenv("COUCHBASE_URI"), "default", os.Getenv("COUCHBASE_BUCKET"))
var store, _ = couchbasestore.NewCouchStoreBucket(bucket, "/", 3600, []byte("secret-key"))

func foobar(w http.ResponseWriter, r *http.Request) {
    session, _ := store.Get(r, "foo") //name is the key against which a cookie is set in the HTTP header
    defer session.Save(r, w)
    session.Values["bar"] = "baz"
    fmt.Fprintf(w, "<h1>You have successfully accessed sessions.</h1>")
}

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/foo/{bar}", foobar)
    http.Handle("/", r)
    http.ListenAndServe(":8080", nil)
}

Documentation

Overview

Package couchbasestore implements the Gorilla toolkit's sessions store for couchbase. Gorilla's Sessions and their sessions store interface can be found at https://github.com/gorilla/sessions

Couchbasestore is NOT thread-safe.

This package is backwards compatible with the original package by Srinath. The original can be found at https://github.com/srinathgs/couchbasestore

Copyright 2013 Srinath. All rights Reserved. Copyright 2015 drathier. All rights Reserved. This Software is licensed under MIT license available in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var BaseRetryDuration = 50 * time.Millisecond

Duration between retries. Increases exponentially with subsequent failed attempts. Retries stop after roughly 1/2 * Retries*(Retries+1) * BaseRetryDuration.

View Source
var ErrMaxAge = errors.New("max age should be greater than zero")

MaxAge error.

View Source
var Retries = 5

Number of retries. The program that uses this package can change this.

Functions

This section is empty.

Types

type CouchStore

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

CouchStore implements the gorilla/sessions Store interface

func New

func New(bucket *couchbase.Bucket, cookiePath string, cookieMaxAge int, keyPairs ...[]byte) (*CouchStore, error)

New creates a CouchStore using an existing couchbase.Bucket.

func NewCouchStore

func NewCouchStore(endpoint string, pool string, bucket string, cookiePath string, cookieMaxAge int, keyPairs ...[]byte) (*CouchStore, error)

NewCouchStore is a backwards-compatible alias for New.

func NewFromURI

func NewFromURI(endpoint string, pool string, bucketName string, cookiePath string, cookieMaxAge int, keyPairs ...[]byte) (*CouchStore, error)

NewFromURI creates a new CouchStore with a new couchbase.Bucket.

func (*CouchStore) Close

func (c *CouchStore) Close()

Close closes the bucket used by CouchStore.

func (*CouchStore) Delete

func (c *CouchStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete deletes session from CouchStore and HTTP cookie stores.

func (*CouchStore) Get

func (c *CouchStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get Session data from CouchStore. name is the key in the cookie against which the cookie string is set.

func (*CouchStore) New

func (c *CouchStore) New(r *http.Request, name string) (*sessions.Session, error)

New creates a new session. CouchStore.Get will perform this in case there is no existing session.

func (*CouchStore) Save

func (c *CouchStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save saves the session to couchbase using bucket c.bucket.

Jump to

Keyboard shortcuts

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