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

Update to 8.0.2. Read HISTORY.md for the surpise

Former-commit-id: bbdf020ccaa986c332716aa7f749b7bdc24e427e
This commit is contained in:
kataras
2017-07-15 17:40:29 +03:00
parent 5015d92ece
commit 5752625c80
12 changed files with 508 additions and 31 deletions

View File

@@ -34,17 +34,54 @@ It doesn't always contain the "best ways" but it does cover each important featu
### Configuration
- [Functional](configuration/functional/main.go)
* [From Configuration Struct](configuration/from-configuration-structure/main.go)
- [From Configuration Struct](configuration/from-configuration-structure/main.go)
- [Import from YAML file](configuration/from-yaml-file/main.go)
- [Import from TOML file](configuration/from-toml-file/main.go)
### Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context
* `app.Get("{userid:int min(1)}", myHandler)`
* `app.Post("{asset:path}", myHandler)`
* `app.Put("{custom:string regexp([a-z]+)}", myHandler)`
Note: unlike other routers you'd seen, iris' router can handle things like these:
```go
// Matches all GET requests prefixed with "/assets/"
app.Get("/assets/{asset:path}", assetsWildcardHandler)
// Matches only GET "/"
app.Get("/", indexHandler)
// Matches only GET "/about"
app.Get("/about", aboutHandler)
// Matches all GET requests prefixed with "/profile/"
// and followed by a single path part
app.Get("/profile/{username:string}", userHandler)
// Matches only GET "/profile/me" because
// it does not conflict with /profile/{username:string}
// or the root wildcard {root:path}
app.Get("/profile/me", userHandler)
// Matches all GET requests prefixed with /users/
// and followed by a number which should be equal or bigger than 1
app.Get("/user/{userid:int min(1)}", getUserHandler)
// Matches all requests DELETE prefixed with /users/
// and following by a number which should be equal or bigger than 1
app.Delete("/user/{userid:int min(1)}", deleteUserHandler)
// Matches all GET requests except "/", "/about", anything starts with "/assets/" etc...
// because it does not conflict with the rest of the routes.
app.Get("{root:path}", rootWildcardHandler)
```
Navigate through examples for a better understanding.
- [Overview](routing/overview/main.go)
- [Basic](routing/basic/main.go)
- [Custom HTTP Errors](routing/http-errors/main.go)
- [Dynamic Path](routing/dynamic-path/main.go)
* [Root Level Wildcard Path](routing/dynamic-path/root-wildcard/main.go)
- [Reverse routing](routing/reverse/main.go)
- [Custom wrapper](routing/custom-wrapper/main.go)
- Custom Context

View File

@@ -28,6 +28,8 @@ func newApp() *iris.Application {
// })
assetHandler := app.StaticHandler("./public", false, false)
// as an alternative of SPA you can take a look at the /routing/dynamic-path/root-wildcard
// example too
app.SPA(assetHandler)
return app

View File

@@ -25,6 +25,8 @@ func newApp() *iris.Application {
})
assetHandler := app.StaticEmbeddedHandler("./public", Asset, AssetNames)
// as an alternative of SPA you can take a look at the /routing/dynamic-path/root-wildcard
// example too
app.SPA(assetHandler)
return app

View File

@@ -0,0 +1,61 @@
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
app := iris.New()
// this works as expected now,
// will handle all GET requests
// except:
// / -> because of app.Get("/", ...)
// /other/anything/here -> because of app.Get("/other/{paramother:path}", ...)
// /other2/anything/here -> because of app.Get("/other2/{paramothersecond:path}", ...)
// /other2/static -> because of app.Get("/other2/static", ...)
//
// It isn't conflicts with the rest of the routes, without routing performance cost!
//
// i.e /something/here/that/cannot/be/found/by/other/registered/routes/order/not/matters
app.Get("/{p:path}", h)
// this will handle only GET /
app.Get("/", staticPath)
// this will handle all GET requests starting with "/other/"
//
// i.e /other/more/than/one/path/parts
app.Get("/other/{paramother:path}", other)
// this will handle all GET requests starting with "/other2/"
// except /other2/static (because of the next static route)
//
// i.e /other2/more/than/one/path/parts
app.Get("/other2/{paramothersecond:path}", other2)
// this will handle only GET "/other2/static"
app.Get("/other2/static", staticPath)
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
func h(ctx context.Context) {
param := ctx.Params().Get("p")
ctx.WriteString(param)
}
func other(ctx context.Context) {
param := ctx.Params().Get("paramother")
ctx.Writef("from other: %s", param)
}
func other2(ctx context.Context) {
param := ctx.Params().Get("paramothersecond")
ctx.Writef("from other2: %s", param)
}
func staticPath(ctx context.Context) {
ctx.Writef("from the static path: %s", ctx.Path())
}