diff options
Diffstat (limited to 'vendor/github.com/gin-contrib/sessions')
8 files changed, 0 insertions, 762 deletions
diff --git a/vendor/github.com/gin-contrib/sessions/.gitignore b/vendor/github.com/gin-contrib/sessions/.gitignore deleted file mode 100644 index 18a5735c4..000000000 --- a/vendor/github.com/gin-contrib/sessions/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index dc3a01fb7..000000000 --- a/vendor/github.com/gin-contrib/sessions/.goreleaser.yaml +++ /dev/null @@ -1,26 +0,0 @@ -builds: - - skip: true - -changelog: - use: github - groups: - - title: Features - regexp: "^.*feat[(\\w)]*:+.*$" - order: 0 - - title: "Bug fixes" - regexp: "^.*fix[(\\w)]*:+.*$" - order: 1 - - title: "Enhancements" - regexp: "^.*chore[(\\w)]*:+.*$" - order: 2 - - title: "Refactor" - regexp: "^.*refactor[(\\w)]*:+.*$" - order: 3 - - title: "Build process updates" - regexp: ^.*?(build|ci)(\(.+\))??!?:.+$ - order: 4 - - title: "Documentation updates" - regexp: ^.*?docs?(\(.+\))??!?:.+$ - order: 4 - - title: Others - order: 999 diff --git a/vendor/github.com/gin-contrib/sessions/LICENSE b/vendor/github.com/gin-contrib/sessions/LICENSE deleted file mode 100644 index 4e2cfb015..000000000 --- a/vendor/github.com/gin-contrib/sessions/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2016 Gin-Gonic - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/gin-contrib/sessions/README.md b/vendor/github.com/gin-contrib/sessions/README.md deleted file mode 100644 index 86f4d0f9d..000000000 --- a/vendor/github.com/gin-contrib/sessions/README.md +++ /dev/null @@ -1,458 +0,0 @@ -# sessions - -[](https://github.com/gin-contrib/sessions/actions/workflows/lint.yml) -[](https://github.com/gin-contrib/sessions/actions/workflows/testing.yml) -[](https://codecov.io/gh/gin-contrib/sessions) -[](https://goreportcard.com/report/github.com/gin-contrib/sessions) -[](https://godoc.org/github.com/gin-contrib/sessions) - -Gin middleware for session management with multi-backend support: - -- [cookie-based](#cookie-based) -- [Redis](#redis) -- [memcached](#memcached) -- [MongoDB](#mongodb) -- [GORM](#gorm) -- [memstore](#memstore) -- [PostgreSQL](#postgresql) - -## Usage - -### Start using it - -Download and install it: - -```bash -go get github.com/gin-contrib/sessions -``` - -Import it in your code: - -```go -import "github.com/gin-contrib/sessions" -``` - -## Basic Examples - -### single session - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/cookie" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store := cookie.NewStore([]byte("secret")) - r.Use(sessions.Sessions("mysession", store)) - - r.GET("/hello", func(c *gin.Context) { - session := sessions.Default(c) - - if session.Get("hello") != "world" { - session.Set("hello", "world") - session.Save() - } - - c.JSON(200, gin.H{"hello": session.Get("hello")}) - }) - r.Run(":8000") -} -``` - -### multiple sessions - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/cookie" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store := cookie.NewStore([]byte("secret")) - sessionNames := []string{"a", "b"} - r.Use(sessions.SessionsMany(sessionNames, store)) - - r.GET("/hello", func(c *gin.Context) { - sessionA := sessions.DefaultMany(c, "a") - sessionB := sessions.DefaultMany(c, "b") - - if sessionA.Get("hello") != "world!" { - sessionA.Set("hello", "world!") - sessionA.Save() - } - - if sessionB.Get("hello") != "world?" { - sessionB.Set("hello", "world?") - sessionB.Save() - } - - c.JSON(200, gin.H{ - "a": sessionA.Get("hello"), - "b": sessionB.Get("hello"), - }) - }) - r.Run(":8000") -} -``` - -## Backend Examples - -### cookie-based - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/cookie" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store := cookie.NewStore([]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") -} -``` - -### Redis - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/redis" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", []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") -} -``` - -### Memcached - -#### ASCII Protocol - -```go -package main - -import ( - "github.com/bradfitz/gomemcache/memcache" - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/memcached" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store := memcached.NewStore(memcache.New("localhost:11211"), "", []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") -} -``` - -#### Binary protocol (with optional SASL authentication) - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/memcached" - "github.com/gin-gonic/gin" - "github.com/memcachier/mc" -) - -func main() { - r := gin.Default() - client := mc.NewMC("localhost:11211", "username", "password") - store := memcached.NewMemcacheStore(client, "", []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") -} -``` - -### MongoDB - -#### mgo - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/mongo/mongomgo" - "github.com/gin-gonic/gin" - "github.com/globalsign/mgo" -) - -func main() { - r := gin.Default() - session, err := mgo.Dial("localhost:27017/test") - if err != nil { - // handle err - } - - c := session.DB("").C("sessions") - 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 - -```go -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) { - 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") -} -``` - -### memstore - -```go -package main - -import ( - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/memstore" - "github.com/gin-gonic/gin" -) - -func main() { - r := gin.Default() - store := memstore.NewStore([]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") -} -``` - -### GORM - -```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" -) - -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") -} -``` diff --git a/vendor/github.com/gin-contrib/sessions/memstore/memstore.go b/vendor/github.com/gin-contrib/sessions/memstore/memstore.go deleted file mode 100644 index 8826d6dd4..000000000 --- a/vendor/github.com/gin-contrib/sessions/memstore/memstore.go +++ /dev/null @@ -1,31 +0,0 @@ -package memstore - -import ( - "github.com/gin-contrib/sessions" - "github.com/quasoft/memstore" -) - -type Store interface { - sessions.Store -} - -// Keys are defined in pairs to allow key rotation, but the common case is to set a single -// authentication key and optionally an encryption key. -// -// The first key in a pair is used for authentication and the second for encryption. The -// encryption key can be set to nil or omitted in the last pair, but the authentication key -// is required in all pairs. -// -// It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, -// if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes. -func NewStore(keyPairs ...[]byte) Store { - return &store{memstore.NewMemStore(keyPairs...)} -} - -type store struct { - *memstore.MemStore -} - -func (c *store) Options(options sessions.Options) { - c.MemStore.Options = options.ToGorillaOptions() -} diff --git a/vendor/github.com/gin-contrib/sessions/session_options_go1.10.go b/vendor/github.com/gin-contrib/sessions/session_options_go1.10.go deleted file mode 100644 index 68c880814..000000000 --- a/vendor/github.com/gin-contrib/sessions/session_options_go1.10.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build !go1.11 -// +build !go1.11 - -package sessions - -import ( - gsessions "github.com/gorilla/sessions" -) - -// Options stores configuration for a session or session store. -// Fields are a subset of http.Cookie fields. -type Options struct { - Path string - Domain string - // MaxAge=0 means no 'Max-Age' attribute specified. - // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. - // MaxAge>0 means Max-Age attribute present and given in seconds. - MaxAge int - Secure bool - HttpOnly bool -} - -func (options Options) ToGorillaOptions() *gsessions.Options { - return &gsessions.Options{ - Path: options.Path, - Domain: options.Domain, - MaxAge: options.MaxAge, - Secure: options.Secure, - HttpOnly: options.HttpOnly, - } -} diff --git a/vendor/github.com/gin-contrib/sessions/session_options_go1.11.go b/vendor/github.com/gin-contrib/sessions/session_options_go1.11.go deleted file mode 100644 index 65da33872..000000000 --- a/vendor/github.com/gin-contrib/sessions/session_options_go1.11.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:build go1.11 -// +build go1.11 - -package sessions - -import ( - "net/http" - - gsessions "github.com/gorilla/sessions" -) - -// Options stores configuration for a session or session store. -// Fields are a subset of http.Cookie fields. -type Options struct { - Path string - Domain string - // MaxAge=0 means no 'Max-Age' attribute specified. - // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. - // MaxAge>0 means Max-Age attribute present and given in seconds. - MaxAge int - Secure bool - HttpOnly bool - // rfc-draft to preventing CSRF: https://tools.ietf.org/html/draft-west-first-party-cookies-07 - // refer: https://godoc.org/net/http - // https://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/ - SameSite http.SameSite -} - -func (options Options) ToGorillaOptions() *gsessions.Options { - return &gsessions.Options{ - Path: options.Path, - Domain: options.Domain, - MaxAge: options.MaxAge, - Secure: options.Secure, - HttpOnly: options.HttpOnly, - SameSite: options.SameSite, - } -} diff --git a/vendor/github.com/gin-contrib/sessions/sessions.go b/vendor/github.com/gin-contrib/sessions/sessions.go deleted file mode 100644 index 0ef8ec414..000000000 --- a/vendor/github.com/gin-contrib/sessions/sessions.go +++ /dev/null @@ -1,152 +0,0 @@ -package sessions - -import ( - "log" - "net/http" - - "github.com/gin-gonic/gin" - "github.com/gorilla/context" - "github.com/gorilla/sessions" -) - -const ( - DefaultKey = "github.com/gin-contrib/sessions" - errorFormat = "[sessions] ERROR! %s\n" -) - -type Store interface { - sessions.Store - Options(Options) -} - -// Wraps thinly gorilla-session methods. -// Session stores the values and optional configuration for a session. -type Session interface { - // ID of the session, generated by stores. It should not be used for user data. - ID() string - // Get returns the session value associated to the given key. - Get(key interface{}) interface{} - // Set sets the session value associated to the given key. - Set(key interface{}, val interface{}) - // Delete removes the session value associated to the given key. - Delete(key interface{}) - // Clear deletes all values in the session. - Clear() - // AddFlash adds a flash message to the session. - // A single variadic argument is accepted, and it is optional: it defines the flash key. - // If not defined "_flash" is used by default. - AddFlash(value interface{}, vars ...string) - // Flashes returns a slice of flash messages from the session. - // A single variadic argument is accepted, and it is optional: it defines the flash key. - // If not defined "_flash" is used by default. - Flashes(vars ...string) []interface{} - // Options sets configuration for a session. - Options(Options) - // Save saves all sessions used during the current request. - Save() error -} - -func Sessions(name string, store Store) gin.HandlerFunc { - return func(c *gin.Context) { - s := &session{name, c.Request, store, nil, false, c.Writer} - c.Set(DefaultKey, s) - defer context.Clear(c.Request) - c.Next() - } -} - -func SessionsMany(names []string, store Store) gin.HandlerFunc { - return func(c *gin.Context) { - sessions := make(map[string]Session, len(names)) - for _, name := range names { - sessions[name] = &session{name, c.Request, store, nil, false, c.Writer} - } - c.Set(DefaultKey, sessions) - defer context.Clear(c.Request) - c.Next() - } -} - -type session struct { - name string - request *http.Request - store Store - session *sessions.Session - written bool - writer http.ResponseWriter -} - -func (s *session) ID() string { - return s.Session().ID -} - -func (s *session) Get(key interface{}) interface{} { - return s.Session().Values[key] -} - -func (s *session) Set(key interface{}, val interface{}) { - s.Session().Values[key] = val - s.written = true -} - -func (s *session) Delete(key interface{}) { - delete(s.Session().Values, key) - s.written = true -} - -func (s *session) Clear() { - for key := range s.Session().Values { - s.Delete(key) - } -} - -func (s *session) AddFlash(value interface{}, vars ...string) { - s.Session().AddFlash(value, vars...) - s.written = true -} - -func (s *session) Flashes(vars ...string) []interface{} { - s.written = true - return s.Session().Flashes(vars...) -} - -func (s *session) Options(options Options) { - s.written = true - s.Session().Options = options.ToGorillaOptions() -} - -func (s *session) Save() error { - if s.Written() { - e := s.Session().Save(s.request, s.writer) - if e == nil { - s.written = false - } - return e - } - return nil -} - -func (s *session) Session() *sessions.Session { - if s.session == nil { - var err error - s.session, err = s.store.Get(s.request, s.name) - if err != nil { - log.Printf(errorFormat, err) - } - } - return s.session -} - -func (s *session) Written() bool { - return s.written -} - -// shortcut to get session -func Default(c *gin.Context) Session { - return c.MustGet(DefaultKey).(Session) -} - -// shortcut to get session with given name -func DefaultMany(c *gin.Context, name string) Session { - return c.MustGet(DefaultKey).(map[string]Session)[name] -} |