11 handler "hdfs-writer/pkg/handler"
12 utils "hdfs-writer/pkg/utils"
17 slogger := utils.GetLoggerInstance()
20 httpServer := &http.Server{
21 Handler: handler.CreateRouter(),
25 connectionsClose := make(chan struct{})
27 c := make(chan os.Signal, 1)
28 signal.Notify(c, os.Interrupt)
29 <-c // function literal waiting to receive Interrupt signal
30 fmt.Printf(":::Got the kill signal:::")
31 slogger.Info(":::Got the kill signal:::")
32 for eachWriter, eachChannel := range handler.ChannelMap {
33 slogger.Infof("Closing writer goroutine :: %s", eachWriter)
34 slogger.Infof("eachChannel:: %v", eachChannel)
36 // This wait time ensures that the each of the channel is killed before
37 // main routine finishes.
38 time.Sleep(time.Second * 5)
40 //once all goroutines are signalled, send close to main thread
41 httpServer.Shutdown(context.Background())
42 close(connectionsClose)
45 // Sever starts listening
46 err := httpServer.ListenAndServe()
47 if err != nil && err != http.ErrServerClosed {
50 <-connectionsClose //main thread waiting to receive close signal