This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/cmd/main.go
2021-01-18 16:24:28 -05:00

56 lines
1.1 KiB
Go

package main
import (
"os"
"os/signal"
"github.com/urfave/cli/v2"
log "github.com/sirupsen/logrus"
"reichard.io/imagini/cmd/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}})
log.Info("Starting Imagini")
app := &cli.App{
Name: "Imagini",
Usage: "A self hosted photo library.",
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start Imagini web server.",
Action: cmdServer,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func cmdServer(ctx *cli.Context) error {
server := server.NewServer()
server.StartServer()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
server.StopServer()
os.Exit(0)
return nil
}