go-zero/gateway
2022-07-16 22:59:25 +08:00
..
config.go feat: export gateway.Server to let users add middlewares (#2157) 2022-07-16 22:59:25 +08:00
headerbuilder_test.go feat: restful -> grpc gateway (#2155) 2022-07-16 14:11:34 +08:00
headerbuilder.go feat: restful -> grpc gateway (#2155) 2022-07-16 14:11:34 +08:00
readme.md feat: restful -> grpc gateway (#2155) 2022-07-16 14:11:34 +08:00
requestparser_test.go feat: restful -> grpc gateway (#2155) 2022-07-16 14:11:34 +08:00
requestparser.go feat: export gateway.Server to let users add middlewares (#2157) 2022-07-16 22:59:25 +08:00
server.go feat: export gateway.Server to let users add middlewares (#2157) 2022-07-16 22:59:25 +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
        Rpc: hello.Hello/Ping
  - Grpc:
      Endpoints:
        - localhost:8081
    # reflection mode, no ProtoSet settings
    Mapping:
      - Method: post
        Path: /pingWorld
        Rpc: world.World/Ping

Generate ProtoSet files

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