This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (84 loc) · 2.88 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"gcom-backend/configs"
"gcom-backend/controllers"
_ "gcom-backend/docs"
"gcom-backend/util"
"log"
"os"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger"
)
// @title GCOM Backend
// @version 1.0
// @description This is the backend service for UBC UAS
// @contact.name UBC UAS
// @contact.url https://ubcuas.com/
// @contact.email [email protected]
// @host localhost:1323
// @Accept json
// @Produce json
// @Tags Waypoints
func main() {
db := configs.Connect(false)
err := os.MkdirAll("db", 0755) //Create db dir
err = os.MkdirAll("imgs", 0755) //Create images dir
if err != nil {
fmt.Println(err)
return
}
mp, err := configs.ConnectMissionPlanner("http://host.docker.internal:9000")
if err != nil {
log.Fatal("Error connecting to MPS")
}
e := echo.New()
e.Use(middleware.CORS())
e.Use(util.DBMiddleware(db))
e.Use(util.MPMiddleware(mp))
e.Use(middleware.CORS())
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} method=${method} uri=${uri} status=${status} ping=${latency_human}\n",
}))
e.GET("/", func(c echo.Context) error {
return c.JSON(200, "Hello, World!")
})
//Swagger Docs
e.GET("/swagger/*", echoSwagger.WrapHandler)
//Waypoints
e.POST("/waypoint", controllers.CreateWaypoint)
e.POST("/waypoints", controllers.CreateWaypointBatch)
e.PATCH("/waypoint/:waypointId", controllers.EditWaypoint)
e.GET("/waypoint/:waypointId", controllers.GetWaypoint)
e.DELETE("/waypoint/:waypointId", controllers.DeleteWaypoint)
e.DELETE("/waypoints", controllers.DeleteWaypointBatch)
e.GET("/waypoints", controllers.GetAllWaypoints)
//Drone
e.GET("/status", controllers.GetCurrentStatus)
e.GET("/status/history", controllers.GetStatusHistory)
e.POST("/drone/takeoff", controllers.Takeoff)
e.GET("/drone/land", controllers.Land)
e.POST("/drone/rtl", controllers.RTL)
e.GET("/drone/lock", controllers.Lock)
e.GET("/drone/unlock", controllers.Unlock)
e.GET("/drone/queue", controllers.GetQueue)
e.POST("/drone/queue", controllers.PostQueue)
e.POST("/drone/home", controllers.PostHome)
e.POST("/drone/arm", controllers.Arm)
//Ground Objects
e.POST("/groundobject", controllers.CreateGroundObject)
e.POST("/groundobjects", controllers.CreateGroundObjectBatch)
e.PATCH("/groundobject/:objectId", controllers.EditGroundObject)
e.GET("/groundobject/:objectId", controllers.GetGroundObject)
e.DELETE("/groundobject/:objectId", controllers.DeleteGroundObject)
e.DELETE("/groundobjects", controllers.DeleteGroundObjectBatch)
e.GET("/groundobjects", controllers.GetAllGroundObjects)
//Image Handling
e.POST("/image", controllers.UploadImage)
e.GET("/image/list", controllers.ListImages)
e.GET("/image/:filename", controllers.GetImage)
//Websockets
e.Any("/socket.io/", controllers.WebsocketHandler())
e.Logger.Fatal(e.Start("0.0.0.0:1323"))
}