config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Grpc is the target of the upstream.
  26. Grpc zrpc.RpcClientConf
  27. // ProtoSets is the file list of proto set, like [hello.pb].
  28. // if your proto file import another proto file, you need to write multi-file slice,
  29. // like [hello.pb, common.pb].
  30. ProtoSets []string `json:",optional"`
  31. // Mappings is the mapping between gateway routes and Upstream rpc methods.
  32. // Keep it blank if annotations are added in rpc methods.
  33. Mappings []RouteMapping `json:",optional"`
  34. }
  35. )