couchbasestore

package module
v0.0.0-...-20f656c Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2013 License: MIT Imports: 7 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 here

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.

Installation

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

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

Example

package main
import (
    "fmt"
    "net/http"
    "github.com/srinathgs/couchbasestore"
    "github.com/gorilla/mux"
)

var store, _ = couchbasestore.NewCouchStore("http://[<username>]:[<password>]@<ip>:<port>","<poolname>",
                                          "<bucketname>","/",3600,[]byte("secret-key"))
func foobar(w http.ResponseWriter, r *http.Request){
  session,err := 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(":8081",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 [here](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.

package main
import (
    "fmt"
    "net/http"
    "github.com/srinathgs/couchbasestore"
    "github.com/gorilla/mux"
)

var store, _ = couchbasestore.NewCouchStore("http://[<username>]:[<password>]@<ip>:<port>","<poolname>",
                                          "<bucketname>","/",3600,[]byte("secret-key"))
func foobar(w http.ResponseWriter, r *http.Request){
  session,err := 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(":8081",nil)
}

Index

Constants

This section is empty.

Variables

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

MaxAge Error.

View Source
var Retries = 5

No. 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 Definition

func NewCouchStore

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

NewCouchStore creates a new CouchStore.

func (*CouchStore) Close

func (c *CouchStore) Close()

Close CouchStore

func (*CouchStore) Delete

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

Delete session from CouchStore and HTTP cookie

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 Session

Jump to

Keyboard shortcuts

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