156 lines
4.3 KiB
Go
156 lines
4.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/labstack/echo/v5"
|
|
"jubilee-server/fsexplore"
|
|
"jubilee-server/geocode"
|
|
"jubilee-server/structs"
|
|
"jubilee-server/utils"
|
|
"jubilee-server/weather"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/pocketbase/pocketbase"
|
|
"github.com/pocketbase/pocketbase/apis"
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
var (
|
|
Version string
|
|
Build string
|
|
)
|
|
|
|
func main() {
|
|
log.Printf("GO-PB-JUBILEE v%+v build %+v\n\n", Version, Build)
|
|
app := pocketbase.New()
|
|
|
|
// serves static files from the provided public dir (if exists)
|
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
|
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), false))
|
|
|
|
e.Router.GET("/geocode/:latitude/:longitude", func(c echo.Context) error {
|
|
apis.ActivityLogger(app)
|
|
return geocodeHandler(c, app)
|
|
})
|
|
|
|
e.Router.GET("/weather/:latitude/:longitude", func(c echo.Context) error {
|
|
apis.ActivityLogger(app)
|
|
return forecastHandler(c, app)
|
|
})
|
|
|
|
e.Router.GET("/weatheralert/:latitude/:longitude", func(c echo.Context) error {
|
|
apis.ActivityLogger(app)
|
|
return weatherAlertHandler(c, app)
|
|
})
|
|
|
|
e.Router.GET("/fsexplore/:latitude/:longitude/:soqval/:soqtype/:limit", func(c echo.Context) error {
|
|
apis.ActivityLogger(app)
|
|
return fsExploreHandler(c, app)
|
|
})
|
|
|
|
e.Router.GET("/nearbydetail/:fsqid", func(c echo.Context) error {
|
|
apis.ActivityLogger(app)
|
|
return fsNearbyDetailHandler(c, app)
|
|
})
|
|
|
|
return nil
|
|
})
|
|
|
|
if err := app.Start(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func geocodeHandler(c echo.Context, app *pocketbase.PocketBase) error {
|
|
|
|
params := c.PathParams()
|
|
|
|
fmt.Printf("$$:geocodeHandler")
|
|
fmt.Printf("-- %+v\n", params)
|
|
|
|
log.Printf("Latitude: %s", c.PathParam("latitude"))
|
|
log.Printf("Longitude: %s", c.PathParam("longitude"))
|
|
|
|
latlong := new(structs.LatLong)
|
|
|
|
latlong = utils.LLfromStrings64(c.PathParam("latitude"), c.PathParam("longitude"))
|
|
|
|
address := geocode.Geocode(app, *latlong)
|
|
|
|
return c.JSON(http.StatusOK, address)
|
|
}
|
|
|
|
func forecastHandler(c echo.Context, app *pocketbase.PocketBase) error {
|
|
params := c.PathParams()
|
|
|
|
fmt.Printf("$$:forecastHandler")
|
|
fmt.Printf("-- %+v\n", params)
|
|
|
|
log.Printf("Latitude: %s", c.PathParam("latitude"))
|
|
log.Printf("Longitude: %s", c.PathParam("longitude"))
|
|
latlong := new(structs.LatLong)
|
|
|
|
latlong = utils.LLfromStrings64(c.PathParam("latitude"), c.PathParam("longitude"))
|
|
|
|
returnJson := weather.GetOpenWeather(app, *latlong)
|
|
|
|
c.Response().Header().Set("Cache-Control", "max-age=600, must-revalidate")
|
|
return c.String(http.StatusOK, returnJson)
|
|
}
|
|
|
|
func weatherAlertHandler(c echo.Context, app *pocketbase.PocketBase) error {
|
|
params := c.PathParams()
|
|
|
|
fmt.Printf("$$:WeatherAlertHandler")
|
|
fmt.Printf("-- %+v\n", params)
|
|
|
|
log.Printf("Latitude: %s", c.PathParam("latitude"))
|
|
log.Printf("Longitude: %s", c.PathParam("longitude"))
|
|
latlong := new(structs.LatLong)
|
|
|
|
latlong = utils.LLfromStrings64(c.PathParam("latitude"), c.PathParam("longitude"))
|
|
|
|
returnJson := weather.GetPirateForecast(app, *latlong)
|
|
c.Response().Header().Set("Cache-Control", "max-age=600, must-revalidate")
|
|
return c.String(http.StatusOK, returnJson)
|
|
}
|
|
|
|
func fsExploreHandler(c echo.Context, app *pocketbase.PocketBase) error {
|
|
params := c.PathParams()
|
|
|
|
fmt.Printf("$$:fsExploreHandler")
|
|
fmt.Printf("-- %+v\n", params)
|
|
|
|
log.Printf("Latitude: %s", c.PathParam("latitude"))
|
|
log.Printf("Longitude: %s", c.PathParam("longitude"))
|
|
log.Printf("Soqval: %s", c.PathParam("soqval"))
|
|
log.Printf("Soqtype: %s", c.PathParam("soqtype"))
|
|
log.Printf("Limit: %s", c.PathParam("Limit"))
|
|
|
|
latlong := new(structs.LatLong)
|
|
|
|
latlong = utils.LLfromStrings64(c.PathParam("latitude"), c.PathParam("longitude"))
|
|
|
|
log.Printf("latlong: %s", latlong)
|
|
|
|
returnJson := fsexplore.FsRequest(*latlong, c.PathParam("soqval"), c.PathParam("soqtype"), c.PathParam("limit"))
|
|
c.Response().Header().Set("Cache-Control", "max-age=600, must-revalidate")
|
|
return c.String(http.StatusOK, returnJson)
|
|
}
|
|
|
|
func fsNearbyDetailHandler(c echo.Context, app *pocketbase.PocketBase) error {
|
|
|
|
params := c.PathParams()
|
|
|
|
fmt.Printf("$$:fsNearbyDetailHandler")
|
|
fmt.Printf("-- %+v\n", params)
|
|
|
|
log.Printf("fsqid: %s", c.PathParam("fsqid"))
|
|
|
|
returnJson := fsexplore.FsRequestDetails(app, c.PathParam("fsqid"))
|
|
c.Response().Header().Set("Cache-Control", "max-age=600, must-revalidate")
|
|
return c.String(http.StatusOK, returnJson)
|
|
}
|