iris/_examples/mvc/versioned-controller/main.go
Gerasimos (Makis) Maropoulos 04c8b79b1f mvc: versioning: add 'Deprecated' feature as well
Former-commit-id: c233bae47aa765a7e1cd9ab7000acd14614a78ae
2020-06-20 11:11:44 +03:00

63 lines
1.3 KiB
Go

package main
import (
"time"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
// Optional deprecated X-API-XXX headers for version 1.
var opts = mvc.DeprecationOptions{
WarnMessage: "deprecated, see <this link>",
DeprecationDate: time.Now().UTC(),
DeprecationInfo: "a bigger version is available, see <this link> for more information",
}
func main() {
app := newApp()
// See main_test.go for request examples.
app.Listen(":8080")
}
func newApp() *iris.Application {
app := iris.New()
dataRouter := app.Party("/data")
{
m := mvc.New(dataRouter)
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))
}
return app
}
type v1Controller struct{}
func (c *v1Controller) Get() string {
return "data (v1.x)"
}
type v2Controller struct{}
func (c *v2Controller) Get() string {
return "data (v2.x)"
}
type v3Controller struct{}
func (c *v3Controller) Get() string {
return "data (v3.x)"
}
type noVersionController struct{}
func (c *noVersionController) Get() string {
return "data"
}