mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
mvc: versioning: add 'Deprecated' feature as well
Former-commit-id: c233bae47aa765a7e1cd9ab7000acd14614a78ae
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
package mvc
|
||||
|
||||
import "github.com/kataras/iris/v12/hero"
|
||||
import (
|
||||
"github.com/kataras/iris/v12/hero"
|
||||
"github.com/kataras/iris/v12/versioning"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
// Result is a type alias for the `hero#Result`, useful for output controller's methods.
|
||||
Result = hero.Result
|
||||
// Response is a type alias for the `hero#Response`, useful for output controller's methods.
|
||||
Response = hero.Response
|
||||
// View is a type alias for the `hero#View`, useful for output controller's methods.
|
||||
View = hero.View
|
||||
// DeprecationOptions describes the deprecation headers key-values.
|
||||
// Is a type alias for the `versioning#DeprecationOptions`.
|
||||
//
|
||||
// See `Deprecated` package-level option.
|
||||
DeprecationOptions = versioning.DeprecationOptions
|
||||
)
|
||||
|
||||
// Try is a type alias for the `hero#Try`,
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
//
|
||||
// Usage:
|
||||
// m := mvc.New(dataRouter)
|
||||
// m.Handle(new(v1Controller), mvc.Version("1"))
|
||||
// m.Handle(new(v1Controller), mvc.Version("1"), mvc.Deprecated(mvc.DeprecationOptions{}))
|
||||
// m.Handle(new(v2Controller), mvc.Version("2.3"))
|
||||
// m.Handle(new(v3Controller), mvc.Version(">=3, <4"))
|
||||
// m.Handle(new(noVersionController))
|
||||
@@ -36,3 +36,15 @@ func Version(version string) OptionFunc {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated marks a specific Controller as a deprecated one.
|
||||
// Deprecated can be used to tell the clients that
|
||||
// a newer version of that specific resource is available instead.
|
||||
func Deprecated(options DeprecationOptions) OptionFunc {
|
||||
return func(c *ControllerActivator) {
|
||||
c.Use(func(ctx context.Context) {
|
||||
versioning.WriteDeprecated(ctx, options)
|
||||
ctx.Next()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user