32 lines
472 B
Go
32 lines
472 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go-rest-api/server"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Hello world!")
|
|
|
|
s := server.NewServer(":9999")
|
|
|
|
go func() {
|
|
s.Serve()
|
|
}()
|
|
|
|
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)
|
|
}
|