mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 02:47:04 +00:00
move example flash-messages to sessions example folder and change httptest example with basicauth
Former-commit-id: 3c5f6c97629a2a6ae44e62f2900edd32c0329b50
This commit is contained in:
43
_examples/intermediate/sessions/flash-messages/main.go
Normal file
43
_examples/intermediate/sessions/flash-messages/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/sessions"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// output startup banner and error logs on os.Stdout
|
||||
|
||||
sess := sessions.New(sessions.Config{Cookie: "myappsessionid"})
|
||||
app.AttachSessionManager(sess)
|
||||
|
||||
app.Get("/set", func(ctx context.Context) {
|
||||
ctx.Session().SetFlash("name", "iris")
|
||||
ctx.Writef("Message setted, is available for the next request")
|
||||
})
|
||||
|
||||
app.Get("/get", func(ctx context.Context) {
|
||||
name := ctx.Session().GetFlashString("name")
|
||||
if name == "" {
|
||||
ctx.Writef("Empty name!!")
|
||||
return
|
||||
}
|
||||
ctx.Writef("Hello %s", name)
|
||||
})
|
||||
|
||||
app.Get("/test", func(ctx context.Context) {
|
||||
name := ctx.Session().GetFlashString("name")
|
||||
if name == "" {
|
||||
ctx.Writef("Empty name!!")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Writef("Ok you are comming from /set ,the value of the name is %s", name)
|
||||
ctx.Writef(", and again from the same context: %s", name)
|
||||
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user