76 lines
1.0 KiB
Go
76 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
_ "fmt"
|
|
"jubilee/src/geocode"
|
|
"log"
|
|
|
|
_ "log"
|
|
"os"
|
|
_ "strings"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/template/html/v2"
|
|
|
|
"jubilee/src/structs"
|
|
"jubilee/src/utils"
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
|
engine := html.New("./dist", ".html")
|
|
|
|
app := fiber.New(fiber.Config{
|
|
Views: engine,
|
|
|
|
})
|
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
return indexHandler(c)
|
|
})
|
|
|
|
app.Get("/geocode", func(c * fiber.Ctx) error {
|
|
|
|
return geocodeHandler(c)
|
|
})
|
|
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8110"
|
|
}
|
|
|
|
app.Static("/", "./dist")
|
|
log.Fatalln(app.Listen(fmt.Sprintf(":%v", port)))
|
|
|
|
}
|
|
|
|
|
|
func indexHandler(c *fiber.Ctx) error {
|
|
|
|
return c.Render("index", nil)
|
|
}
|
|
|
|
func geocodeHandler(c * fiber.Ctx) error {
|
|
|
|
log.Println("geocodeHandler", c.Query("ll"))
|
|
|
|
ll := new(structs.LL)
|
|
|
|
latlong := new(structs.LatLong)
|
|
|
|
if err := c.QueryParser(ll); err != nil {
|
|
log.Println("ERROR", err)
|
|
|
|
}
|
|
|
|
latlong = utils.ParseLL(*ll)
|
|
|
|
address := geocode.Geocode(*latlong)
|
|
|
|
return c.JSON(address)
|
|
|
|
}
|