gsarangodb

package module
v0.0.0-...-858bd0c Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2015 License: LGPL-2.1 Imports: 5 Imported by: 0

README

Gorilla Session Arangodb

This small library will allow you to use arango db to store user sessions in a document collection.

First create the collection that you want to store the sessions in. You can use arangosh to do this:

db._create( 'sessions', {
    
    //You don't need this. Actually, make this false if you want sessions to persist across database restarts
    "isVolatile": true,

    //AllowUserKeys can be false too. This library lets arangodb to decide session keys right now by using the autogenerated _key
    //attribute. In the future maybe I'll add an option to allow creation from the library side
    "allowUserKeys": true 
}, 'document' )

Now in go code you can save sessions like so:

store, err := NewArangoDbStore(&ArangoDbOptions{
    CollectionName: "sessions", //the name of the collection from above
    Host: "http://localhost:8529", //where to connect to
    DatabaseName: "_system", //the database to use
    User: "root", //user to connect as
    Password: "",
}, []byte("secret-encryption-key-thingy"))

func (f HandlerFunc) ServeHTTP(w ResponseWriter, request *Request) {
    session, err := store.Get( request, "GO_SESS_ID" )
    // Set some session values.
    session.Values["foo"] = "bar"
    session.Values[42] = 43

    session.Save( r, w )
    //OR
    store.Save( r, w, session )
}

The session data will be stored in the collection under the "session-data" key. Sorry, no way for me to switch that key name on the fly right now.

This library also currently relies on another library I'm writing github.com/starJammer/arango. It's a REST API for arangodb written in go. Maybe in the future I will remove this dependency and only use the http package.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoOptionsSetErr = errors.New("You must provide a set of valid options")
)

Functions

This section is empty.

Types

type ArangoDbOptions

type ArangoDbOptions struct {

	//CollectionName is if you have created your own session collection. Otherwise, the "sessions" name will be used
	CollectionName string

	//Use these options if you don't already have a connection available and want to create a new one
	Host         string //http://localhost:8529 will be used if not specified
	DatabaseName string //_system will be used if not specified
	User         string //root will be used if not specified
	Password     string //root's blank password will be used if not specified

	//Set this if you already have an arango connection and want to use that instead.
	//You should still set the CollectionName unless you want to use the default "sessions" collection
	Database *arango.Database

	//Setting this will cause all other options to be ignored. This collection will be used write sessions to.
	Collection *arango.Collection

	//SessionOptions specifies options for the sessions that this store will create. See github.com/gorilla/sessions
	SessionOptions *sessions.Options
}

ArangoDbOptions holds options for the ArangoDbStore, such as connection info. It also lets you provide

type ArangoDbStore

type ArangoDbStore struct {
	Codecs []securecookie.Codec

	SessionOptions *sessions.Options
	// contains filtered or unexported fields
}

func NewArangoDbStore

func NewArangoDbStore(opts *ArangoDbOptions, keyPairs ...[]byte) (*ArangoDbStore, error)

func (*ArangoDbStore) Get

func (a *ArangoDbStore) Get(r *http.Request, name string) (*sessions.Session, error)

func (*ArangoDbStore) New

func (a *ArangoDbStore) New(r *http.Request, name string) (*sessions.Session, error)

func (*ArangoDbStore) Save

Jump to

Keyboard shortcuts

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