sqlitestore

package module
v0.0.0-...-4e4ca16 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 11 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 SQLite.

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

This section is empty.

Functions

This section is empty.

Types

type DB

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

type SqliteStore

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

func NewSqliteStore

func NewSqliteStore(endpoint string, tableName string, path string, maxAge int, keyPairs ...[]byte) (*SqliteStore, error)

func NewSqliteStoreFromConnection

func NewSqliteStoreFromConnection(db DB, tableName string, path string, maxAge int, keyPairs ...[]byte) (*SqliteStore, error)

func (*SqliteStore) Close

func (m *SqliteStore) Close()

func (*SqliteStore) Delete

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

func (*SqliteStore) Get

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

func (*SqliteStore) MaxLength

func (m *SqliteStore) MaxLength(l int)

func (*SqliteStore) New

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

func (*SqliteStore) Save

func (m *SqliteStore) 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