https://github.com/kohkimakimoto/echo-session
This is session middleware for Echo, provided as an alternative implementation inspired by labstack/echo-contrib/session.
https://github.com/kohkimakimoto/echo-session
go golang labstack-echo
Last synced: 3 months ago
JSON representation
This is session middleware for Echo, provided as an alternative implementation inspired by labstack/echo-contrib/session.
- Host: GitHub
- URL: https://github.com/kohkimakimoto/echo-session
- Owner: kohkimakimoto
- License: mit
- Created: 2025-09-20T02:47:33.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-09-21T01:48:56.000Z (3 months ago)
- Last Synced: 2025-09-21T03:27:19.370Z (3 months ago)
- Topics: go, golang, labstack-echo
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Echo Session
[](https://github.com/kohkimakimoto/echo-session/actions/workflows/test.yml)
[](https://github.com/kohkimakimoto/echo-session/blob/master/LICENSE)
[](https://pkg.go.dev/github.com/kohkimakimoto/echo-session)
This is session middleware for [Echo](https://github.com/labstack/echo), provided as an alternative implementation inspired by [labstack/echo-contrib/session](https://github.com/labstack/echo-contrib/tree/master/session).
## Usage
```go
package main
import (
"fmt"
"net/http"
session "github.com/kohkimakimoto/echo-session"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.Use(session.Middleware(session.NewCookieStore([]byte("12345678901234567890123456789012"))))
e.GET("/", func(c echo.Context) error {
s := session.MustGet(c)
counter := 0
if val := s.Get("counter"); val != nil {
if count, ok := val.(int); ok {
counter = count
}
}
counter++
s.Set("counter", counter)
if err := s.Save(); err != nil {
return err
}
return c.HTML(http.StatusOK, fmt.Sprintf("Counter: %d", counter))
})
e.GET("/refresh", func(c echo.Context) error {
s := session.MustGet(c)
s.Clear()
if err := s.Save(); err != nil {
return err
}
return c.Redirect(http.StatusFound, "/")
})
e.Logger.Fatal(e.Start(":8080"))
}
```
## Author
Kohki Makimoto
## License
The MIT License (MIT)