-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
39 lines (34 loc) · 829 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
"github.com/jordan-wright/http-boilerplate/server"
"golang.org/x/crypto/acme/autocert"
)
func main() {
// This is the domain the server should accept connections for.
domains := []string{"example.com", "www.example.com"}
handler := server.NewRouter()
srv := &http.Server{
Addr: ":443",
Handler: handler,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}
// Start the server
go func() {
srv.Serve(autocert.NewListener(domains...))
}()
// Wait for an interrupt
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
// Attempt a graceful shutdown
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
srv.Shutdown(ctx)
}