Service Configuration

Overview

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

Configuration

  1. type RpcClientConf struct {
  2. Etcd discov.EtcdConf `json:",optional,inherit"`
  3. Endpoints []string `json:",optional"`
  4. Target string `json:",optional"`
  5. App string `json:",optional"`
  6. Token string `json:",optional"`
  7. NonBlock bool `json:",optional"`
  8. Timeout int64 `json:",default=2000"`
  9. KeepaliveTime time.Duration `json:",default=20s"`
  10. Middlewares ClientMiddlewaresConf
  11. }
  12. type EtcdConf struct {
  13. Hosts []string
  14. Key string
  15. ID int64 `json:",optional"`
  16. User string `json:",optional"`
  17. Pass string `json:",optional"`
  18. CertFile string `json:",optional"`
  19. CertKeyFile string `json:",optional=CertFile"`
  20. CACertFile string `json:",optional=CertFile"`
  21. InsecureSkipVerify bool `json:",optional"`
  22. }
  23. type ServerMiddlewaresConf struct {
  24. Trace bool `json:",default=true"`
  25. Recover bool `json:",default=true"`
  26. Stat bool `json:",default=true"`
  27. Prometheus bool `json:",default=true"`
  28. Breaker bool `json:",default=true"`
  29. }

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