...

Source file src/golang.conradwood.net/go-easyops/registry/pkg.go

Documentation: golang.conradwood.net/go-easyops/registry

     1  /*
     2  connect to a registry. used by many other go-easyops packages.
     3  */
     4  package registry
     5  
     6  import (
     7  	pb "golang.conradwood.net/apis/registry"
     8  	"golang.conradwood.net/go-easyops/utils"
     9  	"google.golang.org/grpc"
    10  	"strings"
    11  	"time"
    12  )
    13  
    14  const (
    15  	CONST_CALL_TIMEOUT = 4
    16  )
    17  
    18  // get a registry client from a specific ip
    19  func Client(ip string) (pb.RegistryClient, error) {
    20  	if !strings.Contains(ip, ":") {
    21  		ip = ip + ":5000"
    22  	}
    23  	conn, err := grpc.Dial(ip, grpc.WithInsecure(), grpc.WithTimeout(time.Duration(CONST_CALL_TIMEOUT)*time.Second))
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	r := pb.NewRegistryClient(conn)
    28  	return r, nil
    29  }
    30  
    31  // get a registry client from a specific ip, panic if it cannot
    32  func ClientOrPanic(ip string) pb.RegistryClient {
    33  	conn, err := grpc.Dial(ip, grpc.WithInsecure(), grpc.WithTimeout(time.Duration(CONST_CALL_TIMEOUT)*time.Second))
    34  	utils.Bail("Failed to get registry client at ip "+ip, err)
    35  	r := pb.NewRegistryClient(conn)
    36  	return r
    37  }
    38  

View as plain text