mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Add a trivial sessions example of SetImmutable
.
https://github.com/iris-contrib/community-board/issues/5#issuecomment-307030072 Former-commit-id: 2d6267465cceeba31c96feba19f4851d4db7f7aa
This commit is contained in:
parent
acd3389dd7
commit
8b66c2de3b
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/kataras/iris/sessions"
|
||||
)
|
||||
|
||||
type myobject struct {
|
||||
name string
|
||||
type businessModel struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -84,5 +84,20 @@ func main() {
|
|||
// mySessions.DestroyByID
|
||||
// mySessions.DestroyAll
|
||||
|
||||
app.Get("/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
|
||||
businessGet[0].Name = "Gabriel"
|
||||
})
|
||||
|
||||
app.Get("/immutable_get", func(ctx context.Context) {
|
||||
if ctx.Session().Get("businessEdit").([]businessModel)[0].Name == "Gabriel" {
|
||||
panic("Report this as a bug, immutable data cannot be changed from the caller without re-SetImmutable")
|
||||
}
|
||||
// the name should remains "Edward"
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user