mysqlstore

package module
v0.0.0-...-3f1cb5f Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2013 License: MIT Imports: 11 Imported by: 0

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.NewMySQLStore("UN:PASS@tcp(<IP>:<PORT>)/<DB>?parseTime=true&loc=Local", <tablename>, "/", 3600, []byte("<SecretKey>"))
  defer store.Close()

  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 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 (*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

Jump to

Keyboard shortcuts

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