Comments (8)
Gin workflow spins around gin.Context. It represents the current state and information of a HTTP request. We do not really need to integrate session management in Gin, you can use github.com/gorilla/sessions without any problem. Just set the your session store to a global variable in your Go! package and use it.
Anyway I will do research about that, it could be interesting to provide a built-in solution.
If you want to use Gin with Gorilla, use this:
import (
"net/http"
"github.com/gorilla/sessions"
"github.com/gin-gonic/gin"
)
var store = sessions.NewCookieStore([]byte("something-very-secret"))
func MyHandler(c *gin.Context) {
// Get a session. We're ignoring the error resulted from decoding an
// existing session: Get() always returns a session, even if empty.
session, _ := store.Get(c.Req, "session-name")
// Set some session values.
session.Values["foo"] = "bar"
session.Values[42] = 43
// Save it.
session.Save(c.Req, c.Writer)
}
from gin.
Thank you. It will be great if it is part of the framework. Nice work!
from gin.
@manucorporat maybe leave this to gin-contrib
, gin is a lightweight framework, I don't see why gorrilla sessions won't do the job? keeping gin open to use any library out there is a big plus. Same goes for BasicAuth
This is just me being enthusiastic about gin 😄
from gin.
I do think it is necessary to create a repository called "gin-contrib" or other names, developers then can create and submit middleware for gin.
from gin.
+1
from gin.
I will create a gin-contrib tomorrow! :)
from gin.
Hey, cool, could you please decide on #22 also before that, since this could go into the contrib packages when people use context in them.
from gin.
@manucorporat the gorilla site (http://www.gorillatoolkit.org/pkg/sessions) mentions
Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory! An easy way to do this is to wrap the top-level mux when calling http.ListenAndServe:
Gorilla stores the data using the request as a map key (https://github.com/gorilla/context/blob/master/context.go#L91-L105) using the gorilla context pkg
Here is the Gin implementation (https://github.com/gorilla/context/blob/master/context.go#L91-L105)
Gorilla context is so light weight and it's session pkg seems to be the best available, would you be interested in a pull request to use gorilla context under to hood to power context data. It appears that the Gin API would not change and then Gin gets compatibility with any middleware depending on gorilla context
from gin.
Related Issues (20)
- Does gin.Recovery() run before or after Group middleware? HOT 1
- How can i prevent a http connection to close HOT 3
- BasicAuth is not suitable for proxy auth
- Can't get status as expected from context.Status() HOT 1
- Gin Context implementation breaks context.Context contract HOT 4
- [Suggestions] Introducing an AI-powered robot to assist with daily issue and pull request (PR) tasks.
- Need c.JSON() response like behaviour for c.SSEvent() response for supporting first party clients like OpenAI SDK HOT 2
- custom time.Time type can not use bindQuery get a value. HOT 3
- configure server parameters HOT 1
- The binding:"required" tag does not seem to work for struct types HOT 3
- Is there a way to preserve order in JSON on response? HOT 1
- redirect is not success HOT 1
- I want to use shouldmindbodywith first and then use formafile, but it doesn't work right now HOT 3
- Extend the routing tree entry
- Transparent decompression for gzip, deflate, etc? HOT 1
- Custom time.Time type can not use bindQuery get a value 2 HOT 2
- http: response.Write on hijacked connection from github.com/gin-gonic/gin.(*responseWriter).Write (response_writer.go:83) HOT 1
- Suggestion: Move Print Debug to Run() functions? HOT 7
- AbortWithStatusJSON doesn't abort context HOT 2
- I translated `tree.go` into java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gin.