pgpin

command module
v0.0.0-...-d7157a5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2014 License: MIT Imports: 20 Imported by: 0

README

pgpin

pgpin is an open-source example app showing how to build a database-backed service in Go.

The example is a clone of Heroku Dataclips, basically a "pastebin for SQL queries".

In working through this example app we hope to learn:

  • How to build database-backed services in idiomatic Go, with an eye towards robustness and operability.

  • How developing such services in Go compares to other stacks, such as Ruby/Sinatra/Sequel.

Work on pgpin is ongoing. The current version of the app has some but not all of the user-facing features and robustness properties we eventually want. See FEATURES.md and TODO.md.

Developing

A Vagrant development environment is provided. Install a recent version of Vagrant and Virtualbox and run:

$ vagrant up
$ vagrant ssh

To start a development version of app:

$ cat migrations/* | psql $DATABASE_URL
$ godep go install
$ goreman start

An environment variable is provided to make testing with curl easy:

$ curl -i $PGPIN_URL/status

To apply code changes:

$ godep go install
$ goreman start

We suggest a git pre-commit hook to verify adherence to Go coding standards:

$ cat > .git/hooks/pre-commit <<EOF
#!/bin/bash

gofmt -d *.go 2>&1 | tee /tmp/pgpin-pre-commit
if [ \$(wc -l < /tmp/pgpin-pre-commit) -gt "0" ]; then
  exit 1
fi
go vet github.com/mmcgrana/pgpin || exit 1
errcheck -ignore 'fmt:a^' github.com/mmcgrana/pgpin || exit 1
EOF
$ chmod +x .git/hooks/pre-commit
$ go get github.com/kisielk/errcheck

Testing

To run tests:

$ cat migrations/* | psql $TEST_DATABASE_URL
$ godep go test

By default logs are silenced during tests. Turn them on with:

$ TEST_LOGS=true godep go test

Scripting

To write and run one-off scripts that use the pgpin app code:

$ cat > script/count_pins.go <<EOF
package main

import (
	"log"
	pgpin "../../pgpin"
)

func main() {
    pgpin.PgStart()
    count, _ := pgpin.PgCount("SELECT count(*) from pins")
    log.Printf("pins.count total=%d", count)
}
EOF

$ godep go run script/count_pins.go

Deployment

To an instance of pgpin to Heroku:

$ export DEPLOY=... (e.g. "production", or your username)
$ bin/deploy-setup
$ curl -i https://pgpin-$DEPLOY.herokuapp.com/status

To tear it down:

$ bin/deploy-teardown

License

See LICENSE.md.

References

Some other projects we've looked to in writing the pgpin example app:

We are interested in collecting other examples of non-trivial, open-source, database-backed (Postgres or otherwise) services written in Go. Please send suggestions to the author.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/code.google.com/p/go-uuid/uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.
_workspace/src/github.com/fernet/fernet-go
Package fernet takes a user-provided message (an arbitrary sequence of bytes), a key (256 bits), and the current time, and produces a token, which contains the message in a form that can't be read or altered without the key.
Package fernet takes a user-provided message (an arbitrary sequence of bytes), a key (256 bits), and the current time, and produces a token, which contains the message in a form that can't be read or altered without the key.
_workspace/src/github.com/garyburd/redigo/redis
Package redis is a client for the Redis database.
Package redis is a client for the Redis database.
_workspace/src/github.com/lib/pq
Package pq is a pure Go Postgres driver for the database/sql package.
Package pq is a pure Go Postgres driver for the database/sql package.
_workspace/src/github.com/lib/pq/listen_example
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
_workspace/src/github.com/lib/pq/oid
Package oid contains OID constants as defined by the Postgres server.
Package oid contains OID constants as defined by the Postgres server.
_workspace/src/github.com/zenazn/goji/web
Package web is a microframework inspired by Sinatra.
Package web is a microframework inspired by Sinatra.
_workspace/src/github.com/zenazn/goji/web/middleware
Package middleware provides several standard middleware implementations.
Package middleware provides several standard middleware implementations.

Jump to

Keyboard shortcuts

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