...

Source file src/golang.conradwood.net/go-easyops/client/stop-service/stop-service.go

Documentation: golang.conradwood.net/go-easyops/client/stop-service

     1  /*
     2  contains an example of how to use the /internal/ api of gRPC servers to shutdown a server gracefully.
     3  */
     4  package main
     5  
     6  import (
     7  	"crypto/tls"
     8  	"flag"
     9  	"fmt"
    10  	"net/http"
    11  	"os"
    12  	"strings"
    13  )
    14  
    15  var (
    16  	service = flag.String("service", "", "Service to shutdown, either host:port or name")
    17  )
    18  
    19  func main() {
    20  	flag.Parse()
    21  	target := *service
    22  	if target == "" {
    23  		target = flag.Arg(0)
    24  	}
    25  	if target == "" {
    26  		fmt.Printf("Please provide service name or host:port with --service option\n")
    27  		os.Exit(10)
    28  	}
    29  	fmt.Printf("Shutting down service: %s\n", target)
    30  	if strings.Contains(target, ":") {
    31  		doHttp(target)
    32  	} else {
    33  		doRegistry()
    34  	}
    35  }
    36  func doHttp(target string) {
    37  	tr := &http.Transport{
    38  		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    39  	}
    40  	client := &http.Client{Transport: tr}
    41  	url := fmt.Sprintf("https://%s/internal/pleaseshutdown", target)
    42  	resp, err := client.Get(url)
    43  	if err != nil {
    44  		fmt.Printf("Failed to connect to %s: %s\n", url, err)
    45  	} else {
    46  		fmt.Printf("Response: %v\n", resp)
    47  	}
    48  }
    49  func doRegistry() {
    50  
    51  }
    52  

View as plain text