github.com/GoogleContainerTools/skaffold@v1.39.18/examples/lifecycle-hooks/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  	"os/signal"
     8  	"syscall"
     9  	"time"
    10  )
    11  
    12  func main() {
    13  	sigs := make(chan os.Signal, 1)
    14  	signal.Notify(sigs, syscall.SIGHUP)
    15  	data, err := ioutil.ReadFile("hello.txt")
    16  	if err != nil {
    17  		fmt.Printf("failed to read file hello.txt: %v", err)
    18  	}
    19  	go func() {
    20  		for range sigs {
    21  			fmt.Printf("received SIGHUP signal. Reloading file hello.txt\n")
    22  			data, err = ioutil.ReadFile("hello.txt")
    23  			if err != nil {
    24  				fmt.Printf("failed to read file hello.txt: %v", err)
    25  			}
    26  		}
    27  	}()
    28  	for {
    29  		fmt.Println(string(data))
    30  		time.Sleep(time.Second * 1)
    31  	}
    32  }