Some stuff and profilers into server

This commit is contained in:
qowevisa 2024-06-09 07:38:54 +03:00
parent 6752ce2771
commit 40e74e6bd3

View File

@ -8,12 +8,23 @@ import (
"io" "io"
"log" "log"
"net" "net"
"os"
"os/signal"
"sync"
"syscall"
com "git.qowevisa.me/Qowevisa/gotell/communication" com "git.qowevisa.me/Qowevisa/gotell/communication"
"git.qowevisa.me/Qowevisa/gotell/env" "git.qowevisa.me/Qowevisa/gotell/env"
"git.qowevisa.me/Qowevisa/gotell/profilers"
) )
func atEnd() {
profilers.GetMemoryProfiler()
}
func main() { func main() {
cpuProfDefer := profilers.GetCPUProfiler()
defer cpuProfDefer()
userCenter.Init() userCenter.Init()
linkCenter.Init() linkCenter.Init()
connCenter.Init() connCenter.Init()
@ -41,8 +52,23 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("server: listen: %s", err) log.Fatalf("server: listen: %s", err)
} }
defer listener.Close()
log.Printf("server: listening on %s", service) log.Printf("server: listening on %s", service)
defer atEnd()
var wg sync.WaitGroup
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
log.Println("received shutdown signal")
listener.Close()
wg.Wait()
os.Exit(0)
}()
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err != nil { if err != nil {