mysqlstore

package module
Version: v0.0.0-...-9cbb942 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 11 Imported by: 22

README

mysqlstore

Gorilla's Session Store Implementation for MySQL

Installation

Run go get github.com/srinathgs/mysqlstore from command line. Gets installed in $GOPATH

Usage

NewMysqlStore 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, mysqlstore uses this MySQL driver.

e.g.,

  package main

  import (
    "fmt"
    "github.com/srinathgs/mysqlstore"
    "net/http"
  )

  var store *mysqlstore.MySQLStore

  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 = mysqlstore.NewMySQLStore("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 MySQLStore

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

func NewMySQLStore

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

func NewMySQLStoreFromConnection

func NewMySQLStoreFromConnection(db *sql.DB, tableName string, path string, maxAge int, keyPairs ...[]byte) (*MySQLStore, error)

func (*MySQLStore) Cleanup

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

func (m *MySQLStore) Close()

func (*MySQLStore) Delete

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

func (*MySQLStore) Get

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

func (*MySQLStore) New

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

func (*MySQLStore) Save

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

func (*MySQLStore) StopCleanup

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