consul

package
v0.0.0-...-6a0a93c Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

pkg/discovery/consul_discovery.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsulClient

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

func NewConsulClient

func NewConsulClient(addr string) (*ConsulClient, error)

func (*ConsulClient) DeregisterService

func (c *ConsulClient) DeregisterService(id string) error

func (*ConsulClient) GetKV

func (c *ConsulClient) GetKV(key string) ([]byte, error)

GetKV 从 Consul KV 读取数据

func (*ConsulClient) PutKV

func (c *ConsulClient) PutKV(key string, value []byte) error

PutKV 将数据写入 Consul KV,key 如 config/app.yaml

func (*ConsulClient) RegisterService

func (c *ConsulClient) RegisterService(id, name, address string, port int, tags []string) error

func (*ConsulClient) WatchKey

func (c *ConsulClient) WatchKey(ctx context.Context, key string, waitIndex uint64) ([]byte, uint64, error)

Example: Watch KV key changes (simple blocking query)

type Discovery

type Discovery interface {
	// GetGRPCConn 获取指定服务的 gRPC 连接
	GetGRPCConn(serviceName string) (*grpc.ClientConn, error)
}

func NewConsulDiscovery

func NewConsulDiscovery(addr string) (Discovery, error)

type ServiceRegistration

type ServiceRegistration struct {
	ID      string
	Name    string
	Address string
	Port    int
	Client  *api.Client
}

Jump to

Keyboard shortcuts

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