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

56 lines
1.1 KiB
Go
Raw Normal View History

2021-01-03 03:21:11 +00:00
package main
import (
2021-01-04 06:55:41 +00:00
"os"
2021-01-16 22:00:17 +00:00
"os/signal"
2021-01-08 02:45:59 +00:00
"github.com/urfave/cli/v2"
2021-01-10 00:44:02 +00:00
log "github.com/sirupsen/logrus"
2021-01-08 02:45:59 +00:00
2021-01-16 22:00:17 +00:00
"reichard.io/imagini/cmd/server"
2021-01-03 03:21:11 +00:00
)
2021-01-10 00:44:02 +00:00
type UTCFormatter struct {
log.Formatter
}
func (u UTCFormatter) Format(e *log.Entry) ([]byte, error) {
e.Time = e.Time.UTC()
return u.Formatter.Format(e)
}
2021-01-03 03:21:11 +00:00
func main() {
2021-01-10 00:44:02 +00:00
log.SetFormatter(UTCFormatter{&log.TextFormatter{FullTimestamp: true}})
2021-01-16 22:00:17 +00:00
log.Info("Starting Imagini")
2021-01-03 22:31:16 +00:00
app := &cli.App{
Name: "Imagini",
Usage: "A self hosted photo library.",
Commands: []*cli.Command{
2021-01-16 22:00:17 +00:00
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start Imagini web server.",
Action: cmdServer,
},
2021-01-03 22:31:16 +00:00
},
2021-01-03 03:21:11 +00:00
}
2021-01-03 22:31:16 +00:00
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
2021-01-03 03:21:11 +00:00
}
2021-01-16 22:00:17 +00:00
func cmdServer(ctx *cli.Context) error {
server := server.NewServer()
server.StartServer()
c := make(chan os.Signal, 1)
2021-01-18 21:24:28 +00:00
signal.Notify(c, os.Interrupt)
<-c
2021-01-16 22:00:17 +00:00
server.StopServer()
os.Exit(0)
return nil
}