mysqlstore

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

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

Go to latest
Published: Sep 14, 2019 License: MIT Imports: 11 Imported by: 0

README

mysqlstore

This is fork base on the srinathgs/mysqlstore.

Gorilla's Session Store Implementation for MySQL

Installation

Run go get github.com/skanehira/mysqlstore from command line.

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"
  "github.com/go-sql-driver/mysql"
  "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