gernest / qlstore

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


GoDoc Build Status Coverage Status Go Report Card

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


go get


package main

import (

	// load ql drier
	_ ""

var keyPair = [][]byte{

func main() {

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

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

	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))


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

License:MIT License


Language:Go 100.0%