mirror of
https://github.com/kataras/iris.git
synced 2026-01-04 10:47:20 +00:00
finalize the API
Former-commit-id: e680a9fc517c02eca66f83e42519c9820122fae8
This commit is contained in:
@@ -90,7 +90,7 @@ This will make the handler to send these headers to the client:
|
||||
Grouping routes by version is possible as well.
|
||||
|
||||
Using the `versioning.NewGroup(version string) *versioning.Group` function you can create a group to register your versioned routes.
|
||||
The `versioning.RegisterGroups(r iris.Party, groups ...*versioning.Group)` must be called in the end in order to register the routes to a specific `Party`.
|
||||
The `versioning.RegisterGroups(r iris.Party, versionNotFoundHandler iris.Handler, groups ...*versioning.Group)` must be called in the end in order to register the routes to a specific `Party`.
|
||||
|
||||
```go
|
||||
app := iris.New()
|
||||
@@ -106,9 +106,11 @@ userAPIV2.Get("/", sendHandler(v2Response))
|
||||
userAPIV2.Post("/", sendHandler(v2Response))
|
||||
userAPIV2.Put("/other", sendHandler(v2Response))
|
||||
|
||||
versioning.RegisterGroups(userAPI, userAPIV10, userAPIV2)
|
||||
versioning.RegisterGroups(userAPI, versioning.NotFoundHandler, userAPIV10, userAPIV2)
|
||||
```
|
||||
|
||||
> A middleware can be registered to the actual `iris.Party` only, using the methods we learnt above, i.e by using the `versioning.Match` in order to detect what code/handler you want to be executed when "x" or no version is requested.
|
||||
|
||||
### Deprecation for Group
|
||||
|
||||
Just call the `Deprecated(versioning.DeprecationOptions)` on the group you want to notify your API consumers that this specific version is deprecated.
|
||||
@@ -117,17 +119,6 @@ Just call the `Deprecated(versioning.DeprecationOptions)` on the group you want
|
||||
userAPIV10 := versioning.NewGroup("1.0").Deprecated(versioning.DefaultDeprecationOptions)
|
||||
```
|
||||
|
||||
### Version not found for Groups
|
||||
|
||||
In order to register a custom version not found handler you have to use the `versioning.Concat` first, which gives you the API to add a version not found handler.
|
||||
|
||||
```go
|
||||
versioning.Concat(userAPIV10, userAPIV2).NotFound(func(ctx iris.Context) {
|
||||
ctx.StatusCode(iris.StatusNotFound)
|
||||
ctx.Writef("unknown version %s", versioning.GetVersion(ctx))
|
||||
}).For(userAPI)
|
||||
```
|
||||
|
||||
## Compare version manually from inside your handlers
|
||||
|
||||
```go
|
||||
|
||||
Reference in New Issue
Block a user