AnthoLume/main.go

67 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-09-18 23:57:18 +00:00
package main
import (
2023-11-29 03:01:49 +00:00
"embed"
"io/fs"
2023-09-18 23:57:18 +00:00
"os"
"os/signal"
"syscall"
2023-09-18 23:57:18 +00:00
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"reichard.io/antholume/config"
"reichard.io/antholume/server"
2023-09-18 23:57:18 +00:00
)
2023-11-29 03:01:49 +00:00
//go:embed templates/* assets/*
var embeddedAssets embed.FS
2023-11-29 03:01:49 +00:00
2023-09-18 23:57:18 +00:00
func main() {
app := &cli.App{
Name: "AnthoLume",
Usage: "A self hosted e-book progress tracker.",
EnableBashCompletion: true,
2023-09-18 23:57:18 +00:00
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
2023-11-04 23:40:32 +00:00
Usage: "Start AnthoLume web server.",
2023-09-18 23:57:18 +00:00
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("./")
}
2023-11-04 23:40:32 +00:00
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()
2023-09-18 23:57:18 +00:00
// Wait & close
<-signals
s.Stop()
2023-09-18 23:57:18 +00:00
// Stop server
2023-09-18 23:57:18 +00:00
os.Exit(0)
return nil
}