-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (38 loc) · 1.17 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
package main
import (
"embed"
"fmt"
"log"
"net/http"
"nms/src/backend/env"
"nms/src/backend/model"
"nms/src/backend/util/connection"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
//? Embed static files to binary
//go:embed src/frontend/web/*
var frontend embed.FS
func main() {
e := echo.New()
/* -------------------------------- FRONT END ------------------------------- */
contentHandler := echo.WrapHandler(http.FileServer(http.FS(frontend)))
contentRewrite := middleware.Rewrite(map[string]string{"/*": "/src/frontend/web/$1"})
e.GET("/*", contentHandler, contentRewrite)
/* -------------------------------- BACK END -------------------------------- */
svc := e.Group("/svc")
database := svc.Group("/database")
mongodb := new(connection.MongoDB)
database.GET("/find", func(c echo.Context) error {
return model.BuildResponse(c, mongodb.GetDatabaseNames(), nil)
})
database.GET("/collection/find", func(c echo.Context) error {
return model.BuildResponse(c, mongodb.GetDatabaseNameWithCollectionName(), nil)
})
log.Fatalln(e.Start(
fmt.Sprintf(":%d", env.APP_PORT),
))
}