Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/otoolep/go-grpc-pg
Simple service exposing a gRPC interface, with a connection to PostgreSQL on the backend
https://github.com/otoolep/go-grpc-pg
go golang grpc postgres
Last synced: 3 months ago
JSON representation
Simple service exposing a gRPC interface, with a connection to PostgreSQL on the backend
- Host: GitHub
- URL: https://github.com/otoolep/go-grpc-pg
- Owner: otoolep
- License: mit
- Created: 2017-06-28T05:34:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-12T01:34:41.000Z (over 6 years ago)
- Last Synced: 2024-10-13T21:59:47.405Z (3 months ago)
- Topics: go, golang, grpc, postgres
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 33
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-grpc-pg [![Circle CI](https://circleci.com/gh/otoolep/go-grpc-pg/tree/master.svg?style=svg)](https://circleci.com/gh/otoolep/go-grpc-pg/tree/master) [![GoDoc](https://godoc.org/github.com/otoolep/go-grpc-pg?status.svg)](https://godoc.org/github.com/otoolep/go-grpc-pg) [![Go Report Card](https://goreportcard.com/badge/github.com/otoolep/go-grpc-pg)](https://goreportcard.com/report/github.com/otoolep/go-grpc-pg)
======A simple service demonstrating Go, gRPC, and PostgreSQL. Integration with [CircleCI (version 1.0)](http://www.circleci.com) included.
## Building go-grpc-pg
*Building go-httpd requires Go 1.8 or later. [gvm](https://github.com/moovweb/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
>>
```