diff options
Diffstat (limited to 'vendor/github.com/gin-contrib')
4 files changed, 185 insertions, 34 deletions
diff --git a/vendor/github.com/gin-contrib/sessions/.gitignore b/vendor/github.com/gin-contrib/sessions/.gitignore index 5d32c7593..18a5735c4 100644 --- a/vendor/github.com/gin-contrib/sessions/.gitignore +++ b/vendor/github.com/gin-contrib/sessions/.gitignore @@ -1,3 +1,5 @@ coverage.out vendor/* !/vendor/vendor.json +/gorm/test.db +.idea diff --git a/vendor/github.com/gin-contrib/sessions/.goreleaser.yaml b/vendor/github.com/gin-contrib/sessions/.goreleaser.yaml new file mode 100644 index 000000000..aa5453cfc --- /dev/null +++ b/vendor/github.com/gin-contrib/sessions/.goreleaser.yaml @@ -0,0 +1,57 @@ +project_name: queue + +builds: + - + # If true, skip the build. + # Useful for library projects. + # Default is false + skip: true + +changelog: + # Set it to true if you wish to skip the changelog generation. + # This may result in an empty release notes on GitHub/GitLab/Gitea. + skip: false + + # Changelog generation implementation to use. + # + # Valid options are: + # - `git`: uses `git log`; + # - `github`: uses the compare GitHub API, appending the author login to the changelog. + # - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog. + # - `github-native`: uses the GitHub release notes generation API, disables the groups feature. + # + # Defaults to `git`. + use: git + + # Sorts the changelog by the commit's messages. + # Could either be asc, desc or empty + # Default is empty + sort: asc + + # Group commits messages by given regex and title. + # Order value defines the order of the groups. + # Proving no regex means all commits will be grouped under the default group. + # Groups are disabled when using github-native, as it already groups things by itself. + # + # Default is no groups. + groups: + - title: Features + regexp: "^.*feat[(\\w)]*:+.*$" + order: 0 + - title: 'Bug fixes' + regexp: "^.*fix[(\\w)]*:+.*$" + order: 1 + - title: 'Enhancements' + regexp: "^.*chore[(\\w)]*:+.*$" + order: 2 + - title: Others + order: 999 + + filters: + # Commit messages matching the regexp listed here will be removed from + # the changelog + # Default is empty + exclude: + - '^docs' + - 'CICD' + - typo diff --git a/vendor/github.com/gin-contrib/sessions/README.md b/vendor/github.com/gin-contrib/sessions/README.md index 7d5c2305a..9984794e9 100644 --- a/vendor/github.com/gin-contrib/sessions/README.md +++ b/vendor/github.com/gin-contrib/sessions/README.md @@ -13,6 +13,7 @@ Gin middleware for session management with multi-backend support: - [Redis](#redis) - [memcached](#memcached) - [MongoDB](#mongodb) +- [GoRM](#gorm) - [memstore](#memstore) - [PostgreSQL](#postgresql) @@ -249,12 +250,13 @@ func main() { ### MongoDB +#### mgo ```go package main import ( "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/mongo" + "github.com/gin-contrib/sessions/mongo/mongomgo" "github.com/gin-gonic/gin" "github.com/globalsign/mgo" ) @@ -267,7 +269,54 @@ func main() { } c := session.DB("").C("sessions") - store := mongo.NewStore(c, 3600, true, []byte("secret")) + store := mongomgo.NewStore(c, 3600, true, []byte("secret")) + r.Use(sessions.Sessions("mysession", store)) + + r.GET("/incr", func(c *gin.Context) { + session := sessions.Default(c) + var count int + v := session.Get("count") + if v == nil { + count = 0 + } else { + count = v.(int) + count++ + } + session.Set("count", count) + session.Save() + c.JSON(200, gin.H{"count": count}) + }) + r.Run(":8000") +} +``` + +#### mongo-driver +``` +package main + +import ( + "context" + "github.com/gin-contrib/sessions" + "github.com/gin-contrib/sessions/mongo/mongodriver" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +func main() { + r := gin.Default() + mongoOptions := options.Client().ApplyURI("mongodb://localhost:27017") + client, err := mongo.NewClient(mongoOptions) + if err != nil { + // handle err + } + + if err := client.Connect(context.Background()); err != nil { + // handle err + } + + c := client.Database("test").Collection("sessions") + store := mongodriver.NewStore(c, 3600, true, []byte("secret")) r.Use(sessions.Sessions("mysession", store)) r.GET("/incr", func(c *gin.Context) { @@ -322,46 +371,88 @@ func main() { } ``` +### GoRM + +[embedmd]:# (_example/gorm/main.go go) +```go +package main + +import ( + "github.com/gin-contrib/sessions" + gormsessions "github.com/gin-contrib/sessions/gorm" + "github.com/gin-gonic/gin" + "gorm.io/driver/sqlite" + "gorm.io/gorm" +) + +func main() { + db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{}) + if err != nil { + panic(err) + } + store := gormsessions.NewStore(db, true, []byte("secret")) + + r := gin.Default() + r.Use(sessions.Sessions("mysession", store)) + + r.GET("/incr", func(c *gin.Context) { + session := sessions.Default(c) + var count int + v := session.Get("count") + if v == nil { + count = 0 + } else { + count = v.(int) + count++ + } + session.Set("count", count) + session.Save() + c.JSON(200, gin.H{"count": count}) + }) + r.Run(":8000") +} +``` + ### PostgreSQL ```go package main import ( - "database/sql" - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/postgres" - "github.com/gin-gonic/gin" + "database/sql" + "github.com/gin-contrib/sessions" + "github.com/gin-contrib/sessions/postgres" + "github.com/gin-gonic/gin" ) func main() { - r := gin.Default() - db, err := sql.Open("postgres", "postgresql://username:password@localhost:5432/database") - if err != nil { - // handle err - } - - store, err := postgres.NewStore(db, []byte("secret")) - if err != nil { - // handle err - } - - r.Use(sessions.Sessions("mysession", store)) - - r.GET("/incr", func(c *gin.Context) { - session := sessions.Default(c) - var count int - v := session.Get("count") - if v == nil { - count = 0 - } else { - count = v.(int) - count++ - } - session.Set("count", count) - session.Save() - c.JSON(200, gin.H{"count": count}) - }) - r.Run(":8000") + r := gin.Default() + db, err := sql.Open("postgres", "postgresql://username:password@localhost:5432/database") + if err != nil { + // handle err + } + + store, err := postgres.NewStore(db, []byte("secret")) + if err != nil { + // handle err + } + + r.Use(sessions.Sessions("mysession", store)) + + r.GET("/incr", func(c *gin.Context) { + session := sessions.Default(c) + var count int + v := session.Get("count") + if v == nil { + count = 0 + } else { + count = v.(int) + count++ + } + session.Set("count", count) + session.Save() + c.JSON(200, gin.H{"count": count}) + }) + r.Run(":8000") } ``` diff --git a/vendor/github.com/gin-contrib/sessions/sessions.go b/vendor/github.com/gin-contrib/sessions/sessions.go index fe116e8ef..0ef8ec414 100644 --- a/vendor/github.com/gin-contrib/sessions/sessions.go +++ b/vendor/github.com/gin-contrib/sessions/sessions.go @@ -111,6 +111,7 @@ func (s *session) Flashes(vars ...string) []interface{} { } func (s *session) Options(options Options) { + s.written = true s.Session().Options = options.ToGorillaOptions() } |
