golang.org/x/playground@v0.0.0-20230418134305-14ebe15bcd59/internal/gcpdial/gcpdialtool/gcpdialtool.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // The gcpdialtool command is an interactive validation tool for the
     6  // gcpdial package.
     7  package main
     8  
     9  import (
    10  	"context"
    11  	"flag"
    12  	"log"
    13  	"os"
    14  	"time"
    15  
    16  	"golang.org/x/playground/internal/gcpdial"
    17  )
    18  
    19  var (
    20  	proj   = flag.String("project", "golang-org", "GCP project name")
    21  	region = flag.String("region", "us-central1", "GCP region")
    22  	group  = flag.String("group", "play-sandbox-rigm", "regional instance group name")
    23  )
    24  
    25  func main() {
    26  	flag.Parse()
    27  	log.SetOutput(os.Stdout)
    28  	log.SetFlags(log.Flags() | log.Lmicroseconds)
    29  
    30  	log.Printf("starting")
    31  	d := gcpdial.NewRegionInstanceGroupDialer(*proj, *region, *group)
    32  
    33  	ctx := context.Background()
    34  	for {
    35  		ip, err := d.PickIP(ctx)
    36  		if err != nil {
    37  			log.Fatal(err)
    38  		}
    39  		log.Printf("picked %v", ip)
    40  		time.Sleep(time.Second)
    41  	}
    42  }