Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support client and validate #2

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

proto: ## protoc
protoc -I/usr/local/include -I$(GOPATH)/src/github.com/googleapis/googleapis\
--proto_path=$(GOPATH)/src:. --go_out=. --go-http_out=. --go-grpc_out=.\
--proto_path=$(GOPATH)/src:. --go_out=. --go-http_out=validate=true:. --go-grpc_out=.\
--validate_out=lang=go,paths=source_relative:.\
example/greeter/v1/hello.proto
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ click [here](https://yusank.github.io/posts/go-protoc-http/) to learn how to dev

## TODO

- [ ] support [validate](https://github.com/envoyproxy/protoc-gen-validate)
- [ ] gen client code.
- [x] support [validate](https://github.com/envoyproxy/protoc-gen-validate)
- [x] gen client code.
20 changes: 20 additions & 0 deletions example/greeter/greeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package greeter

import (
"context"
"net/http"
"time"

"github.com/gin-gonic/gin"
"google.golang.org/grpc"

v1 "github.com/yusank/protoc-gen-go-http/example/greeter/v1"
phttp "github.com/yusank/protoc-gen-go-http/http"
)

// Greeter implement v1.HelloServer and v1.HelloHTTPHandler at same time
Expand All @@ -27,3 +30,20 @@ func register() {
v1.RegisterHelloServer(&grpc.Server{}, &Greeter{})
v1.RegisterHelloHTTPHandler(gin.Default().Group("/"), &Greeter{})
}

func callAsClient() {
cli, err := v1.NewHelloHTTPClient(nil, phttp.Retry(3, time.Millisecond*100))
if err != nil {
return
}

h := http.Header{}
h.Set("custom-key", "protoc")
rsp, err := cli.Add(context.Background(), &v1.AddRequest{}, phttp.Header(h))
if err != nil {
return
}

// handle response
_ = rsp.String()
}
4 changes: 2 additions & 2 deletions example/greeter/v1/hello.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 105 additions & 26 deletions example/greeter/v1/hello.pb.http.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading