alps/cmd/koushin/main.go

70 lines
1.5 KiB
Go
Raw Normal View History

2019-12-02 14:31:00 +00:00
package main
import (
"flag"
2019-12-02 16:24:19 +00:00
"fmt"
"os"
"os/signal"
"syscall"
2019-12-02 16:24:19 +00:00
2019-12-02 14:31:00 +00:00
"git.sr.ht/~emersion/koushin"
"github.com/labstack/echo/v4"
2019-12-02 14:31:00 +00:00
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
_ "git.sr.ht/~emersion/koushin/plugins/base"
_ "git.sr.ht/~emersion/koushin/plugins/caldav"
_ "git.sr.ht/~emersion/koushin/plugins/carddav"
_ "git.sr.ht/~emersion/koushin/plugins/lua"
2020-02-12 13:42:51 +00:00
_ "git.sr.ht/~emersion/koushin/plugins/viewhtml"
_ "git.sr.ht/~emersion/koushin/plugins/viewtext"
2019-12-02 14:31:00 +00:00
)
func main() {
var options koushin.Options
2020-01-08 11:01:50 +00:00
var addr string
flag.StringVar(&options.Theme, "theme", "", "default theme")
2020-01-08 11:01:50 +00:00
flag.StringVar(&addr, "addr", ":1323", "listening address")
2020-02-11 17:39:52 +00:00
flag.BoolVar(&options.Debug, "debug", false, "enable debug logs")
flag.Usage = func() {
2020-02-11 17:39:52 +00:00
fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream servers...>\n")
flag.PrintDefaults()
2019-12-02 16:24:19 +00:00
}
flag.Parse()
2019-12-02 16:24:19 +00:00
options.Upstreams = flag.Args()
if len(options.Upstreams) == 0 {
flag.Usage()
return
2019-12-03 14:21:59 +00:00
}
e := echo.New()
2020-01-16 23:22:11 +00:00
e.HideBanner = true
if l, ok := e.Logger.(*log.Logger); ok {
l.SetHeader("${time_rfc3339} ${level}")
}
s, err := koushin.New(e, &options)
if err != nil {
e.Logger.Fatal(err)
}
2019-12-02 14:31:00 +00:00
e.Use(middleware.Recover())
2020-02-11 17:39:52 +00:00
if options.Debug {
e.Logger.SetLevel(log.DEBUG)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGUSR1)
go func() {
for range sigs {
if err := s.Reload(); err != nil {
e.Logger.Errorf("Failed to reload server: %v", err)
}
}
}()
2020-01-08 11:01:50 +00:00
e.Logger.Fatal(e.Start(addr))
2019-12-02 14:31:00 +00:00
}