AnthoLume/main.go
Evan Reichard 761163d666
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
[add] migrate to percentages vs pages
[add] task runner
[fix] calculate word count on upload
[remove] unused queries
2023-11-03 19:38:35 -04:00

66 lines
1.1 KiB
Go

package main
import (
"os"
"os/signal"
"sync"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"reichard.io/bbank/server"
)
type UTCFormatter struct {
log.Formatter
}
func (u UTCFormatter) Format(e *log.Entry) ([]byte, error) {
e.Time = e.Time.UTC()
return u.Formatter.Format(e)
}
func main() {
log.SetFormatter(UTCFormatter{&log.TextFormatter{FullTimestamp: true}})
app := &cli.App{
Name: "Book Manager",
Usage: "A self hosted e-book progress tracker.",
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start Book Manager web server.",
Action: cmdServer,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func cmdServer(ctx *cli.Context) error {
log.Info("Starting Book Manager Server")
// Create Channel
wg := sync.WaitGroup{}
done := make(chan struct{})
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
// Start Server
server := server.NewServer()
server.StartServer(&wg, done)
// Wait & Close
<-interrupt
server.StopServer(&wg, done)
// Stop Server
os.Exit(0)
return nil
}