Skip to main content

Service Configuration

Overview

This paper describes how to use the go-Zero framework for gRPC client development.

Configuration

type RpcClientConf struct {
Etcd discov.EtcdConf `json:",optional,inherit"`
Endpoints []string `json:",optional"`
Target string `json:",optional"`
App string `json:",optional"`
Token string `json:",optional"`
NonBlock bool `json:",optional"`
Timeout int64 `json:",default=2000"`
KeepaliveTime time.Duration `json:",default=20s"`
Middlewares ClientMiddlewaresConf
}

type EtcdConf struct {
Hosts []string
Key string
ID int64 `json:",optional"`
User string `json:",optional"`
Pass string `json:",optional"`
CertFile string `json:",optional"`
CertKeyFile string `json:",optional=CertFile"`
CACertFile string `json:",optional=CertFile"`
InsecureSkipVerify bool `json:",optional"`
}

type ServerMiddlewaresConf struct {
Trace bool `json:",default=true"`
Recover bool `json:",default=true"`
Stat bool `json:",default=true"`
Prometheus bool `json:",default=true"`
Breaker bool `json:",default=true"`
}

RpcClientConf

NameDataTypeMeaningDefault valueRequired?
EtcdEtcdConfService finds configuration, when using etcd for service discoveryNoneNO
EndpointsString Type ArrayRPC Server address list, used for direct link, configured when required for a rpc server clusterNoneNO
TargetstringDomain URL solved, please refer to https://github.com/grpc/grpc/blob/master/doc/naming.mdNoneNO
Appstringrpc authenticated app name, only configured when rpserver opens authenticationNoneNO
Tokenstringrpc authenticated token, only configured when rpserver opens authenticationNoneNO
NonBlockboolWhether to block mode, when true does not block rpc linksfalseNO
Timeoutint64Timeout time2000msNO
KeepaliveTimeTime.DurationKeepalive Time20sNO
MiddlewaresClientMiddlewaresConfEnable MiddlewareNoneNO

EtcdConf

EtcdConf config service discovery when using etcd for service discovery.

NameDataTypeMeaningDefault valueRequired?
HostsString Type Arrayetcd cluster addressNoneYES
KeystringService discovery keyNoneYES
IDint64etcd tenant idNoneNO
Userstringetcd usernameNoneNO
Passstringetcd passwordNoneNO
CertFilestringetcd certificate fileCertFileNO
CertKeyFilestringetcd certificate private key fileNoneNO
CACertFilestringetcd certificate fileCertFileNO
InsecureSkipVerifyboolWhether or not to skip certificate verificationNoneNO

ServerMiddlewaresConf

ServerMidlewaresConf is configured as an intermediary, when control is required.

NameDataTypeMeaningDefault valueRequired?
TraceboolEnable link trackingtrueNO
RecoverboolWhether to enable an exception recoverytrueNO
StatboolEnable statstrueNO
PrometheusboolWhether prometheus are enabledtrueNO
BreakerboolWhether to turn on smeltingtrueNO