Skip to content

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

License

Notifications You must be signed in to change notification settings

gernest/qlstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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