go-zero/gateway
2022-07-27 09:10:23 +08:00
..
internal feat: support customized header to metadata processor (#2162) 2022-07-17 23:21:19 +08:00
config.go support mulitple protoset files (#2190) 2022-07-27 09:10:23 +08:00
readme.md feat: verify RpcPath on startup (#2159) 2022-07-17 12:37:23 +08:00
server.go support mulitple protoset files (#2190) 2022-07-27 09:10:23 +08:00

Gateway

Usage

  • main.go
var configFile = flag.String("f", "config.yaml", "config file")

func main() {
	flag.Parse()

	var c gateway.GatewayConf
	conf.MustLoad(*configFile, &c)
	gw := gateway.MustNewServer(c)
	defer gw.Stop()
	gw.Start()
}
  • config.yaml
Name: demo-gateway
Host: localhost
Port: 8888
Upstreams:
  - Grpc:
      Etcd:
        Hosts:
        - localhost:2379
        Key: hello.rpc
    # protoset mode
    ProtoSet: hello.pb
    Mapping:
      - Method: get
        Path: /pingHello/:ping
        RpcPath: hello.Hello/Ping
  - Grpc:
      Endpoints:
        - localhost:8081
    # reflection mode, no ProtoSet settings
    Mapping:
      - Method: post
        Path: /pingWorld
        RpcPath: world.World/Ping

Generate ProtoSet files

  • example command
protoc --descriptor_set_out=hello.pb hello.proto