discovery

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 11 Imported by: 0

README

discovery

discovery 服务服务发现,与服务注册registry对应,支持etcd、consul、nacos三种方式。

使用示例

etcd
func getETCDDiscovery(etcdEndpoints []string) registry.Discovery {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints: etcdEndpoints,
		DialTimeout: 10 * time.Second,
		DialOptions: []grpc.DialOption{
			grpc.WithBlock(),
			grpc.WithTransportCredentials(insecure.NewCredentials()),
		},
	})
	if err != nil {
		panic(err)
	}

	return etcd.New(cli)
}

func discoveryExample() {
    iDiscovery := getETCDDiscovery([]string{"192.168.1.6:2379"})

    // 服务发现的endpoint固定格式discovery:///serviceName
	endpoint := "discovery:///" + "user"
    // grpc客户端
	conn, err := grpccli.DialInsecure(ctx, endpoint,
		grpccli.WithUnaryInterceptors(interceptor.UnaryClientLog(logger.Get())),
		grpccli.WithDiscovery(discovery),
	)
	if err != nil {
		panic(err)
	}

	// ......
}

consul

nacos

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSecure

func IsSecure(u *url.URL) bool

IsSecure parses isSecure for Endpoint URL.

func NewBuilder

func NewBuilder(d registry.Discovery, opts ...Option) resolver.Builder

NewBuilder creates a builder which is used to factory registry resolvers.

Types

type Option

type Option func(o *builder)

Option is builder option.

func DisableDebugLog

func DisableDebugLog() Option

DisableDebugLog disables update instances log.

func WithInsecure

func WithInsecure(insecure bool) Option

WithInsecure with isSecure option.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout with timeout option.

Jump to

Keyboard shortcuts

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