2022-07-16 14:11:34 +08:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// GatewayConf is the configuration for gateway.
|
|
|
|
GatewayConf struct {
|
|
|
|
rest.RestConf
|
2022-07-19 09:58:46 +08:00
|
|
|
Upstreams []Upstream
|
2022-07-16 14:11:34 +08:00
|
|
|
}
|
|
|
|
|
2025-01-27 20:00:58 +08:00
|
|
|
// HttpClientConf is the configuration for an HTTP client.
|
|
|
|
HttpClientConf struct {
|
|
|
|
Target string
|
|
|
|
Prefix string `json:",optional"`
|
|
|
|
Timeout int64 `json:",default=3000"`
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:58:46 +08:00
|
|
|
// RouteMapping is a mapping between a gateway route and an upstream rpc method.
|
|
|
|
RouteMapping struct {
|
2022-07-16 14:11:34 +08:00
|
|
|
// Method is the HTTP method, like GET, POST, PUT, DELETE.
|
|
|
|
Method string
|
|
|
|
// Path is the HTTP path.
|
|
|
|
Path string
|
2025-01-27 20:00:58 +08:00
|
|
|
// RpcPath is the gRPC rpc method, with format of package.service/method, optional.
|
|
|
|
// If the mapping is for HTTP, it's not necessary.
|
|
|
|
RpcPath string `json:",optional"`
|
2022-07-16 14:11:34 +08:00
|
|
|
}
|
2022-07-16 22:59:25 +08:00
|
|
|
|
2022-07-19 09:58:46 +08:00
|
|
|
// Upstream is the configuration for an upstream.
|
|
|
|
Upstream struct {
|
2022-08-07 16:09:54 +08:00
|
|
|
// Name is the name of the upstream.
|
|
|
|
Name string `json:",optional"`
|
2022-07-19 09:58:46 +08:00
|
|
|
// Grpc is the target of the upstream.
|
2025-01-27 20:00:58 +08:00
|
|
|
Grpc *zrpc.RpcClientConf `json:",optional"`
|
|
|
|
// Http is the target of the upstream.
|
|
|
|
Http *HttpClientConf `json:",optional=!grpc"`
|
2022-08-06 16:32:12 +08:00
|
|
|
// ProtoSets is the file list of proto set, like [hello.pb].
|
|
|
|
// if your proto file import another proto file, you need to write multi-file slice,
|
|
|
|
// like [hello.pb, common.pb].
|
2022-07-27 09:10:23 +08:00
|
|
|
ProtoSets []string `json:",optional"`
|
2025-01-27 20:00:58 +08:00
|
|
|
// Mappings is the mapping between gateway routes and Upstream methods.
|
2022-07-17 14:57:25 +08:00
|
|
|
// Keep it blank if annotations are added in rpc methods.
|
2022-08-06 16:32:12 +08:00
|
|
|
Mappings []RouteMapping `json:",optional"`
|
2022-07-16 14:11:34 +08:00
|
|
|
}
|
|
|
|
)
|