Skip to content

Import googleapis (LatLng) from Buf Schema Registry #36

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.idea
.idea

idl/google
idl/grafeas
idl/validate
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ all:

.PHONY: gen-proto
gen-proto:
rm -rf internal/idl
buf breaking idl --against '.git#branch=main,subdir=idl'
buf mod update idl
buf lint idl
buf format idl -w
buf mod update idl
buf generate idl

.PHONY: gen-models
Expand Down
5 changes: 3 additions & 2 deletions cmd/dispatch/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1"
"github.com/kevinmichaelchen/api-dispatch/internal/service/money"
"github.com/spf13/cobra"
"google.golang.org/genproto/googleapis/type/latlng"
"google.golang.org/protobuf/types/known/timestamppb"
"io/ioutil"
"log"
Expand Down Expand Up @@ -63,7 +64,7 @@ func ingestDrivers(cmd *cobra.Command, args []string) {
locations = append(locations, &v1beta1.DriverLocation{
DriverId: e.DriverID,
MostRecentHeartbeat: timestamppb.Now(),
CurrentLocation: &v1beta1.LatLng{
CurrentLocation: &latlng.LatLng{
Latitude: e.LatLng.Latitude,
Longitude: e.LatLng.Longitude,
},
Expand Down Expand Up @@ -123,7 +124,7 @@ func ingestTrips(cmd *cobra.Command, args []string) {
trips = append(trips, &v1beta1.Trip{
Id: e.Id,
ScheduledFor: timestamppb.New(e.ScheduledFor),
PickupLocation: &v1beta1.LatLng{
PickupLocation: &latlng.LatLng{
Latitude: e.LatLng.Latitude,
Longitude: e.LatLng.Longitude,
},
Expand Down
5 changes: 3 additions & 2 deletions cmd/dispatch/nearest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1"
"github.com/spf13/cobra"
"google.golang.org/genproto/googleapis/type/latlng"
"log"
)

func getNearestDrivers(cmd *cobra.Command, args []string) {
// Create request
req := &v1beta1.GetNearestDriversRequest{
PickupLocation: &v1beta1.LatLng{
PickupLocation: &latlng.LatLng{
Latitude: latitude,
Longitude: longitude,
},
Expand All @@ -36,7 +37,7 @@ func getNearestTrips(cmd *cobra.Command, args []string) {
// Create request
req := &v1beta1.GetNearestTripsRequest{
Driver: &v1beta1.GetNearestTripsRequest_DriverLocation{
DriverLocation: &v1beta1.LatLng{
DriverLocation: &latlng.LatLng{
Latitude: latitude,
Longitude: longitude,
},
Expand Down
13 changes: 3 additions & 10 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,8 @@ dispatch=# select driver_id from driver_location ;
## JetBrains Protobuf Import Paths
In `Languages & Frameworks > Protocol Buffers`, import the `./idl` directory.

Install envoyproxy/protoc-gen-validate into your `GOPATH`.
Then install dependencies in `./idl/buf.yaml`:
```
$ go env -json GOPATH GOROOT
{
"GOPATH": "/Users/kevinchen/go",
"GOROOT": "/opt/homebrew/Cellar/go/1.18.2/libexec"
}

$ go install github.com/envoyproxy/protoc-gen-validate@latest
buf export buf.build/googleapis/googleapis -o idl
buf export buf.build/envoyproxy/protoc-gen-validate -o idl
```

Add an import path for `${GOPATH}/pkg/mod/github.com/envoyproxy/[email protected]`.
10 changes: 10 additions & 0 deletions idl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Our protobufs use dependencies from the
[Buf Schema Registry](https://buf.build/explore).

You'll need to download these locally for your IDE to be happy.

From the root-level of this repo, run:
```
buf export buf.build/googleapis/googleapis -o idl
buf export buf.build/envoyproxy/protoc-gen-validate -o idl
```
4 changes: 4 additions & 0 deletions idl/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ deps:
owner: envoyproxy
repository: protoc-gen-validate
commit: dc09a417d27241f7b069feae2cd74a0e
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 2c4adef7af3d4b74b8a224260cf10cb9
1 change: 1 addition & 0 deletions idl/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: v1
deps:
- buf.build/envoyproxy/protoc-gen-validate:0e25aabb25c0709aff19aea176a1da13328b12fb
- buf.build/googleapis/googleapis:2c4adef7af3d4b74b8a224260cf10cb9
breaking:
use:
- FILE
Expand Down
8 changes: 4 additions & 4 deletions idl/coop/drivers/dispatch/v1beta1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ syntax = "proto3";
package coop.drivers.dispatch.v1beta1;

import "coop/drivers/dispatch/v1beta1/driver.proto";
import "coop/drivers/dispatch/v1beta1/latlng.proto";
import "coop/drivers/dispatch/v1beta1/trip.proto";
import "google/protobuf/duration.proto";
import "google/type/latlng.proto";
import "validate/validate.proto";

option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";
Expand Down Expand Up @@ -47,7 +47,7 @@ message CreateTripsResponse {}

message GetNearestDriversRequest {
// trip pickup location
LatLng pickup_location = 1;
google.type.LatLng pickup_location = 1 [(validate.rules).message.required = true];
int32 limit = 2 [(validate.rules).int32 = {
gt: 0,
lte: 1000
Expand All @@ -64,7 +64,7 @@ message GetNearestTripsRequest {
option (validate.required) = true;

string driver_id = 1;
LatLng driver_location = 2;
google.type.LatLng driver_location = 2;
}
int32 limit = 3 [(validate.rules).int32 = {
gt: 0,
Expand All @@ -86,7 +86,7 @@ message SearchResult {
// Time it takes driver to go to pickup
google.protobuf.Duration duration = 4;
// The match's location.
LatLng location = 5;
google.type.LatLng location = 5;
// Human-readable location
string address = 6;
// The highest (finest) H3 resolution in which the match was found.
Expand Down
4 changes: 2 additions & 2 deletions idl/coop/drivers/dispatch/v1beta1/driver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ syntax = "proto3";

package coop.drivers.dispatch.v1beta1;

import "coop/drivers/dispatch/v1beta1/latlng.proto";
import "google/protobuf/timestamp.proto";
import "google/type/latlng.proto";
import "validate/validate.proto";

option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";
Expand All @@ -12,5 +12,5 @@ message DriverLocation {
string id = 1;
string driver_id = 2 [(validate.rules).string.min_len = 1];
google.protobuf.Timestamp most_recent_heartbeat = 3 [(validate.rules).timestamp.required = true];
LatLng current_location = 4 [(validate.rules).message.required = true];
google.type.LatLng current_location = 4 [(validate.rules).message.required = true];
}
26 changes: 0 additions & 26 deletions idl/coop/drivers/dispatch/v1beta1/latlng.proto

This file was deleted.

4 changes: 2 additions & 2 deletions idl/coop/drivers/dispatch/v1beta1/trip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ syntax = "proto3";

package coop.drivers.dispatch.v1beta1;

import "coop/drivers/dispatch/v1beta1/latlng.proto";
import "google/protobuf/timestamp.proto";
import "google/type/latlng.proto";
import "validate/validate.proto";

option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";

message Trip {
string id = 1 [(validate.rules).string.min_len = 1];
// where
LatLng pickup_location = 2 [(validate.rules).message.required = true];
google.type.LatLng pickup_location = 2 [(validate.rules).message.required = true];
// when
google.protobuf.Timestamp scheduled_for = 3 [(validate.rules).timestamp.required = true];
// how much $$$
Expand Down
Loading