github.com/hduhelp/go-zero@v1.4.3/gateway/readme.md (about) 1 # Gateway 2 3 ## Usage 4 5 - main.go 6 7 ```go 8 var configFile = flag.String("f", "config.yaml", "config file") 9 10 func main() { 11 flag.Parse() 12 13 var c gateway.GatewayConf 14 conf.MustLoad(*configFile, &c) 15 gw := gateway.MustNewServer(c) 16 defer gw.Stop() 17 gw.Start() 18 } 19 ``` 20 21 - config.yaml 22 23 ```yaml 24 Name: demo-gateway 25 Host: localhost 26 Port: 8888 27 Upstreams: 28 - Grpc: 29 Etcd: 30 Hosts: 31 - localhost:2379 32 Key: hello.rpc 33 # protoset mode 34 ProtoSets: 35 - hello.pb 36 # Mappings can also be written in proto options 37 Mappings: 38 - Method: get 39 Path: /pingHello/:ping 40 RpcPath: hello.Hello/Ping 41 - Grpc: 42 Endpoints: 43 - localhost:8081 44 # reflection mode, no ProtoSet settings 45 Mappings: 46 - Method: post 47 Path: /pingWorld 48 RpcPath: world.World/Ping 49 ``` 50 51 ## Generate ProtoSet files 52 53 - example command without external imports 54 55 ```shell 56 protoc --descriptor_set_out=hello.pb hello.proto 57 ``` 58 59 - example command with external imports 60 61 ```shell 62 protoc --include_imports --proto_path=. --descriptor_set_out=hello.pb hello.proto 63 ```