consul

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 2 Imported by: 0

README

go-consul

go-consulfirefly 体系中基于 Consul 的基础接入库,当前主要提供两类能力:

  • Consul 客户端初始化(根包)
  • 轻量服务调用实现(invocation 子包)

包结构

  • conf.go:Consul 客户端配置模型
  • core.go:根据配置创建 *api.Client
  • invocation/:面向 service -> service 的轻量服务调用实现

当前状态

  • registry 子包已废弃并移除
  • 裸机业务服务统一改走 go-micro/registry/agent -> sidecar-agent -> consul / envoy
  • go-consul 当前只保留 Consul 客户端能力与 invocation 调用能力

客户端初始化

package main

import (
	consulx "github.com/fireflycore/go-consul"
)

func main() {
	client, err := consulx.New(&consulx.Conf{
		Address:    "127.0.0.1:8500",
		Scheme:     "http",
		Datacenter: "dc1",
	})
	if err != nil {
		panic(err)
	}

	_ = client
}

调用能力

当前推荐只使用:

  • invocation/README.md

设计约束

  • 业务服务不做服务发现,只做服务注册
  • 服务发现能力不再通过 go-consul/registry 暴露给业务侧
  • Consul 特有能力由 sidecar-agent 或仓库内部基础能力承接,不再对外暴露 registry 子包
  • 新的服务调用主路径应优先围绕 invocation 收敛

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c *Conf) (*api.Client, error)

New 根据入参创建 Consul API 客户端。

Types

type Conf

type Conf struct {
	// Address 是 Consul HTTP API 地址,例如 127.0.0.1:8500。
	Address string `json:"address"`
	// Scheme 是访问协议,常见值为 http 或 https。
	Scheme string `json:"scheme"`
	// Datacenter 指定目标数据中心。
	Datacenter string `json:"datacenter"`
	// Token 是 ACL 访问令牌。
	Token string `json:"token"`

	// TLS 配置 HTTPS 连接参数。
	TLS *TLS `json:"tls"`
}

Conf 定义 Consul 客户端初始化配置。

type TLS

type TLS struct {
	// Enable 表示是否启用 TLS 配置。
	Enable bool `json:"enable"`
	// CaFile 指向 CA 证书文件路径。
	CaFile string `json:"ca_file"`
	// CertFile 指向客户端证书文件路径。
	CertFile string `json:"cert_file"`
	// KeyFile 指向客户端私钥文件路径。
	KeyFile string `json:"key_file"`
	// InsecureSkipVerify 控制是否跳过服务端证书校验。
	InsecureSkipVerify bool `json:"insecure_skip_verify"`
}

TLS 定义 Consul TLS 连接选项。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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