gohttp/main.go

42 lines
704 B
Go
Raw Normal View History

2023-12-07 00:22:53 +08:00
package main
import (
2023-12-07 22:42:27 +08:00
"os"
"os/signal"
"syscall"
2023-12-10 19:26:09 +08:00
"git.pyer.club/kingecg/godaemon"
2023-12-13 10:59:47 +08:00
"git.pyer.club/kingecg/gologger"
2023-12-07 00:22:53 +08:00
)
func main() {
2023-12-13 17:59:14 +08:00
LoadConfig()
2023-12-13 10:59:47 +08:00
l := gologger.GetLogger("main")
defer func() {
if err := recover(); err != nil {
l.Error("panic", err)
}
}()
2023-12-10 19:26:09 +08:00
daemon := godaemon.NewGoDaemon(start, stop)
daemon.Start()
}
2023-12-13 09:22:05 +08:00
var waiter chan os.Signal
2023-12-10 19:26:09 +08:00
func start(g *godaemon.GoDaemon) {
2023-12-13 09:22:05 +08:00
waiter = make(chan os.Signal, 1) // buffered channel
2023-12-07 22:42:27 +08:00
signal.Notify(waiter, syscall.SIGTERM, syscall.SIGINT)
2023-12-10 19:26:09 +08:00
httpd := &GoHttp{}
httpd.Start()
2023-12-07 22:42:27 +08:00
// blocks here until there's a signal
<-waiter
2023-12-13 09:22:05 +08:00
httpd.logger.Info("Exit")
2023-12-10 19:26:09 +08:00
}
2023-12-08 22:02:36 +08:00
2023-12-10 19:26:09 +08:00
func stop(g *godaemon.GoDaemon) {
g.Running.Process.Signal(syscall.SIGTERM)
2023-12-07 00:22:53 +08:00
}