Skip to content

Commit

Permalink
Use grpc-gateway to create restful services.
Browse files Browse the repository at this point in the history
* Add grpc-gateway annotations to the services and include them
  in the buf file

* We will use grpc-gateway to create restful services accessible
  form the vscode extension so that we don't have to rely on grpc-web
  • Loading branch information
jlewi committed Apr 4, 2024
1 parent 3d6ad65 commit d3c47f9
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 27 deletions.
21 changes: 21 additions & 0 deletions protos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Protocol buffers

We use protocol buffers as a way of defining APIs and data resources.

## Developer Guide

Language bindings are generated using [buf](https://buf.build/docs/introduction)

```
buf generate
```

In the past we've run into issues generating grpc bindings for python;
see [bufbuild/buf#1344](https://github.com/bufbuild/buf/issues/1344). As of right
now we aren't using grpc in python so hopefully we don't need to worry about this and
if we do hopefully the issue has been resolved by now.


## GRPC-Gateway

We [grpc-gateway](https://grpc-ecosystem.github.io/grpc-gateway/) to generate RESTful services from our grpc services.
4 changes: 4 additions & 0 deletions protos/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ plugins:
# then its pased on the path relative to the location of the buf.yaml file.
- paths=source_relative
- name: go-grpc
out: go/
opt:
- paths=source_relative
- plugin: grpc-gateway
out: go/
opt:
- paths=source_relative
8 changes: 8 additions & 0 deletions protos/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 7a6bc1e3207144b38e9066861e1de0ff
digest: shake256:d646836485c34192401253703c4e7ce899c826fceec060bf4b2a62c4749bd9976dc960833e134a1f814725e1ffd60b1bb3cf0335a7e99ef0e8cec34b070ffb66
2 changes: 2 additions & 0 deletions protos/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ breaking:
lint:
use:
- DEFAULT
deps:
- buf.build/googleapis/googleapis
16 changes: 14 additions & 2 deletions protos/foyle/v1alpha1/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import "foyle/v1alpha1/doc.proto";

option go_package = "github.com/jlewi/foyle/protos/go/v1alpha1";

// grpc-gateway
// https://github.com/grpc-ecosystem/grpc-gateway
import "google/api/annotations.proto";

message GenerateRequest {
Doc doc = 1;
}
Expand All @@ -16,7 +20,11 @@ message GenerateResponse {
// Generate completions using AI
service GenerateService {
// Generate generates new cells given an existing document.
rpc Generate (GenerateRequest) returns (GenerateResponse) {}
rpc Generate (GenerateRequest) returns (GenerateResponse) {
option (google.api.http) = {
post: "/v1alpha1/generate"
};
}
}

message ExecuteRequest {
Expand All @@ -30,5 +38,9 @@ message ExecuteResponse {
// Execute code and commands
service ExecuteService {
// Execute executes a cell in an existing document.
rpc Execute(ExecuteRequest) returns (ExecuteResponse) {}
rpc Execute(ExecuteRequest) returns (ExecuteResponse) {
option (google.api.http) = {
post: "/v1alpha1/execute"
};
}
}
56 changes: 31 additions & 25 deletions protos/go/foyle/v1alpha1/agent.pb.go

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

Loading

0 comments on commit d3c47f9

Please sign in to comment.