-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
43 lines (35 loc) · 978 Bytes
/
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
package main
import (
"gopkg.in/kataras/iris.v6"
"gopkg.in/kataras/iris.v6/adaptors/cors"
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
)
func main() {
app := iris.New()
app.Adapt(iris.DevLogger())
app.Adapt(httprouter.New())
crs := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
})
app.Adapt(crs) // this line should be added
// adaptor supports cors allowed methods, middleware does not.
// if you want per-route-only cors
// then you should check https://github.com/iris-contrib/middleware/tree/master/cors
v1 := app.Party("/api/v1")
{
v1.Post("/home", func(c *iris.Context) {
app.Log(iris.DevMode, "lalala")
c.WriteString("Hello from /home")
})
v1.Get("/g", func(c *iris.Context) {
app.Log(iris.DevMode, "lalala")
c.WriteString("Hello from /home")
})
v1.Post("/h", func(c *iris.Context) {
app.Log(iris.DevMode, "lalala")
c.WriteString("Hello from /home")
})
}
app.Listen(":8080")
}