-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (50 loc) · 1.34 KB
/
main.go
File metadata and controls
60 lines (50 loc) · 1.34 KB
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
package main
import (
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files" // swagger embed files
ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware
"github.com/together-coding/runtime-bridge/containers"
"github.com/together-coding/runtime-bridge/db"
"github.com/together-coding/runtime-bridge/docs"
"github.com/together-coding/runtime-bridge/runtimes"
"github.com/together-coding/runtime-bridge/users"
"github.com/together-coding/runtime-bridge/utils"
"math/rand"
"time"
)
func ping(c *gin.Context) {
c.JSON(200, gin.H{
"ping": "pong",
})
}
func main() {
rand.Seed(time.Now().Unix())
// Load configs
err := godotenv.Load(".env")
if err != nil {
panic(err)
}
// Initialize DB
db.Initialize()
// Gin
r := gin.Default()
r.GET("/ping", ping)
utils.CORSMiddleware(r)
// users
userApi := r.Group("/api/users")
userApi.Use(users.IdentifyUser())
users.Register(userApi.Group("/"))
// runtimes
runtimeApi := r.Group("/api/runtimes")
runtimes.Register(runtimeApi.Group("/"))
// containers
containerApi := r.Group("/api/containers")
containers.Register(containerApi.Group("/"), users.IdentifyUser)
// swagger
if utils.GetConfigBool("DEBUG") {
docs.SwaggerInfo.BasePath = "/api"
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
r.Run()
}