init Project ✌️✌️
This commit is contained in:
commit
8a6dc19bdd
42 changed files with 249179 additions and 0 deletions
43
server/main.go
Normal file
43
server/main.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := NewServer(3000)
|
||||
|
||||
serverCtx, serverStopCtx := context.WithCancel(context.Background())
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
go func() {
|
||||
<-sig
|
||||
|
||||
shutdownCtx, _ := context.WithTimeout(serverCtx, 30*time.Second)
|
||||
|
||||
go func() {
|
||||
<-shutdownCtx.Done()
|
||||
if shutdownCtx.Err() == context.DeadlineExceeded {
|
||||
log.Println("Shutdown timeout, force exit")
|
||||
}
|
||||
}()
|
||||
|
||||
err := s.Shutdown(shutdownCtx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
serverStopCtx()
|
||||
}()
|
||||
|
||||
err := s.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
<-serverCtx.Done()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue