config.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package gateway
  2. import (
  3. "time"
  4. "github.com/zeromicro/go-zero/rest"
  5. "github.com/zeromicro/go-zero/zrpc"
  6. )
  7. type (
  8. // GatewayConf is the configuration for gateway.
  9. GatewayConf struct {
  10. rest.RestConf
  11. Upstreams []Upstream
  12. Timeout time.Duration `json:",default=5s"`
  13. }
  14. // RouteMapping is a mapping between a gateway route and an upstream rpc method.
  15. RouteMapping struct {
  16. // Method is the HTTP method, like GET, POST, PUT, DELETE.
  17. Method string
  18. // Path is the HTTP path.
  19. Path string
  20. // RpcPath is the gRPC rpc method, with format of package.service/method
  21. RpcPath string
  22. }
  23. // Upstream is the configuration for an upstream.
  24. Upstream struct {
  25. // Name is the name of the upstream.
  26. Name string `json:",optional"`
  27. // Grpc is the target of the upstream.
  28. Grpc zrpc.RpcClientConf
  29. // ProtoSets is the file list of proto set, like [hello.pb].
  30. // if your proto file import another proto file, you need to write multi-file slice,
  31. // like [hello.pb, common.pb].
  32. ProtoSets []string `json:",optional"`
  33. // Mappings is the mapping between gateway routes and Upstream rpc methods.
  34. // Keep it blank if annotations are added in rpc methods.
  35. Mappings []RouteMapping `json:",optional"`
  36. }
  37. )