Skip to content

Commit

Permalink
Merge pull request #2 from yusank/feature/support-http-client-code
Browse files Browse the repository at this point in the history
feat: support client and validate
  • Loading branch information
yusank authored Dec 20, 2022
2 parents 207c44b + 82b0d1a commit 9e6d90a
Show file tree
Hide file tree
Showing 13 changed files with 738 additions and 71 deletions.
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

0 comments on commit 9e6d90a

Please sign in to comment.