README.md

April 12, 2024 · View on GitHub

创建http+grpc服务

准备好greeter.proto文件

  1. 创建服务

sponge micro grpc-http-pb --module-name=helloworld --server-name=helloworld --project-name=helloworld --protobuf-file=./greeter.proto

  1. 打开代码文件 internal/service/greeter.go, 把去掉代码 panic("implement me"),添加代码:
return &helloworldV1.HelloReply{Message: req.Name}, nil
  1. 启动服务
# 生成代码
make proto

# 运行服务
make run
  1. 测试api


启动和停止服务

切换到目录 sponge/helloworld

# 后台启动http服务,日志输出到文件 helloworld.log
make run-nohup

# 停止服务
make run-http-nohup CMD=stop

注: 性能测试时必须在后台运行服务,如果直接在终端运行服务,大部分性能会损耗在打印日志到终端上,压测就没意义了。