consulcli

package
v1.4.54 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

consulcli

Connect to the consul service client.

Example of use

    import "github.com/18721889353/sunshine/pkg/consulcli"

    addr := "192.168.3.37:8500"

    // Way 1: setting parameters
    cli, err := consulcli.Init(addr,
        consulcli.WithWaitTime(time.Second*5),
        // consulcli.WithDatacenter(""),
    )

    // Way 2: setting up api.Config
    cli, err = Init("", consulcli.WithConfig(&api.Config{
        Address:    addr,
        Scheme:     "http",
        WaitTime:   time.Second * 5,
        Datacenter: "",
    }))

Documentation

Overview

Package consulcli 是连接到 Consul 服务的客户端包。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(addr string, opts ...Option) (*api.Client, error)

Init 初始化连接到 Consul 服务 参数: - addr: Consul 服务器的地址,如果设置了 WithConfig(*api.Config) 参数,则此参数会被忽略。 - opts: 可选参数,用于设置连接的其他选项。 返回值: - *api.Client: 连接到 Consul 的客户端实例。 - error: 如果初始化过程中发生错误,则返回相应的错误信息。 注意: - 如果设置了 WithConfig(*api.Config) 参数,则会忽略 addr 参数!

Types

type Option

type Option func(*options)

Option 设置 Consul 客户端选项的函数类型。

func WithConfig

func WithConfig(c *api.Config) Option

WithConfig 设置完整的 Consul 配置。

func WithDatacenter

func WithDatacenter(datacenter string) Option

WithDatacenter 设置数据中心名称。

func WithScheme

func WithScheme(scheme string) Option

WithScheme 设置协议方案(如 "http" 或 "https")。

func WithToken

func WithToken(token string) Option

WithToken 设置访问令牌。

func WithWaitTime

func WithWaitTime(waitTime time.Duration) Option

WithWaitTime 设置阻塞查询的最大等待时间。

Jump to

Keyboard shortcuts

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