github.com/mattevans/edward@v1.9.2/edward/testdata/tick/simple1/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  	"net/http"
     8  	"os"
     9  	"time"
    10  )
    11  
    12  func handler(w http.ResponseWriter, r *http.Request) {
    13  	fmt.Fprintf(w, "Hello: %s!", r.URL.Path[1:])
    14  }
    15  
    16  func main() {
    17  	http.HandleFunc("/", handler)
    18  	fmt.Println("Starting to listen on port", os.Args[1])
    19  
    20  	go func() {
    21  		c := time.Tick(1 * time.Second)
    22  		for now := range c {
    23  			fmt.Printf("%v %s\n", now, "Tick")
    24  		}
    25  	}()
    26  
    27  	http.ListenAndServe(":"+os.Args[1], nil)
    28  }