echosession

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

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Session middleware for Echo

Build Codecov ReportCard GoDoc License

Quick Start

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

import (
	"fmt"
	"net/http"

	"github.com/go-session/echo-session"
	"github.com/labstack/echo"
)

func main() {
	e := echo.New()

	e.Use(echosession.New())

	e.GET("/", func(ctx echo.Context) error {
		store := echosession.FromContext(ctx)
		store.Set("foo", "bar")
		err := store.Save()
		if err != nil {
			return err
		}
		return ctx.Redirect(302, "/foo")
	})

	e.GET("/foo", func(ctx echo.Context) error {
		store := echosession.FromContext(ctx)
		foo, ok := store.Get("foo")
		if !ok {
			return ctx.String(http.StatusNotFound, "not found")
		}
		return ctx.String(http.StatusOK, fmt.Sprintf("foo:%s", foo))
	})

	e.Logger.Fatal(e.Start(":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

View Source
var (
	// DefaultConfig is the default Recover middleware config.
	DefaultConfig = Config{
		Skipper:   func(_ echo.Context) bool { return false },
		StoreKey:  "github.com/go-session/echo-session/store",
		ManageKey: "github.com/go-session/echo-session/manage",
	}
)

Functions

func Destroy

func Destroy(ctx echo.Context) error

Destroy a session

func FromContext

func FromContext(ctx echo.Context) session.Store

FromContext get session storage from context

func New

func New(opt ...session.Option) echo.MiddlewareFunc

New create a session middleware

func NewWithConfig

func NewWithConfig(config Config, opt ...session.Option) echo.MiddlewareFunc

NewWithConfig create a session middleware

func Refresh

func Refresh(ctx echo.Context) (session.Store, error)

Refresh a session and return to session storage

Types

type Config

type Config struct {
	// Skipper defines a function to skip middleware.
	Skipper Skipper
	// StoreKey keys stored in the context
	StoreKey string
	// ManageKey keys stored in the context
	ManageKey string
}

Config defines the config for Session middleware.

type Skipper

type Skipper func(c echo.Context) bool

Skipper defines a function to skip middleware. Returning true skips processing the middleware.

Jump to

Keyboard shortcuts

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