forked from peer-calls/peer-calls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (71 loc) · 1.94 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
77
78
79
80
81
82
83
84
package main
import (
"context"
"embed"
"io/fs"
"os"
"github.com/juju/errors"
"github.com/peer-calls/peer-calls/v4/server"
"github.com/peer-calls/peer-calls/v4/server/cli"
"github.com/peer-calls/peer-calls/v4/server/logformatter"
"github.com/peer-calls/peer-calls/v4/server/logger"
"github.com/peer-calls/peer-calls/v4/server/multierr"
"github.com/spf13/pflag"
)
//nolint:gochecknoglobals
//go:embed server/templates/*.html
var templatesFS embed.FS
//nolint:gochecknoglobals
//go:embed build/*.js build/style.css
var staticFS embed.FS
//nolint:gochecknoglobals
//go:embed res/*
var resourcesFS embed.FS
// GitDescribe contains the version information.
// nolint:gochecknoglobals
var GitDescribe = "v0.0.0"
func mustSub(dir fs.FS, path string) fs.FS {
fs, err := fs.Sub(dir, path)
if err != nil {
panic(err)
}
return fs
}
func start(ctx context.Context, log logger.Logger, args []string) error {
err := cli.Exec(ctx, cli.Props{
Log: log,
Version: GitDescribe,
Args: args,
Embed: server.Embed{
Resources: mustSub(resourcesFS, "res"),
Templates: mustSub(templatesFS, "server/templates"),
Static: mustSub(staticFS, "build"),
},
})
return errors.Trace(err)
}
func main() {
log := logger.New().
WithConfig(
logger.NewConfig(logger.ConfigMap{
"**:sdp": logger.LevelError,
"**:ws": logger.LevelError,
"**:nack": logger.LevelError,
"**:signaller:**": logger.LevelError,
"**:pion:**": logger.LevelWarn,
"**:pubsub": logger.LevelTrace,
"**:factory": logger.LevelTrace,
"": logger.LevelInfo,
}),
).
WithConfig(logger.NewConfigFromString(os.Getenv("PEERCALLS_LOG"))).
WithFormatter(logformatter.New()).
WithNamespaceAppended("main")
err := start(context.Background(), log, os.Args[1:])
if multierr.Is(err, pflag.ErrHelp) {
os.Exit(1)
} else if err != nil {
log.Error("Command error", errors.Trace(err), nil)
os.Exit(1)
}
}