-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 1.05 KB
/
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
39
40
41
42
package main
import (
"gharpeti/cmd/db"
"gharpeti/handlers"
"gharpeti/routes"
"log"
_ "github.com/joho/godotenv/autoload"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"auth-token"},
}))
e.GET("/", handlers.Home)
db.InitDB()
// here we create geospatial index
err := db.DB.Exec("CREATE EXTENSION IF NOT EXISTS postgis").Error
if err != nil {
log.Fatal("failed to create PostGIS extension:", err)
}
// Run the CREATE INDEX command
errr := db.DB.Exec("CREATE INDEX IF NOT EXISTS idx_properties_location ON properties USING GIST (ST_GeographyFromText('SRID=4326;POINT(' || longitude || ' ' || latitude || ')'))").Error
if errr != nil {
log.Fatal("failed to create index:", err)
}
routes.UserRoutes(e)
routes.PropertyRoutes(e)
routes.ApplicationRoutes(e)
e.Logger.Fatal(e.Start(":8080"))
}