fix unsubscribe for go http example

Signed-off-by: Sarthak Sharma <sartsharma@microsoft.com>
This commit is contained in:
Sarthak Sharma 2022-11-22 00:07:08 +05:30
parent e9d3da9dc0
commit e7cfccf383
1 changed files with 3 additions and 7 deletions

View File

@ -93,20 +93,16 @@ func startServerToListen(subscriptionId *string) {
}
r.HandleFunc("/configuration/configstore/{configItem}", configUpdateHandler).Methods("POST")
// Shutdown Server after 20 seconds
// Unsubscribe to config updates and shutdown http server after 20 seconds
time.AfterFunc(20*time.Second, func() {
unsubscribeFromConfigUpdates(*subscriptionId)
fmt.Println("Shutting down HTTP server")
err := httpServer.Shutdown(context.Background())
if err != nil {
fmt.Println("Error shutting down HTTP server, err:" + err.Error())
}
})
// Register shutdown function
httpServer.RegisterOnShutdown(func() {
fmt.Println("Shutting down HTTP server")
unsubscribeFromConfigUpdates(*subscriptionId)
})
// Start HTTP server
if err := httpServer.ListenAndServe(); err != nil {
log.Println("HTTP server error:", err)