10 handler "hdfs-writer/pkg/handler"
11 pipeline "hdfs-writer/pkg/pipeline"
12 utils "hdfs-writer/pkg/utils"
17 slogger := utils.GetLoggerInstance()
20 httpServer := &http.Server{
21 Handler: handler.CreateRouter(),
25 connectionsClose := make(chan bool)
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 pipeline.ChannelMap {
33 slogger.Info("Begin:: Closing writer goroutines::")
34 slogger.Infof("Closing writer goroutine :: %s", eachWriter)
35 delete(pipeline.ChannelMap, eachWriter)
39 httpServer.Shutdown(context.Background())
40 /*once all goroutines are signalled and httpServer is shutdown,
41 send close to main thread */
42 connectionsClose <- true
43 close(connectionsClose)
46 // Sever starts listening
47 err := httpServer.ListenAndServe()
48 if err != nil && err != http.ErrServerClosed {
52 <-connectionsClose //main thread waiting to receive close signal