ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
File: routing/route-state/main.go ~~~ package main import ( "github.com/kataras/iris" ) func main() { app := iris.New() none := app.None("/invisible/{username}", func(ctx iris.Context) { ctx.Writef("Hello %s with method: %s", ctx.Params().Get("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 iris.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 iris.Context) { // 导航到"http://localhost:8080/invisible/iris" 何时调用/更改并更改路由状态 // 从“离线”到“在线” ctx.Values().Set("from", "/execute") // 从“外部”上下文调用Exec时,可以共享值和会话。"foreign" context. ctx.Exec("GET", "/invisible/iris") }) app.Run(iris.Addr(":8080")) } ~~~