mysqlstore

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

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

Go to latest
Published: Mar 6, 2019 License: MIT Imports: 12 Imported by: 0

README

This project is a modified fork of srinathgs/mysqlstore.

mysqlstore

Build Status

Gorilla's Session Store Implementation for MySQL.

Fixed version which is working with the current versions of Go.

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.

Example:

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() {
	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) 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