rest-api/main.go

29 lines
435 B
Go
Raw Normal View History

2020-09-15 23:09:07 +02:00
package main
import (
2020-09-17 18:01:18 +02:00
"context"
"go-rest-api/server"
2020-09-17 18:01:18 +02:00
"log"
"os"
"os/signal"
"time"
2020-09-15 23:09:07 +02:00
)
func main() {
s := server.NewServer(":8000")
2020-09-17 18:01:18 +02:00
go func() {
s.Serve()
2020-09-17 18:01:18 +02:00
}()
signCh := make(chan os.Signal)
signal.Notify(signCh, os.Interrupt)
signal.Notify(signCh, os.Kill)
sig := <-signCh
log.Println("Received terminal, graceful shutdown", sig)
tc, _ := context.WithTimeout(context.Background(), 30*time.Second)
s.Shutdown(tc)
2020-09-15 23:09:07 +02:00
}