package Api import ( "fmt" "github.com/gin-gonic/gin" "io/ioutil" "os" ) func Tiles(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") dir, _ := os.Getwd() //path := dir + "/tiles/" + c.Query("z") + "/" + c.Query("x") + "/" + c.Query("y") + ".jpg" path := fmt.Sprintf("%s/tiles/%s/%s/%s.jpg",dir,c.Query("z"),c.Query("x"),c.Query("y")) if !PathExists(path) { path = dir + "/tiles/blank.png" } b, err := ioutil.ReadFile(path) if err != nil { fmt.Print(err) } c.Data(200, "Content-type: image/jpeg", b) } func PathExists(path string) (bool) { _, err := os.Stat(path) if err == nil { return true } if os.IsNotExist(err) { return false } return false }