https://github.com/go-session/gin-session
Session middleware for Gin.
https://github.com/go-session/gin-session
gin-middleware gin-session
Last synced: 6 months ago
JSON representation
Session middleware for Gin.
- Host: GitHub
- URL: https://github.com/go-session/gin-session
- Owner: go-session
- License: mit
- Created: 2018-05-09T06:51:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T11:05:05.000Z (over 3 years ago)
- Last Synced: 2025-08-13T18:49:56.880Z (11 months ago)
- Topics: gin-middleware, gin-session
- Language: Go
- Homepage: https://godoc.org/github.com/go-session/session
- Size: 8.79 KB
- Stars: 30
- Watchers: 3
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Session middleware for [Gin](https://github.com/gin-gonic/gin)
[![Build][Build-Status-Image]][Build-Status-Url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]
## Quick Start
### Download and install
```bash
$ go get -u -v github.com/go-session/gin-session
```
### Create file `server.go`
```go
package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-session/gin-session"
)
func main() {
app := gin.Default()
app.Use(ginsession.New())
app.GET("/", func(ctx *gin.Context) {
store := ginsession.FromContext(ctx)
store.Set("foo", "bar")
err := store.Save()
if err != nil {
ctx.AbortWithError(500, err)
return
}
ctx.Redirect(302, "/foo")
})
app.GET("/foo", func(ctx *gin.Context) {
store := ginsession.FromContext(ctx)
foo, ok := store.Get("foo")
if !ok {
ctx.AbortWithStatus(404)
return
}
ctx.String(http.StatusOK, "foo:%s", foo)
})
app.Run(":8080")
}
```
### Build and run
```bash
$ go build server.go
$ ./server
```
### Open in your web browser
foo:bar
## MIT License
Copyright (c) 2018 Lyric
[Build-Status-Url]: https://travis-ci.org/go-session/gin-session
[Build-Status-Image]: https://travis-ci.org/go-session/gin-session.svg?branch=master
[codecov-url]: https://codecov.io/gh/go-session/gin-session
[codecov-image]: https://codecov.io/gh/go-session/gin-session/branch/master/graph/badge.svg
[reportcard-url]: https://goreportcard.com/report/github.com/go-session/gin-session
[reportcard-image]: https://goreportcard.com/badge/github.com/go-session/gin-session
[godoc-url]: https://godoc.org/github.com/go-session/gin-session
[godoc-image]: https://godoc.org/github.com/go-session/gin-session?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg