-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (54 loc) · 1.1 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
package main
import (
"embed"
"io/fs"
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"reichard.io/antholume/config"
"reichard.io/antholume/server"
)
//go:embed templates/* assets/*
var embeddedAssets embed.FS
func main() {
app := &cli.App{
Name: "AnthoLume",
Usage: "A self hosted e-book progress tracker.",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start AnthoLume web server.",
Action: cmdServer,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func cmdServer(ctx *cli.Context) error {
var assets fs.FS = embeddedAssets
// Load config
c := config.Load()
if c.Version == "develop" {
assets = os.DirFS("./")
}
log.Info("Starting AnthoLume Server")
// Create notify channel
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
// Start server
s := server.New(c, assets)
s.Start()
// Wait & close
<-signals
s.Stop()
// Stop server
os.Exit(0)
return nil
}