Session middleware for Echo.
Find a file
2022-09-27 09:31:53 +09:00
.gitignore Initial commit 2018-05-16 09:23:49 +08:00
.travis.yml update import path 2018-06-13 15:15:27 +08:00
go.mod Fixed package import in go.mod 2022-09-27 09:31:53 +09:00
go.sum Added mod files; updated to support session/v3 and echo/v4 2022-09-26 12:22:01 +09:00
LICENSE Initial commit 2018-05-16 09:23:49 +08:00
README.md Updated README 2022-09-26 12:25:31 +09:00
session.go Added mod files; updated to support session/v3 and echo/v4 2022-09-26 12:22:01 +09:00
session_test.go Added mod files; updated to support session/v3 and echo/v4 2022-09-26 12:22:01 +09:00

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/v3"
	"github.com/labstack/echo/v4"
)

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