Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjmkznr/gin-sessions-dynamodb
A session store backend for gin-contrib/sessions
https://github.com/kjmkznr/gin-sessions-dynamodb
dynamodb gin golang
Last synced: 8 days ago
JSON representation
A session store backend for gin-contrib/sessions
- Host: GitHub
- URL: https://github.com/kjmkznr/gin-sessions-dynamodb
- Owner: kjmkznr
- License: mit
- Created: 2020-07-23T04:31:29.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-23T05:08:31.000Z (over 4 years ago)
- Last Synced: 2024-06-20T05:07:44.395Z (5 months ago)
- Topics: dynamodb, gin, golang
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gin-session-dynamodb
[![PkgGoDev](https://pkg.go.dev/badge/github.com/kjmkznr/gin-sessions-dynamodb)](https://pkg.go.dev/github.com/kjmkznr/gin-sessions-dynamodb)
[![Build Status](https://travis-ci.org/kjmkznr/gin-sessions-dynamodb.svg?branch=master)](https://travis-ci.org/kjmkznr/gin-sessions-dynamodb)A session store backend for [gin-contrib/sessions](https://github.com/gin-contrib/sessions/).
## Usage
Import it in your code:
```go
import "github.com/kjmkznr/gin-sessions-dynamodb"
```## Basic Examples
[embedmd]:# (example/main.go go)
```go
package mainimport (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
dynamodbstore "github.com/kjmkznr/gin-sessions-dynamodb"
)func main() {
r := gin.Default()
sess, err := session.NewSession(&aws.Config{
Region: aws.String("ap-northeast-1"),
})
if err != nil {
panic(err)
}ddb := dynamodb.New(sess)
store := dynamodbstore.NewStore(ddb, "SessionTable", []byte("secret"))
r.Use(sessions.Sessions("mysession", store))r.GET("/incr", func(c *gin.Context) {
sess := sessions.Default(c)
var count int
v := sess.Get("count")
if v == nil {
count = 0
} else {
count = v.(int)
count++
}
sess.Set("count", count)
err := sess.Save()
if err != nil {
println(err.Error())
}
c.JSON(200, gin.H{"count": count})
})
r.Run(":8000")
}
```## DynamoDB Table Schema
* Hash Key: session_id (S)
* Attributes
- session_data (S)
- session_expires_at (N)## Testing
```shell script
$ docker run -p 8000:8000 -d amazon/dynamodb-local:latest
$ go test
```