sessions

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

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

Go to latest
Published: Jun 17, 2015 License: MIT Imports: 4 Imported by: 13

README

gin-sessions

Build Status

Session middleware for Gin.

Installation

$ go get github.com/tommy351/gin-sessions

Usage

import (
    "github.com/gin-gonic/gin"
    "github.com/tommy351/gin-sessions"
)

func main(){
    g := gin.New()
    store := sessions.NewCookieStore([]byte("secret123"))
    g.Use(sessions.Middleware("my_session", store))
    
    g.GET("/set", func(c *gin.Context){
        session := sessions.Get(c)
        session.Set("hello", "world")
        session.Save()
    })
    
    g.GET("/get", func(c *gin.Context){
        session := sessions.Get(c)
        session.Get("hello")
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(name string, store Store) gin.HandlerFunc

Middleware helps you set up a session in context

Types

type CookieStore

type CookieStore interface {
	Store
	Options(Options)
}

CookieStore stores sessions using secure cookies.

func NewCookieStore

func NewCookieStore(keyPairs ...[]byte) CookieStore

NewCookieStore creates a new CookieStore.

type Options

type Options struct {
	Path     string
	Domain   string
	MaxAge   int
	Secure   bool
	HttpOnly bool
}

Options stores configurations of a session

type Session

type Session interface {
	Get(key interface{}) interface{}
	Set(key interface{}, val interface{})
	Delete(key interface{})
	Clear()
	AddFlash(value interface{}, vars ...string)
	Flashes(vars ...string) []interface{}
	Save() error
	Options(Options)
}

Session is an interface that stores values and configurations for a session.

func Get

func Get(c *gin.Context) Session

Get returns a session in the context

type Store

type Store interface {
	sessions.Store
}

Store is an interface for custom session stores.

Jump to

Keyboard shortcuts

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