clustersqlstore

package module
v0.0.0-...-0c43c58 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2016 License: MIT Imports: 12 Imported by: 0

README

GoDoc

clustersqlstore

Gorilla's Session Store Implementation for ClusterSQL - Server Fram of MySQLs

Dependency

EnumApps/clustersql (https://github.com/EnumApps/clustersql) ;

EnumApps/aerror (https://github.com/EnumApps/aerror) - for error tracing;

Run

  go get github.com/go-sql-driver/mysql 
  go get github.com/EnumApps/clustersqlstore
  go get github.com/EnumApps/aerror

Installation

Run

  go get github.com/EnumApps/clustersqlstore

from command line. Gets installed in $GOPATH

Database Config

create table with following SQL CREATE TABLE session_cluster ( id char(40) NOT NULL COMMENT '2006-01-02T15:04:05.999999999Z07:00+(00000-99999)', data longblob NOT NULL, expire_on datetime NOT NULL, modify_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=ascii;

clean up session with following SQL

  CREATE EVENT AutoDeleteOldSession
  ON SCHEDULE EVERY 1 HOUR
  ON COMPLETION PRESERVE
  DISABLE ON SLAVE
  DO DELETE LOW_PRIORITY FROM <database>.session_cluster WHERE `expire_on` < DATE_SUB(NOW(), INTERVAL 1 HOUR)

Usage

NewClusterSQLStore takes the following paramaters

driverName  - the name of pre-registered cluster drvier, see EnumApps/clustersql (https://github.com/EnumApps/clustersql) for detail
path        - path for Set-Cookie header
maxAge      - maxAge for session
codecs

Internally, clustersqlstore uses this ClusterSQL driver (not the original one; Since you may using another connection for your major data, this patched version allow multi drivers, each have a custom name).

e.g.,

  package main

  import (
    "fmt"
    "github.com/EnumApps/clustersqlstore"
    "net/http"
  )

  var store, _ = clustersqlstore.NewClusterSQLStore(<drivername>, "/", 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 ClusterSQL.

Copyright (c) 2016 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 ClusterSQLStore

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

func NewClusterSQLStore

func NewClusterSQLStore(driverName, path string, maxAge int, keyPairs ...[]byte) (*ClusterSQLStore, error)

NewClusterSQLStore return a ClusterSQLStore, driverName is the name of preregistered cluster drvier

func NewClusterSQLStoreConnection

func NewClusterSQLStoreConnection(db *sql.DB, path string, maxAge int, keyPairs ...[]byte) (*ClusterSQLStore, error)

NewClusterSQLStore return a ClusterSQLStore, db is an existing db connection

func (*ClusterSQLStore) Close

func (m *ClusterSQLStore) Close()

Close implement the Close method of session store

func (*ClusterSQLStore) Delete

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

Delete allow delete of mysql session (not exposed by gorilla sessions interface).

func (*ClusterSQLStore) Get

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

Get implement the Get method of session store

func (*ClusterSQLStore) New

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

New implement the New method of session store

func (*ClusterSQLStore) Save

Save implement the Save method of session store

Jump to

Keyboard shortcuts

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