go-zero/gateway
Kevin Wan fcc246933c
fix: service group not working well when callback takes long time (#4531)
Signed-off-by: kevin <wanjunfeng@gmail.com>
2025-01-01 07:06:50 +00:00
..
internal Fixed #3771 (#3788) 2023-12-16 06:37:35 +00:00
config.go fix: gateway conf doesn't work (#2968) 2023-03-05 22:19:58 +08:00
readme.md Update readme.md 2022-08-07 16:08:16 +08:00
server_test.go fix: service group not working well when callback takes long time (#4531) 2025-01-01 07:06:50 +00:00
server.go fix: service group not working well when callback takes long time (#4531) 2025-01-01 07:06:50 +00: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
    ProtoSets:
      - hello.pb
    # Mappings can also be written in proto options
    Mappings:
      - Method: get
        Path: /pingHello/:ping
        RpcPath: hello.Hello/Ping
  - Grpc:
      Endpoints:
        - localhost:8081
    # reflection mode, no ProtoSet settings
    Mappings:
      - Method: post
        Path: /pingWorld
        RpcPath: world.World/Ping

Generate ProtoSet files

  • example command without external imports
protoc --descriptor_set_out=hello.pb hello.proto
  • example command with external imports
protoc --include_imports --proto_path=. --descriptor_set_out=hello.pb hello.proto