-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (45 loc) · 1.56 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
package main
import (
"embed"
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/jxskiss/mcli"
"github.com/multisig-labs/webauthn-demo/pkg/server"
"github.com/multisig-labs/webauthn-demo/pkg/version"
)
//go:embed public/*
var webContent embed.FS
func main() {
defer handlePanic()
mcli.Add("serve", serveCmd, "Start HTTP server")
mcli.AddHelp()
mcli.AddCompletion()
mcli.Run()
}
func serveCmd() {
args := struct {
Host string `cli:"--host, host" default:"0.0.0.0"`
Port int `cli:"--port, port" default:"8000"`
Db string `cli:"--db, database" default:"data/webauthn.db"`
}{}
mcli.Parse(&args, mcli.WithErrorHandling(flag.ExitOnError))
server.StartServer(args.Host, args.Port, args.Db, webContent)
}
func handlePanic() {
if panicPayload := recover(); panicPayload != nil {
stack := string(debug.Stack())
fmt.Fprintln(os.Stderr, "================================================================================")
fmt.Fprintln(os.Stderr, " Fatal error. Sorry! You found a bug.")
fmt.Fprintln(os.Stderr, "================================================================================")
fmt.Fprintf(os.Stderr, "Version: %s\n", version.Version)
fmt.Fprintf(os.Stderr, "Build Date: %s\n", version.BuildDate)
fmt.Fprintf(os.Stderr, "Git Commit: %s\n", version.GitCommit)
fmt.Fprintf(os.Stderr, "Go Version: %s\n", version.GoVersion)
fmt.Fprintf(os.Stderr, "OS / Arch: %s\n", version.OsArch)
fmt.Fprintf(os.Stderr, "Panic: %s\n\n", panicPayload)
fmt.Fprintln(os.Stderr, stack)
os.Exit(1)
}
}