Service Registration and Discovery

Service Registration and Discovery Extensions provided by Hertz.

The service discovery extensions currently supported in the open source version of Hertz are stored in the registry. You are welcomed to join us in contributing and maintaining for this project.

As of now, the supported service discovery extensions are


Some optional configurations are provided to users when using service discovery.

WithSDUsed in conjunction with service discovery, this request uses service discovery when true is passed.
WithTagUsed in conjunction with service discovery to set Tag information.
WithCustomizedAddrsCustomize the address of the target instance.
WithLoadBalanceOptionsConfigure load balancing options.


The WithSD configuration item is provided, and when the parameter is passed as true, this request uses service discovery. The WithSD configuration item must be used when using service discovery requests. Signature:

func WithSD(b bool) RequestOption

Sample code:

status, body, err := cli.Get(context.Background(), nil, "http://hertz.test.demo/ping", config.WithSD(true))


Provides the WithTag configuration, which is used to set the Tag information. Signature:

func WithTag(k, v string) RequestOption

Sample code:

status, body, err := cli.Get(context.Background(), nil, "http://hertz.test.demo/ping", config.WithTag("foo", "var"))


This configuration item specifies the target instance address during service discovery. It will overwrite the result from Resolver. Resolver is a service discovery center for service discovery.


func WithCustomizedAddrs(addrs ...string) ServiceDiscoveryOption

Sample code:

cli.Use(sd.Discovery(r, sd.WithCustomizedAddrs("")))


This configuration item can configure the load balancing algorithm and load balancing parameters for the client.


func WithLoadBalanceOptions(lb loadbalance.Loadbalancer, options loadbalance.Options) ServiceDiscoveryOption

Sample code:

cli.Use(sd.Discovery(r, sd.WithLoadBalanceOptions(loadbalance.NewWeightedBalancer(), loadbalance.Options{
     RefreshInterval: 5 * time. Second,
     ExpireInterval: 15 * time. Second,

Custom load-balance extensions are detailed in Load Balancing Extensions.


Service Registration and Discovery nacos Extensions provided by Hertz.


Service Registration and Discovery consul Extensions provided by Hertz.


Service Registration and Discovery etcd Extensions provided by Hertz.


Service Registration and Discovery eureka Extensions provided by Hertz.


Service Registration and Discovery polaris Extensions provided by Hertz.


Service Registration and Discovery servicecomb Extensions provided by Hertz.


Service Registration and Discovery zookeeper Extensions provided by Hertz.


Service Registration and Discovery redis Extensions provided by Hertz.

Last modified June 24, 2024 : fix: correct the file path (#1096) (b3fa1a4)