sqlxstore

package module
v0.0.0-...-f82fe66 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 12 Imported by: 0

README

sqlxstore

Gorilla's Session Store Implementation for Sqlx

Installation

Run go get github.com/mbetel/sqlxstore from command line. Gets installed in $GOPATH

Usage

NewSqlxStore 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 doesnot exist.
path - path for Set-Cookie header
maxAge 
codecs

Internally, sqlxstore uses this MySQL driver.

e.g.,

  package main

  import (
    "fmt"
    "github.com/mbetel/sqlxstore"
    "net/http"
  )

  var store *sqlxstore.SqlxStore

  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() {
    var err error
    store, err = sqlxstore.NewSqlxStore("UN:PASS@tcp(<IP>:<PORT>)/<DB>?parseTime=true&loc=Local", <tablename>, "/", 3600, []byte("<SecretKey>"))
    if err != nil {
      panic(err)
    }
    defer store.Close()

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

Documentation

Overview

Gorilla Sessions backend for MySQL.

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 SqlxStore

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

func NewSqlxStore

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

func NewSqlxStoreFromConnection

func NewSqlxStoreFromConnection(db *sqlx.DB, tableName string, path string, maxAge int, keyPairs ...[]byte) (*SqlxStore, error)

func (*SqlxStore) Cleanup

func (m *SqlxStore) Cleanup(interval time.Duration) (chan<- struct{}, <-chan struct{})

Cleanup runs a background goroutine every interval that deletes expired sessions from the database.

The design is based on https://github.com/yosssi/boltstore

func (*SqlxStore) Close

func (m *SqlxStore) Close()

func (*SqlxStore) Delete

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

func (*SqlxStore) Get

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

func (*SqlxStore) New

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

func (*SqlxStore) Save

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

func (*SqlxStore) StopCleanup

func (m *SqlxStore) StopCleanup(quit chan<- struct{}, done <-chan struct{})

StopCleanup stops the background cleanup from running.

Jump to

Keyboard shortcuts

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