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)
- ctx.Keys is overwritten by obj in methods like ctx.HTML HOT 2
- Gin SetMode not Passing Value to Function, Cause Panic Error On Minikube/Microk8s HOT 4
- [GIN-debug] [WARNING] Headers were already written. Wanted to override status code 200 with 500 HOT 4
- Advertisement, deleted a bunch of useless dependency packages to speed up compilation
- custom time.Time type can not use ShoudBindQuery get a value ,error : invalid character '-' after top-level value HOT 3
- [Bug] UnescapePathValues = false still unescapes path values
- [Bug] infinite redirect with RedirectFixedPath HOT 2
- [Bug] EOF when using ShouldBindJSON HOT 5
- can suport domain router? like github.com/gorilla/mux HOT 4
- time param with timezome in Get method ShouldBindQuery parse error HOT 3
- dare you add a detailed API doc? HOT 5
- Is Gin Context violating the golang context styleguide? HOT 3
- Overwrite `JSONRender` similar to `HTMLRender` HOT 1
- How to apply default value if empty value provided by client during model binding? HOT 8
- msgpack incorrectly encoding unsigned integers HOT 2
- RecoveryWithWriter takes mulitple RecoveryFuncs but only applies the first HOT 3
- Different 404 handler for different group HOT 4
- Interrupt-drop-cancel request by user
- Automatically generate documents
- LogFormatterParams.Body reading failed
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.