func wait(signals ...os.Signal) {
	terminate := make(chan os.Signal)
	signal.Notify(terminate, signals...)
	defer log.Printf("Caught signal: shutting down.\n")
	for {
		select {
		case <-terminate:
			return
		}
	}
}
wait unitl SIGINT or SIGTERM return
package main
import (
	"encoding/json"
	"flag"
	"fmt"
	"log"
	"net"
	"net/http"
	"net/url"
	"os"
	"os/signal"
	"strconv"
	"strings"
	"syscall"
	"time"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudwatch"
	"github.com/otm/cloudwatch-alarm-exporter/alertmanager"
	"github.com/otm/cloudwatch-alarm-exporter/collector"
	"github.com/prometheus/client_golang/prometheus"
)
func main() {
	portFlag := flag.Int("port", 8080, "The HTTP `port` to listen to")
	regionFlag := flag.String("region", "", "The AWS region to use, eg 'eu-west-1'")
	retriesFlag := flag.Int("retries", 1, "The `number` of retries when fetchinh alarms")
	alertManagerFlag := flag.String("alertmanager", "", "`URL` to alert manager")
	refreshIntervalFlag := flag.Int("refresh", 10, "Time in `seconds` between refreshing alarms")
	flag.Parse()
	if *regionFlag == "" {
		*regionFlag = os.Getenv("AWS_REGION")
	}
	sess, err := session.NewSession(&aws.Config{
		Region:     regionFlag,
		MaxRetries: retriesFlag,
	})
	if err != nil {
		log.Fatalf("Unable to create session: %s", err)
	}
	cw := cloudwatch.New(sess)
	ca := CloudwatchAlarms{
		alarmDescriber: cw,
	}
	if *alertManagerFlag != "" {
		alertManagerURL, err := url.Parse(*alertManagerFlag)
		fmt.Println(alertManagerURL.ResolveReference(alertManagerURL))
		if true {
			return
		}
		if err != nil {
			log.Fatalf("not a valid AlertManger URL: %s", *alertManagerFlag)
		}
		alertmanager.New(*alertManagerURL, ca, time.Duration(*refreshIntervalFlag)*time.Second)
	}
	listener, err := net.ListenTCP("tcp", &net.TCPAddr{
		Port: *portFlag,
	})
	if err != nil {
		log.Fatalf("unable to create listener: %v", err)
	}
	prometheus.Unregister(prometheus.NewGoCollector())
	prometheus.Unregister(prometheus.NewProcessCollector(os.Getpid(), ""))
	prometheus.MustRegister(collector.New(&ca))
	server := httpServer{
		listener:      listener,
		healthChecker: AlwaysHealthy{},
		alarmFetcher:  ca,
	}
	server.start()
	log.Printf("Service: online\n")
	wait(syscall.SIGINT, syscall.SIGTERM)
}