mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
Add notes for the new lead maintainer of the open-source iris project and align with @get-ion/ion by @hiveminded
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
This commit is contained in:
39
_examples/routing/route-state/main.go
Normal file
39
_examples/routing/route-state/main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
none := app.None("/invisible/{username}", func(ctx context.Context) {
|
||||
ctx.Writef("Hello %s with method: %s", ctx.Values().GetString("username"), ctx.Method())
|
||||
|
||||
if from := ctx.Values().GetString("from"); from != "" {
|
||||
ctx.Writef("\nI see that you're coming from %s", from)
|
||||
}
|
||||
})
|
||||
|
||||
app.Get("/change", func(ctx context.Context) {
|
||||
|
||||
if none.IsOnline() {
|
||||
none.Method = iris.MethodNone
|
||||
} else {
|
||||
none.Method = iris.MethodGet
|
||||
}
|
||||
|
||||
// refresh re-builds the router at serve-time in order to be notified for its new routes.
|
||||
app.RefreshRouter()
|
||||
})
|
||||
|
||||
app.Get("/execute", func(ctx context.Context) {
|
||||
// same as navigating to "http://localhost:8080/invisible/iris" when /change has being invoked and route state changed
|
||||
// from "offline" to "online"
|
||||
ctx.Values().Set("from", "/execute") // values and session can be shared when calling Exec from a "foreign" context.
|
||||
ctx.Exec("GET", "/invisible/iris")
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user