Skip to content

gernest/qlstore

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

qlstore

GoDoc Build Status Coverage Status Go Report Card

Implements gorilla/sessions store using embedded sql database ( ql)

installation

go get github.com/gernest/qlstore

Usage

package main

import (
	"database/sql"
	"log"
	"net/http"

	"github.com/gernest/qlstore"
	// load ql drier
	_ "github.com/cznic/ql/driver"
)

var keyPair = [][]byte{
	[]byte("ePAPW9vJv7gHoftvQTyNj5VkWB52mlza"),
	[]byte("N8SmpJ00aSpepNrKoyYxmAJhwVuKEWZD"),
}

func main() {

	db, err := sql.Open("ql-mem", "testing.db")
	if err != nil {
		log.Fatal(err)
	}

	// This is a convenient helper. It creates the session table if the table
	// doesnt exist yet.
	err = qlstore.Migrate(db)
	if err != nil {
		log.Fatal(err)
	}

	store := qlstore.NewQLStore(db, "/", 2592000, keyPair...)
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		// Get a session. We're ignoring the error resulted from decoding an
		// existing session: Get() always returns a session, even if empty.
		session, _ := store.Get(r, "session-name")
		// Set some session values.
		session.Values["foo"] = "bar"
		session.Values[42] = 43
		// Save it before we write to the response/return from the handler.
		session.Save(r, w)
	})
	log.Fatal(http.ListenAndServe(":8090", nil))
}

About

gorilla/sessions storage with embedded sql database( (ql)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages