mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Add link for the "community-maden" middleware
I did maintain and upgrade them because community is not evolved too much on these, but that's OK for now. Former-commit-id: b811c133fbfb310834c67d78248f944e0a89c9a6
This commit is contained in:
parent
8b66c2de3b
commit
a0dee3abdb
|
@ -94,6 +94,9 @@ It doesn't contains "best ways" neither explains all its features. It's just a s
|
|||
* [Online Visitors](advanced/online-visitors/main.go)
|
||||
* [URL Shortener using BoltDB](advanced/url-shortener/main.go)
|
||||
|
||||
|
||||
You may want to check out examples for jwt, cors and the rest of community-maden middleware by clicking [here](https://github.com/iris-contrib/middleware)
|
||||
|
||||
> Do not forget to [star or watch the project](https://github.com/kataras/iris/stargazers) in order to stay updated with the latest tech trends, it takes some seconds for the sake of go!
|
||||
|
||||
> Developers should read the official [documentation](https://godoc.org/github.com/kataras/iris) in depth, for deep understanding.
|
||||
|
|
|
@ -84,18 +84,38 @@ func main() {
|
|||
// mySessions.DestroyByID
|
||||
// mySessions.DestroyAll
|
||||
|
||||
app.Get("/immutable", func(ctx context.Context) {
|
||||
// remember: slices and maps are muttable by-design
|
||||
// The `SetImmutable` makes sure that they will be stored and received
|
||||
// as immutable, so you can't change them directly by mistake.
|
||||
//
|
||||
// Use `SetImmutable` consistently, it's slower than `Set`.
|
||||
// Read more about muttable and immutable go types: https://stackoverflow.com/a/8021081
|
||||
app.Get("/set_immutable", func(ctx context.Context) {
|
||||
business := []businessModel{{Name: "Edward"}, {Name: "value 2"}}
|
||||
ctx.Session().SetImmutable("businessEdit", business)
|
||||
businessGet := ctx.Session().Get("businessEdit").([]businessModel)
|
||||
// businessGet[0].Name is equal to Edward initially
|
||||
|
||||
// try to change it, if we used `Set` instead of `SetImmutable` this
|
||||
// change will affect the underline array of the session's value "businessEdit", but now it will not.
|
||||
businessGet[0].Name = "Gabriel"
|
||||
|
||||
})
|
||||
|
||||
app.Get("/immutable_get", func(ctx context.Context) {
|
||||
if ctx.Session().Get("businessEdit").([]businessModel)[0].Name == "Gabriel" {
|
||||
app.Get("/get_immutable", func(ctx context.Context) {
|
||||
valSlice := ctx.Session().Get("businessEdit")
|
||||
if valSlice == nil {
|
||||
ctx.HTML("please navigate to the <a href='/set_immutable'>/set_immutable</a> first")
|
||||
return
|
||||
}
|
||||
|
||||
firstModel := valSlice.([]businessModel)[0]
|
||||
// businessGet[0].Name is equal to Edward initially
|
||||
if firstModel.Name != "Edward" {
|
||||
panic("Report this as a bug, immutable data cannot be changed from the caller without re-SetImmutable")
|
||||
}
|
||||
|
||||
ctx.Writef("[]businessModel[0].Name remains: %s", firstModel.Name)
|
||||
|
||||
// the name should remains "Edward"
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user