2020-06-19 19:58:24 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-20 10:11:44 +02:00
|
|
|
"time"
|
|
|
|
|
2020-06-19 19:58:24 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/mvc"
|
|
|
|
)
|
|
|
|
|
2020-06-20 10:11:44 +02:00
|
|
|
// 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",
|
|
|
|
}
|
|
|
|
|
2020-06-19 19:58:24 +02:00
|
|
|
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)
|
2020-06-20 10:11:44 +02:00
|
|
|
|
2021-01-07 03:14:41 +01:00
|
|
|
m.Handle(new(v1Controller), mvc.Version("1.0.0"), mvc.Deprecated(opts))
|
|
|
|
m.Handle(new(v2Controller), mvc.Version("2.3.0"))
|
|
|
|
m.Handle(new(v3Controller), mvc.Version(">=3.0.0 <4.0.0"))
|
|
|
|
m.Handle(new(noVersionController)) // or if missing it will respond with 501 version not found.
|
2020-06-19 19:58:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|