Skip to content

Commit

Permalink
feat: support gen http server code
Browse files Browse the repository at this point in the history
  • Loading branch information
yusank committed Aug 19, 2021
1 parent 7aca408 commit 02a4a0c
Show file tree
Hide file tree
Showing 14 changed files with 1,352 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +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=.\
example/greeter/v1/hello.proto
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# protoc-gen-go-http
generate go http server code via proto buffer

## how to use

```shell
$ make proto
# or
$ protoc -I/usr/local/include -I$(GOPATH)/src/github.com/googleapis/googleapis\
--proto_path=$(GOPATH)/src:. --go_out=. --go-http_out=. --go-grpc_out=.\
path/to/file.proto
```

## TODO

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

import (
"context"

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

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

// Greeter implement v1.HelloServer and v1.HelloHTTPHandler at same time
type Greeter struct {
v1.UnimplementedHelloServer
}

func (g *Greeter) Add(ctx context.Context, in *v1.AddRequest) (*v1.AddResponse, error) {
panic("implement me")
}

func (g *Greeter) Get(ctx context.Context, in *v1.GetRequest) (*v1.GetResponse, error) {
panic("implement me")
}

func register() {
// can call method by rpc or http
v1.RegisterHelloServer(&grpc.Server{}, &Greeter{})
v1.RegisterHelloHTTPHandler(gin.Default().Group("/"), &Greeter{})
}
Loading

0 comments on commit 02a4a0c

Please sign in to comment.