-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (63 loc) · 1.65 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
package main
import (
"flag"
log "github.com/sirupsen/logrus"
"os"
"parquet-online-viewer/api"
"parquet-online-viewer/logger"
"path/filepath"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
var pathPtr *string
var disablePathPtr *bool
var packageJsonPathPtr *string
func init() {
log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stdout)
path, err := os.Executable()
if err != nil {
panic(err)
}
pathPtr = flag.String("frontend", filepath.Join(path, "../../frontend/build"), "Path to frontend build folder")
disablePathPtr = flag.Bool("disable-frontend", false, "Should disable fronted?")
packageJsonPathPtr = flag.String("package", filepath.Join(path, "../../package.json"), "package.json path")
flag.Parse()
}
func fixRelativePath(path *string) {
if string((*path)[0]) == "." {
if wd, err := os.Getwd(); err != nil {
*path = filepath.Join(wd, *path)
}
}
}
func main() {
e := echo.New()
e.HideBanner = true
logger.Logger = log.New()
e.Logger = logger.GetEchoLogger()
e.Use(logger.Hook())
e.Use(middleware.CORS())
e.Use(middleware.Recover())
g := e.Group("/v1")
g.POST("/parquet", api.Parquet())
fixRelativePath(packageJsonPathPtr)
g.GET("/info", api.Info(*packageJsonPathPtr))
if (*disablePathPtr) != true {
fixRelativePath(pathPtr)
log.Debug("Frontend path:", *pathPtr)
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: *pathPtr,
Index: "index.html",
Browse: true,
HTML5: true,
}))
} else {
log.Info("Frontend disabled")
}
address := ":1323"
log.WithFields(log.Fields{
"address": address,
}).Info("Server started")
e.Logger.Fatal(e.Start(address))
}