mirror of
https://github.com/kataras/iris.git
synced 2026-01-15 16:05:57 +00:00
various improvements and new 'UseOnce' method - read HISTORY.md
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
* [The `urlpath` tmpl func](view/template_html_3/main.go)
|
||||
* [The `url` tmpl func](view/template_html_4/main.go)
|
||||
* [Inject Data Between Handlers](view/context-view-data/main.go)
|
||||
* [Inject Engine Between Handlers](view/context-view-engine/main.go)
|
||||
* [Embedding Templates Into App Executable File](view/embedding-templates-into-app/main.go)
|
||||
* [Write to a custom `io.Writer`](view/write-to)
|
||||
* [Blocks](view/template_blocks_0)
|
||||
|
||||
@@ -31,7 +31,7 @@ func newApp() *iris.Application {
|
||||
m.Handle(new(v1Controller), mvc.Version("1"), mvc.Deprecated(opts)) // 1 or 1.0, 1.0.0 ...
|
||||
m.Handle(new(v2Controller), mvc.Version("2.3")) // 2.3 or 2.3.0
|
||||
m.Handle(new(v3Controller), mvc.Version(">=3, <4")) // 3, 3.x, 3.x.x ...
|
||||
m.Handle(new(noVersionController))
|
||||
m.Handle(new(noVersionController)) // or if missing it will respond with 501 version not found.
|
||||
}
|
||||
|
||||
return app
|
||||
|
||||
@@ -42,9 +42,16 @@ func examplePerRoute(app *iris.Application) {
|
||||
// Headers[1] = Accept-Version: "2"
|
||||
func examplePerParty(app *iris.Application) {
|
||||
usersAPI := app.Party("/api/users")
|
||||
// You can customize the way a version is extracting
|
||||
// via middleware, for example:
|
||||
// version url parameter, and, if it's missing we default it to "1".
|
||||
usersAPI.Use(func(ctx iris.Context) {
|
||||
versioning.SetVersion(ctx, ctx.URLParamDefault("version", "1"))
|
||||
ctx.Next()
|
||||
})
|
||||
|
||||
// version 1.
|
||||
usersAPIV1 := versioning.NewGroup(">= 1, < 2")
|
||||
usersAPIV1 := versioning.NewGroup(usersAPI, ">= 1, < 2")
|
||||
usersAPIV1.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("v1 resource: /api/users handler")
|
||||
})
|
||||
@@ -53,15 +60,13 @@ func examplePerParty(app *iris.Application) {
|
||||
})
|
||||
|
||||
// version 2.
|
||||
usersAPIV2 := versioning.NewGroup(">= 2, < 3")
|
||||
usersAPIV2 := versioning.NewGroup(usersAPI, ">= 2, < 3")
|
||||
usersAPIV2.Get("/", func(ctx iris.Context) {
|
||||
ctx.Writef("v2 resource: /api/users handler")
|
||||
})
|
||||
usersAPIV2.Post("/", func(ctx iris.Context) {
|
||||
ctx.Writef("v2 resource: /api/users post handler")
|
||||
})
|
||||
|
||||
versioning.RegisterGroups(usersAPI, versioning.NotFoundHandler, usersAPIV1, usersAPIV2)
|
||||
}
|
||||
|
||||
func catsVersionExactly1Handler(ctx iris.Context) {
|
||||
|
||||
Reference in New Issue
Block a user