1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-24 04:15:56 +00:00

|You will love this| New Feature: Offline routing, dynamic changes against a route's state | https://github.com/kataras/iris/issues/585

Read HISTORY.md for details
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-01-12 08:28:30 +02:00
parent 020e857b22
commit c91a1e6628
7 changed files with 322 additions and 12 deletions

View File

@@ -2,6 +2,82 @@
**How to upgrade**: remove your `$GOPATH/src/github.com/kataras` folder, open your command-line and execute this command: `go get -u github.com/kataras/iris/iris`.
## 6.1.0 -> 6.1.1
- **NEW FEATURE**: `Offline routes`.
- Discussion: https://github.com/kataras/iris/issues/585
- Test: https://github.com/kataras/iris/blob/master/http_test.go#L735
- Example: https://github.com/iris-contrib/examples/tree/master/route_state
**What?**
```go
package main
import (
"github.com/kataras/iris"
)
func main() {
iris.None("/api/user/:userid", func(ctx *iris.Context) {
userid := ctx.Param("userid")
ctx.Writef("user with id: %s", userid)
})("user.api")
// change the "user.api" state from offline to online and online to offline
iris.Get("/change", func(ctx *iris.Context) {
routeName := "user.api"
if iris.Lookup(routeName).IsOnline() {
// set to offline
iris.SetRouteOffline(routeName)
} else {
// set to online if it was not online(so it was offline)
iris.SetRouteOnline(routeName, iris.MethodGet)
}
})
// iris.Get("/execute/:routename", func(ctx *iris.Context) {
// routeName := ctx.Param("routename")
// userAPICtx := ctx.ExecuteRoute(routeName)
// if userAPICtx == nil {
// ctx.Writef("Route with name: %s didnt' found or couldn't be validate with this request path!", routeName)
// }
// })
iris.Get("/execute", func(ctx *iris.Context) {
routeName := "user.api"
// change the path in order to be catcable from the ExecuteRoute
// ctx.Request.URL.Path = "/api/user/42"
// ctx.ExecRoute(routeName)
// or:
ctx.ExecRouteAgainst(routeName, "/api/user/42")
})
iris.Get("/", func(ctx *iris.Context) {
ctx.Writef("Hello from index /")
})
//
// START THE SERVER
//
// STEPS:
// 1. navigate to http://localhost:8080/user/api/42
// you should get 404 error
// 2. now, navigate to http://localhost:8080/change
// you should see a blank page
// 3. now, navigate to http://localhost:8080/user/api/42
// you should see the page working, NO 404 error
// go back to the http://localhost:8080/change
// you should get 404 error again
// You just dynamically changed the state of a route with 3 lines of code!
// you can do the same with group of routes and subdomains :)
iris.Listen(":8080")
}
```
## 6.0.9 -> 6.1.0
- Fix a not found error when serving static files through custom subdomain, this should work again: `iris.Party("mysubdomain.").StaticWeb("/", "./static")`