rest-api/main.go

33 lines
452 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"
2020-09-15 23:09:07 +02:00
"fmt"
2020-09-17 18:01:18 +02:00
"log"
"os"
"os/signal"
"time"
2020-09-15 23:09:07 +02:00
)
func main() {
fmt.Println("Hello world!")
s := Server{
2020-09-17 18:01:18 +02:00
port: ":9999",
2020-09-15 23:09:07 +02:00
}
2020-09-17 18:01:18 +02:00
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)
2020-09-15 23:09:07 +02:00
}