-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (41 loc) · 1008 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
40
41
42
43
44
45
46
47
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
)
func init() {
InitClientRateLimiterMap()
}
func main() {
fmt.Println("Hello!")
defer fmt.Println("Goodbye.")
// start the http server
fmt.Println("Starting server")
srv := InitServer(nil)
go StartServer(srv)
fmt.Println("...done")
// create some clients
fmt.Println("Creating client rate limiters")
for i := 1; i < 11; i++ {
clientRateLimiterMap[fmt.Sprintf("client-%v", i)] = NewLimiter(i, i)
}
fmt.Println("...done")
// block for shutdown
fmt.Println("Application started, waiting for shutdown")
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGTERM) // sigterm is what kubernetes uses to shutdown pods
<-done
fmt.Println("\nReceived shutdown")
fmt.Println("Closing server")
ShutdownServer(srv, context.Background())
fmt.Println("...done")
fmt.Println("Closing clients")
for _, client := range clientRateLimiterMap {
client.Shutdown()
}
fmt.Println("...done")
return
}