You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have middleware (using r.Use()), you can set keys through the method ctx.Set(k, v) which puts them into ctx.Keys. This sets the expectation of when using:
Inside each one I simply output the context using {{.}}, the context is as follows:
Route /: CTX: map[SignedIn:true Title:My website]
Route about: CTX: map[]
Multitemplate
I am using the github.com/gin-contrib/multitemplate plugin as I need to use multiple templates, and it's recommended in the docs to use that. I am assuming that it's working as intended.
Environment
go version: go version go1.21.12 linux/amd64
gin version (or commit ref): v1.10.0
gin multitemplate: v1.0.1
operating system: Fedora Linux 40
The text was updated successfully, but these errors were encountered:
Although Conetxt.Keys and gin.H are both map[string]any, Keys are only used during the lifetime of the request and should not be exported as a result. gin.H is a specific output structure with multi-type support.
I suggest you use the code below to process the results and do something with the output
r.GET("/", func(ctx*gin.Context) {
varmergeData gin.Hfork, v:=rangectx.Keys {
mergedData[k] =v// Process merge data
}
ctx.HTML(http.StatusOK, "index.html", mergeData)
})
Maybe it would be worth updating the documentation to state that, since my first impression was that it was a way of setting messages to be sent from the middleware to the endpoint.
Description
If you have middleware (using
r.Use()
), you can set keys through the methodctx.Set(k, v)
which puts them intoctx.Keys
. This sets the expectation of when using:You expect that the map
gin.H
's entries will be applied on top ofctx.Keys
, however, it overwrites them. Here is my Use method:Here are some of my routes:
Route /
Route about
Inside each one I simply output the context using
{{.}}
, the context is as follows:CTX: map[SignedIn:true Title:My website]
CTX: map[]
Multitemplate
I am using the github.com/gin-contrib/multitemplate plugin as I need to use multiple templates, and it's recommended in the docs to use that. I am assuming that it's working as intended.
Environment
The text was updated successfully, but these errors were encountered: