sqlitestore

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 9 Imported by: 0

README

sqlitestore

Gorilla's Session Store Implementation for SQLite

Installation

Run from command line:

go get github.com/michaeljs1990/sqlitestore

It gets installed in $GOPATH

Usage

NewSqliteStore takes the following paramaters

  • endpoint - A sql.Open style endpoint
  • tableName - table where sessions are to be saved. Required fields are created automatically if the table does not exist.
  • path - path for Set-Cookie header
  • maxAge
  • codecs

Internally, sqlitestore uses this SQLite driver.

e.g.,

  package main

  import (
    "fmt"
    "github.com/michaeljs1990/sqlitestore"
    "net/http"
  )

  var store *sqlitestore.SqliteStore
  func init() {
     var err error
     store, err = sqlitestore.NewSqliteStore("./database", "sessions", "/", 3600, []byte("<SecretKey>"))
     if err != nil {
         panic(err)
     } 
  }

  func sessTest(w http.ResponseWriter, r *http.Request) {
    session, err := store.Get(r, "foobar")
    session.Values["bar"] = "baz"
    session.Values["baz"] = "foo"
    err = session.Save(r, w)
    fmt.Printf("%#v\n", session)
    fmt.Println(err)
  }

func main() {
    http.HandleFunc("/", sessTest)
    http.ListenAndServe(":8080", nil)
}

Documentation

Overview

Gorilla Sessions backend for Sqlite3.

Copyright (c) 2013 Contributors. See the list of contributors in the CONTRIBUTORS file for details.

This software is licensed under a MIT style license available in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var SessionExpired error = errors.New("session expired")

Functions

This section is empty.

Types

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (Stmt, error)
	Close() error
}

type Stmt

type Stmt interface {
	Exec(args ...interface{}) (sql.Result, error)
	QueryRow(args ...interface{}) *sql.Row
	Close() error
}

Stmt is a subset of *sql.Stmt used to create the session. It allows you to pass a modified database via the DB interface for more control around databse connections. For example, you can use this to create concurrent sessions by locking database access.

type Store added in v0.2.0

type Store struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options
	// contains filtered or unexported fields
}

func NewStore

func NewStore(db DB, keyPairs ...[]byte) (*Store, error)

func (*Store) Close added in v0.2.0

func (m *Store) Close()

func (*Store) Delete added in v0.2.0

func (m *Store) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

func (*Store) Get added in v0.2.0

func (m *Store) Get(r *http.Request, name string) (*sessions.Session, error)

func (*Store) New added in v0.2.0

func (m *Store) New(r *http.Request, name string) (*sessions.Session, error)

func (*Store) Save added in v0.2.0

func (m *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Jump to

Keyboard shortcuts

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