resolve

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 4 Imported by: 0

README

resolve

Example of use

grpc client
func getDialOptions() []grpc.DialOption {
	var options []grpc.DialOption

	// use insecure transfer
	options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials()))

	// load balancing policy, polling https://github.com/grpc/grpc-go/tree/master/examples/features/load_balancing
	// https://github.com/grpc/grpc/blob/master/doc/service_config.md
	options = append(options, grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`))

	return options
}

func main() {
	endpoint := resolve.Register("grpc", "hello.grpc.io", []string{"127.0.0.1:8282", "127.0.0.1:8284", "127.0.0.1:8286"})
	roundRobinConn, err := grpc.Dial(endpoint, getDialOptions()...)
	if err != nil {
		panic(err)
	}
	defer roundRobinConn.Close()

	client := serverNameV1.NewGreeterClient(roundRobinConn)
	for {
		err = sayHello(client)
		if err != nil {
			panic(err)
		}
		time.Sleep(time.Second * 2)
	}
}

Documentation

Overview

Package resolve is setting grpc client-side load balancing policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(scheme string, serviceName string, address []string) string

Register address and serviceName

Types

type ResolverBuilder

type ResolverBuilder struct {
	// contains filtered or unexported fields
}

ResolverBuilder resolver struct

func (*ResolverBuilder) Build

Build resolver

func (*ResolverBuilder) Scheme

func (r *ResolverBuilder) Scheme() string

Scheme get scheme

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL