https://github.com/goapt/grpc-http
generate grpc google api to golang http handler
https://github.com/goapt/grpc-http
Last synced: 2 months ago
JSON representation
generate grpc google api to golang http handler
- Host: GitHub
- URL: https://github.com/goapt/grpc-http
- Owner: goapt
- License: mit
- Created: 2025-12-31T10:11:55.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-01-04T01:20:11.000Z (5 months ago)
- Last Synced: 2026-01-04T17:50:16.685Z (5 months ago)
- Language: Go
- Size: 26.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# protoc-gen-go-http
从 protobuf 文件中生成使用 golang http handler
## 安装
```shell
go install github.com/goapt/grpc-http/cmd/protoc-gen-go-http@latest
```
## 生成
```shell
protoc --proto_path=. \
--proto_path=./third_party \
--go-http_out=paths=source_relative:. \
./example.proto
```
## 合约
你需要实现合约`[contract](contract)`中的接口
Codec: 用户解析请求和返回数据
ServeMux: 可以使用http.ServeMux
```go
mux := http.NewServeMux()
apiv1.RegisterUserServiceHTTPServer(mux,codec,userService)
server := &http.Server{
Addr: ":8080",
Handler: mux,
}
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fmt.Printf("Server startup failed: %v\n", err)
}
```