github.com/mattevans/edward@v1.9.2/edward/testdata/generate/emptyconfig/edward-test-service/main.go (about)

     1  // A simple executable that stays runnning until an interrupt is received
     2  // Based on: https://gobyexample.com/signals
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"log"
     8  	"net/http"
     9  	"os"
    10  	"os/signal"
    11  	"time"
    12  )
    13  
    14  func main() {
    15  	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    16  		fmt.Fprintf(w, "Hello: %s!", r.URL.Path[1:])
    17  	})
    18  
    19  	go func() {
    20  		log.Fatal(http.ListenAndServe(":0", nil))
    21  	}()
    22  
    23  	timer := time.NewTimer(5 * time.Second)
    24  	defer timer.Stop()
    25  
    26  	stop := make(chan os.Signal, 1)
    27  	signal.Notify(stop, os.Interrupt)
    28  
    29  	select {
    30  	case <-stop:
    31  		fmt.Println("Terminated")
    32  	case <-timer.C:
    33  		fmt.Println("Timed out")
    34  	}
    35  
    36  	fmt.Println("Exiting")
    37  }