ducky/subscriptions

Paddy 2015-07-18 Parent:f1a22fc2321d

9:8eb19bcbf17d Go to Latest

ducky/subscriptions/postgres.go

Return errors from responses in client. When the client makes a request, non-200 responses _are not_ considered errors. So we need to check the response.Errors property, and if it has errors, _then_ we consider the request to have an error. To make this happen, we created an httpErrors type that fulfills the error interface and just wraps the response Errors property. Then callers can type-cast it and interrogate it.

History
1 package subscriptions
3 import (
4 "database/sql"
5 )
7 // NewPostgres returns a usable Postgres instance, if and only
8 // if error is nil. If error is not nil, the returned Postgres
9 // instance should not be used.
10 func NewPostgres(conn string) (Postgres, error) {
11 db, err := sql.Open("postgres", conn)
12 if err != nil {
13 return Postgres{}, err
14 }
15 return Postgres{db}, nil
16 }
18 // Postgres represents a thin wrapper around *sql.DB, so we can
19 // inherit its methods but also define our own (so we can fulfill
20 // our subscriptionStore interface on Postgres). Note that the
21 // value of a Postgres variable contains a _pointer_ to an sql.DB
22 // pool of connections, so it's not necessary to use the address of
23 // the Postgres variable itself (though there shouldn't be any harm
24 // in doing so).
25 type Postgres struct {
26 *sql.DB
27 }