package api import ( "net/http" "time" "git.tek.govt.hu/dowerx/place/api/read" "git.tek.govt.hu/dowerx/place/api/write" "github.com/gin-gonic/gin" ) func Listen(address string, staticPath string) { router := gin.Default() router.GET("/info", read.Info) router.GET("/tile", read.Tile) router.POST("/set", write.Pixel) router.OPTIONS("/set", func(c *gin.Context) { c.Header("Access-Control-Allow-Origin", "*") c.Header("Vary", "Origin") c.Header("Access-Control-Allow-Headers", "content-type") c.Header("Access-Control-Allow-Methods", "*") c.Header("Access-Control-Allow-Credentials", "true") }) if staticPath != "" { router.Static("/static", staticPath) } server := &http.Server{ Addr: address, Handler: router, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, } err := server.ListenAndServe() if err != nil { panic(err) } }