-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
62 lines (45 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.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.
}
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"
}