crdb-grpc

command module
v0.0.0-...-2241f1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 8 Imported by: 0

README

crdb-grpc

A barebones example of accessing CockroachDB via gRPC

Dependencies
Running locally

Start a cluster

$ cockroach start-single-node \
    --listen-addr=localhost:26257 \
    --http-addr=localhost:8080 \
    --insecure

Create a table

$ cockroach sql --insecure < create.sql

Generate the proto service

$ protoc --proto_path=protos protos/*.proto --go_out=. --go-grpc_out=.

Run the server

$ go run main.go

Make a request to the gRPC reflection endpoint

$ grpcurl -plaintext localhost:8080 list TodoService
Requests

Create a todo

$ grpcurl \
	-plaintext \
	-d '{"title": "todo d"}' \
		localhost:8080 TodoService.CreateTodo

Fetch all todos

$ grpcurl \
    -plaintext \
    localhost:8080 TodoService.GetTodos

Fetch one todo

$ grpcurl \
	-plaintext \
	-d '{"id": "15c494cd-1c87-45ae-b725-cbf436eda43c"}' \
		localhost:8080 TodoService.GetTodo

Delete a todo

$ grpcurl \
	-plaintext \
	-d '{"id": "15c494cd-1c87-45ae-b725-cbf436eda43c"}' \
		localhost:8080 TodoService.DeleteTodo

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL