Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewResolver ¶
NewResolver creates a naming resolver
Example ¶
const target = "helloworld" // Create a round-robin load-balancer balancer := grpc.RoundRobin(NewResolver(&Options{ Address: "127.0.0.1:8383", })) // Set up a load-balanced connection to the server. conn, err := grpc.Dial(target, grpc.WithInsecure(), grpc.WithBalancer(balancer)) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewGreeterClient(conn) r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "world"}) if err != nil { log.Fatalf("could not greet: %v", err) } log.Printf("Greeting: %s", r.Message)
Output:
func PickFirst ¶
PickFirst returns a Balancer that always selects the first address returned from the Resolver
Example ¶
const target = "helloworld" // Create a pick-first load-balancer balancer := PickFirst(&Options{ Address: "127.0.0.1:8383", }) // Set up a load-balanced connection to the server. conn, err := grpc.Dial(target, grpc.WithInsecure(), grpc.WithBalancer(balancer)) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewGreeterClient(conn) r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "world"}) if err != nil { log.Fatalf("could not greet: %v", err) } log.Printf("Greeting: %s", r.Message)
Output:
Types ¶
type Options ¶
type Options struct { // Address is the address of the load balancer. // Default: 127.0.0.1:8383 Address string // DialOptions define custom dial options. // Default: [WithInsecure]. DialOptions []grpc.DialOption // UpdateInterval is the query interval for // updating known servers. // Default: 2s UpdateInterval time.Duration }
Options is the picker configuration
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
discovery
|
|
consul
Package consul implements grpclb service discovery via Consul (consul.io).
|
Package consul implements grpclb service discovery via Consul (consul.io). |
Package grpclb_backend_v1 is a generated protocol buffer package.
|
Package grpclb_backend_v1 is a generated protocol buffer package. |
Package grpclb_balancer_v1 is a generated protocol buffer package.
|
Package grpclb_balancer_v1 is a generated protocol buffer package. |
Package load include helpers for building grpclb compatible servers.
|
Package load include helpers for building grpclb compatible servers. |
Click to show internal directories.
Click to hide internal directories.