gogrpcpg

package module
v0.0.0-...-4dc1adf Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: MIT Imports: 0 Imported by: 0

README

go-grpc-pg Circle CI GoDoc Go Report Card

A simple service demonstrating Go, gRPC, and PostgreSQL. Integration with CircleCI (version 1.0) included.

Building go-grpc-pg

Building go-httpd requires Go 1.8 or later. gvm is a great tool for installing and managing your versions of Go.

Download and build it like so:

mkdir go-grpc-pg # Or any directory of your choice
cd go-grpc-pg/
export GOPATH=$PWD
go get -t github.com/otoolep/go-grpc-pg/...
cd src/github.com/otoolep/go-grpc-pg
go install ./...

Some people consider using a distinct GOPATH environment variable for each project doing it wrong. In practise I, and many other Go programmers, find this actually most convenient.

Optional step to speed up testing

Unit testing actually uses SQLite, which is built as part of the test suite -- there is no need to install SQLite separately. However the compilation of SQLite is slow, and quickly becomes tedious if continually repeated. To avoid continual compilation every test run, execute the following command after performing the steps above:

go install github.com/mattn/go-sqlite3

Running go-grpc-pg

Once built as per above, launch the server as follows:

$GOPATH/bin/server

This assumes PostgreSQL is listening on localhost, port 5432. Run $GOPATH/bin/server -h to learn the full configuration the server expects of PostgreSQL, including the database, user, and password that must exist.

Generating queries

Assuming the server is up and running, execute the client as follows.

$GOPATH/bin/client

An example session is shown below.

>> CREATE TABLE bar (id INTEGER NOT NULL PRIMARY KEY, name TEXT)
Last Insert ID: -1, rows affected: 1
>> SELECT * FROM bar
>> INSERT INTO bar(id, name) VALUES(1, 'bob')
Last Insert ID: -1, rows affected: 1
>> INSERT INTO bar(id, name) VALUES(2, 'tom')
Last Insert ID: -1, rows affected: 1
>> SELECT * FROM bar
1       bob
2       tom
>>

Documentation

Overview

Package gogrpcpg is a simple example of a service that exposes a gRPC interface, and contacts a PostgreSQL backend.

Directories

Path Synopsis
cmd
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.
Package service represents a gRPC service that communicates with a database backend.
Package service represents a gRPC service that communicates with a database backend.

Jump to

Keyboard shortcuts

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