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 ¶
- Variables
- type CouchStore
- func (c *CouchStore) Close()
- func (c *CouchStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (c *CouchStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (c *CouchStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (c *CouchStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Constants ¶
This section is empty.
Variables ¶
var ErrMaxAge = errors.New("max age should be greater than zero")
MaxAge Error.
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) 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 ¶
Get Session data from CouchStore. name is the key in the cookie against which the cookie string is set.
func (*CouchStore) New ¶
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