forked from tez-capital/tezpeak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (85 loc) · 2.81 KB
/
main.go
File metadata and controls
102 lines (85 loc) · 2.81 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
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 (
"context"
"embed"
"flag"
"fmt"
"log/slog"
"net/http"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/mavryk-network/mavpeak/configuration"
"github.com/mavryk-network/mavpeak/constants"
"github.com/mavryk-network/mavpeak/core"
"github.com/mavryk-network/mavpeak/util"
)
type Message struct {
Text string
}
//go:embed web/dist/*
var staticFiles embed.FS
type staticFs struct {
http.FileSystem
}
func (c staticFs) Open(name string) (http.File, error) {
// try to open .html file first, because filesystem middleware forbids to open folders
// but we want to provide html if it exists when user tries to access path like /mavpay
f, err := c.FileSystem.Open(name + ".html")
if err != nil {
return c.FileSystem.Open(name)
}
return f, nil
}
func main() {
logLevelFlag := flag.String("log-level", "info", "Log level")
versionFlag := flag.Bool("version", false, "Print version and exit")
rootDirFlag := flag.String("root-dir", "", "Root directory (relevant only if auto detecting configuration)")
autodetectConfigurationFlag := flag.String("autodetect-configuration", "", "Path to file where to save autodetected configuration")
flag.Parse()
if autodetectConfigurationFlag != nil && *autodetectConfigurationFlag != "" {
rootDir := "."
if rootDirFlag != nil && *rootDirFlag != "" {
rootDir = *rootDirFlag
}
slog.Info("Autodetecting configuration", "rootDir", rootDir, "autodetectConfiguration", *autodetectConfigurationFlag)
configuration.AutoDetect(rootDir, *autodetectConfigurationFlag)
os.Exit(0)
}
if *versionFlag {
fmt.Printf("mavpeak %s - %s \n", constants.MAVPEAK_VERSION, constants.MAVPEAK_CODENAME)
return
}
util.InitLog(*logLevelFlag)
config, err := configuration.Load()
if err != nil {
panic(err)
}
// // 11695267
// // tz1hZvgjekGo7DmQjWh7XnY5eLQD8wNYPczE
// common.StartNodeStatusProviders(context.Background(), config.Nodes, nil)
// fmt.Println(mavbake.GetBlockRightsFor(context.Background(), 11695742, []string{"tz1P6WKJu2rcbxKiKRZHKQKmKrpC9TfW1AwM"}))
// os.Exit(0)
app := fiber.New()
group, ok := app.Group("/api").(*fiber.Group)
if !ok {
panic("failed to create api group")
}
err = core.Run(context.Background(), config, group)
if err != nil {
panic(err)
}
app.Use("/", filesystem.New(filesystem.Config{
Root: staticFs{http.FS(staticFiles)},
Index: "index.html",
NotFoundFile: "/web/dist/index.html",
PathPrefix: "/web/dist",
Browse: false,
}))
slog.Info("Starting HTTP server", "listen", config.Listen)
err = app.Listen(config.Listen)
if err != nil && err != http.ErrServerClosed {
slog.Error("Failed to start HTTP server", "error", err.Error())
panic(err)
}
}