Categorygithub.com/sevennt/echo-session
modulepackage
0.0.0-20170124092948-07b36329635a
Repository: https://github.com/sevennt/echo-session.git
Documentation: pkg.go.dev

# README

echo-session

Middleware echo-session is a session support for echo.

Installation

go get github.com/ipfans/echo-session

Example

package main

import (
	"github.com/ipfans/echo-session"
	"github.com/labstack/echo"
	"github.com/labstack/echo/engine/standard"
	"github.com/labstack/echo/middleware"
)

func main() {
	serv := echo.New()
	serv.Use(middleware.Logger())
	serv.Use(middleware.Recover())
	// store := session.NewCookieStore([]byte("secret"))
	store, err := session.NewRedisStore(32, "tcp", "localhost:6379", "", []byte("secret"))
	if err != nil {
		panic(err)
	}
	serv.Use(session.Sessions("GSESSION", store))
	serv.Get("/", func(ctx echo.Context) error {
		session := session.Default(ctx)
		var count int
		v := session.Get("count")
		if v == nil {
			count = 0
		} else {
			count = v.(int)
			count += 1
		}
		session.Set("count", count)
		session.Save()
		ctx.JSON(200, map[string]interface{}{
			"visit": count,
		})
		return nil
	})
	serv.Run(standard.New(":8080"))
}

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

# Packages

No description provided by the author

# Functions

shortcut to get session.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The path argument is the directory where sessions will be saved.
size: maximum number of idle connections.
No description provided by the author

# Constants

No description provided by the author

# Structs

Options stores configuration for a session or session store.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
Session stores the values and optional configuration for a session.
No description provided by the author