gearsession

package module
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: MIT Imports: 4 Imported by: 0

README

Session middleware for Gear

Build Codecov ReportCard GoDoc License

Quick Start

Download and install
$ go get -u -v github.com/go-session/gear-session
Create file server.go
package main

import (
	"fmt"
	"net/http"

	"github.com/go-session/gear-session"
	"github.com/teambition/gear"
	"github.com/go-session/session"
)

func main() {
	app := gear.New()
	app.Use(gearsession.New())

	router := gear.NewRouter()

	router.Get("/", func(ctx *gear.Context) error {
		store := gearsession.FromContext(ctx)
		store.Set("foo", "bar")
		err := store.Save()
		if err != nil {
			return gear.ErrInternalServerError.From(err)
		}
		return ctx.Redirect("/foo")
	})

	router.Get("/foo", func(ctx *gear.Context) error {
		store := gearsession.FromContext(ctx)
		foo, ok := store.Get("foo")
		if !ok {
			return gear.ErrNotFound
		}
		return ctx.End(http.StatusOK, []byte(fmt.Sprintf("foo:%s", foo)))
	})
	app.UseHandler(router)

	app.Listen(":8080")
}
Build and run
$ go build server.go
$ ./server
Open in your web browser

http://localhost:8080

foo:bar

MIT License

Copyright (c) 2018 Lyric

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Destroy

func Destroy(ctx *gear.Context) error

Destroy a session

func FromContext

func FromContext(ctx *gear.Context) session.Store

FromContext get session storage from context

func New

func New(opt ...session.Option) gear.Middleware

New create a session middleware

func Refresh

func Refresh(ctx *gear.Context) (session.Store, error)

Refresh a session and return to session storage

Types

This section is empty.

Jump to

Keyboard shortcuts

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