Typical development workflow consist in the following steps:
- Define your API contract with protocol buffers
- Define your data model in a new file in
pkg/db/migrations
and write plain SQL to generate requests in/pkg/db/queries
- Generate Go code for your proto & SQL binding with
make gen
- Write your server implementation in server Go package (including pgtype adaptations)
# For MacOS
brew install golang-migrate sqlc bufbuild/buf/buf grpcurl
go install golang.org/x/tools/cmd/gonew@latest
gonew github.com/thylong/gonew-templates/06-grpc-sqlc github.com/example/myapp
This document provides example grpcurl
queries to interact with the EventService
defined in the provided Protobuf schema. These examples assume your gRPC server is running locally on port 50051
.
Use grpcurl
to list all services available on the server:
grpcurl -plaintext localhost:50051 list
Expected Output:
events.EventService
To describe the EventService
, including its RPC methods:
grpcurl -plaintext localhost:50051 describe events.EventService
Expected Output:
events.EventService is a service:
rpc DeleteEvent ( .events.DeleteEventRequest ) returns ( .events.DeleteEventResponse );
rpc GetEvent ( .events.GetEventRequest ) returns ( .events.GetEventResponse );
rpc GetEvents ( .events.GetEventsRequest ) returns ( .events.GetEventsResponse );
rpc PutEvent ( .events.PutEventRequest ) returns ( .events.PutEventResponse );
Request a list of events with pagination and search filters:
grpcurl -plaintext -d '{
"page": 1,
"page_size": 10,
"search": "example"
}' localhost:50051 events.EventService/GetEvents
Expected Output:
{
"events": [
{
"event_privacy": "EVENT_PRIVACY_INTERNAL",
"event_id": "123",
"name": "Company All-Hands",
"description": "A company All-Hands",
"type": "Meeting",
"department": "HR",
"regions": ["US"],
"tags": ["monthly"],
"start_at": {
"year": 2025,
"month": 1,
"day": 15,
"hours": 10,
"minutes": 30,
"seconds": 0
}
}
],
"total_count": 1,
"page": 1,
"page_size": 10
}
Request details for a specific event by event_id
:
grpcurl -plaintext -d '{
"event_id": "123"
}' localhost:50051 events.EventService/GetEvent
Expected Output:
{
"event": {
"event_privacy": "EVENT_PRIVACY_INTERNAL",
"event_id": "123",
"name": "Company All-Hands",
"description": "A company All-Hands",
"type": "Meeting",
"department": "HR",
"regions": ["US"],
"tags": ["monthly"],
"start_at": {
"year": 2025,
"month": 1,
"day": 15,
"hours": 10,
"minutes": 30,
"seconds": 0
}
}
}
Create or update an event:
grpcurl -plaintext -d '{
"event_privacy": "EVENT_PRIVACY_INTERNAL",
"event_id": "123",
"name": "Team Meeting",
"description": "A Team meeting",
"type": "Meeting",
"department": "Engineering",
"regions": ["EU"],
"tags": ["sprint-planning"],
"start_at": {
"year": 2025,
"month": 1,
"day": 18,
"hours": 14,
"minutes": 0,
"seconds": 0
}
}' localhost:50051 events.EventService/PutEvent
Expected Output:
{
"event": {
"event_privacy": "EVENT_PRIVACY_INTERNAL",
"event_id": "123",
"name": "Team Meeting",
"description": "A Team meeting",
"type": "Meeting",
"department": "Engineering",
"regions": ["EU"],
"tags": ["sprint-planning"],
"start_at": {
"year": 2025,
"month": 1,
"day": 18,
"hours": 14,
"minutes": 0,
"seconds": 0
}
}
}
Delete an event by event_id
:
grpcurl -plaintext -d '{
"eventID": "123"
}' localhost:50051 events.EventService/DeleteEvent
Expected Output:
{}
grpcurl -plaintext localhost:50051 grpc.health.v1.Health/Check