github.com/mattevans/edward@v1.9.2/edward/testdata/generate/groupwithconfig/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 handler(w http.ResponseWriter, r *http.Request) {
    15  	fmt.Fprintf(w, "Hello: %s!", r.URL.Path[1:])
    16  }
    17  
    18  func main() {
    19  	http.HandleFunc("/", handler)
    20  
    21  	port := "51936"
    22  	fmt.Printf("Starting to listen on %v\n", port)
    23  	go func() {
    24  		log.Fatal(http.ListenAndServe(":"+port, nil))
    25  	}()
    26  
    27  	timer := time.NewTimer(5 * time.Second)
    28  	defer timer.Stop()
    29  
    30  	stop := make(chan os.Signal, 1)
    31  	signal.Notify(stop, os.Interrupt)
    32  
    33  	select {
    34  	case <-stop:
    35  		fmt.Println("Terminated")
    36  	case <-timer.C:
    37  		fmt.Println("Timed out")
    38  	}
    39  
    40  	fmt.Println("Exiting")
    41  }