-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (51 loc) 路 1.02 KB
/
Copy pathmain.go
File metadata and controls
62 lines (51 loc) 路 1.02 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
package main
import (
"embed"
"io/fs"
"log/slog"
"os"
_ "embed"
"github.com/robherley/etherlighter/internal/config"
"github.com/robherley/etherlighter/internal/device"
"github.com/robherley/etherlighter/internal/server"
)
var (
//go:embed web/*
webFS embed.FS
)
func run() error {
cfg, err := config.Load()
if err != nil {
cfg.Help(err)
}
log := slog.With("device", cfg.DeviceAddr, "listen", cfg.ListenAddr)
log.Info("connecting")
client, err := device.Connect(cfg)
if err != nil {
return err
}
defer client.Close()
log.Info("connected!")
var files fs.FS
if cfg.DevMode {
log.Warn("development mode enabled, web assets will be reloaded on every request")
files = os.DirFS("web")
} else {
files, err = fs.Sub(webFS, "web")
if err != nil {
return err
}
}
log.Info("starting server")
server, err := server.New(cfg, files, client)
if err != nil {
return err
}
return server.ListenAndServe()
}
func main() {
if err := run(); err != nil {
slog.Error("failed", "error", err)
os.Exit(1)
}
}