-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (34 loc) · 808 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
package main
import (
"poke_api/pokemon"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
)
func main() {
r := gin.New()
config := cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "http://"
},
MaxAge: 12 * time.Hour,
})
r.Use(config)
r.Use(gin.Recovery())
r.Use(static.Serve("/image", static.LocalFile("./images", true)))
r.GET("/", ip)
r.GET("/pokemon", pokemon.Fetch)
r.GET("/pokemon/:id", pokemon.FetchById)
r.Run(":6001")
}
func ip(c *gin.Context) {
i := c.ClientIP()
c.JSON(200, i)
}