-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (35 loc) · 972 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (35 loc) · 972 Bytes
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
40
41
42
package main
import (
"context"
"log"
"os"
"os/signal"
"plainrandom/config"
"plainrandom/server"
)
func main() {
// Setting up a signal handler to receive kill signal.
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1) // Single buffer that takes os.Signal items
signal.Notify(c, os.Interrupt) // os.Interrupt is CTRL + C signal, will notify the c channel
// Start a goroutine to read channel and instantiate cancel functions on os trigger.
go func() { <-c; cancel() }()
// Execute program.
log.Printf("Starting Application...")
//
// Creates a new Main object
conf := config.NewConfig()
s := server.NewServer(conf)
//
// Starts the API server
s.Start()
//
// Line to wait for CTRL-C
<-ctx.Done()
// Start shutting down
log.Printf("Shutting down Server...")
if err := s.Stop(ctx); err != nil {
panic(err) // failure/timeout shutting down the server gracefully
}
log.Printf("main: done. exiting")
}