alps/cmd/koushin/main.go

60 lines
1.1 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"
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")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream server...>\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())
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
}