postgresql

package
v0.0.0-...-b8aeaa3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version              = "0.0.1"
	DefaultAPIPath       = "/client/v11/databases"
	DefaultAPIURL        = "https://postgres-api.heroku.com" + DefaultAPIPath
	DefaultStarterAPIURL = "https://postgres-starter-api.heroku.com" + DefaultAPIPath
	DefaultUserAgent     = "heroku-postgres-go/" + Version + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// HTTP is the Client's internal http.Client, handling HTTP requests to the
	// Heroku Postgres API.
	HTTP *http.Client

	// The URL of the Heroku Postgres API to communicate with. Defaults to
	// DefaultAPIURL.
	URL string

	// The URL of the Heroku Postgres Starter API to communicate with. Defaults
	// to DefaultStarterAPIURL.
	StarterURL string

	// Username is the HTTP basic auth username for API calls made by this Client.
	Username string

	// Password is the HTTP basic auth password for API calls made by this Client.
	Password string

	// UserAgent to be provided in API requests. Set to DefaultUserAgent if not
	// specified.
	UserAgent string

	// Debug mode can be used to dump the full request and response to stdout.
	Debug bool

	// AdditionalHeaders are extra headers to add to each HTTP request sent by
	// this Client.
	AdditionalHeaders http.Header

	// Path to the Unix domain socket or a running heroku-agent.
	HerokuAgentSocket string
}

A Client is a Heroku Postgres API client. Its zero value is a usable client that uses default settings for the Heroku Postgres API. The Client has an internal HTTP client (HTTP) which defaults to http.DefaultClient.

As with all http.Clients, this Client's Transport has internal state (cached HTTP connections), so Clients should be reused instead of created as needed. Clients are safe for use by multiple goroutines.

func (*Client) APIReq

func (c *Client) APIReq(isStarterPlan bool, meth, path string, v interface{}) error

Sends a Heroku Postgres API request and decodes the response into v. As described in DoReq(), the type of v determines how to handle the response body.

func (*Client) DoReq

func (c *Client) DoReq(req *http.Request, v interface{}) error

Submits an HTTP request, checks its response, and deserializes the response into v. The type of v determines how to handle the response body:

nil        body is discarded
io.Writer  body is copied directly into v
else       body is decoded into v as json

func (*Client) Get

func (c *Client) Get(isStarterPlan bool, path string, v interface{}) error

func (*Client) NewDB

func (c *Client) NewDB(id, plan string) DB

Creates a new DB struct initialized with this Client.

func (*Client) NewRequest

func (c *Client) NewRequest(isStarterPlan bool, method, path string) (*http.Request, error)

Generates an HTTP request for the Heroku Postgres API, but does not perform the request. The request's Accept header field will be set to:

Accept: application/json

The Request-Id header will be set to a random UUID. The User-Agent header will be set to the Client's UserAgent, or DefaultUserAgent if UserAgent is not set.

isStarterPlan should be set to true if the target database is a starter plan, and false otherwise (as defined in DB.IsStarterPlan() ). Method is the HTTP method of this request, and path is the HTTP path.

func (*Client) Post

func (c *Client) Post(isStarterPlan bool, path string, v interface{}) error

func (*Client) Put

func (c *Client) Put(isStarterPlan bool, path string, v interface{}) error

type DB

type DB struct {
	Id   string
	Name string
	Plan string
	// contains filtered or unexported fields
}

func (*DB) Info

func (d *DB) Info() (dbi DBInfo, err error)

func (*DB) Ingress

func (d *DB) Ingress() error

func (*DB) IsStarterPlan

func (d *DB) IsStarterPlan() bool

Whether the DB is a starter plan and should communicate with the starter API. Plan names ending in "dev" or "basic" are currently handled by the starter API while all others are handled by the production API.

func (*DB) Reset

func (d *DB) Reset() error

func (*DB) RotateCredentials

func (d *DB) RotateCredentials() error

func (*DB) Unfollow

func (d *DB) Unfollow() error

func (*DB) WaitStatus

func (d *DB) WaitStatus() (ws WaitStatus, err error)

type DBInfo

type DBInfo struct {
	AvailableForIngress   bool          `json:"available_for_ingress"`
	CreatedAt             string        `json:"created_at"`
	CurrentTransaction    string        `json:"current_transaction"`
	DatabaseName          string        `json:"database_name"`
	DatabasePassword      string        `json:"database_password"`
	DatabaseUser          string        `json:"database_user"`
	Following             string        `json:"following"`
	Info                  InfoEntryList `json:"info"`
	IsInRecovery          bool          `json:"is_in_recovery?"`
	NumBytes              int           `json:"num_bytes"`
	NumConnections        int           `json:"num_connections"`
	NumConnectionsWaiting int           `json:"num_connections_waiting"`
	NumTables             int           `json:"num_tables"`
	Plan                  string        `json:"plan"`
	PostgresqlVersion     string        `json:"postgresql_version"`
	ResourceURL           string        `json:"resource_url"`
	ServicePort           int           `json:"service_port"`
	StatusUpdatedAt       time.Time     `json:"status_updated_at"`
	Standalone            bool          `json:"standalone?"`
	TargetTransaction     string        `json:"target_transaction"`
}

func (*DBInfo) IsFollower

func (dbi *DBInfo) IsFollower() bool

type InfoEntry

type InfoEntry struct {
	Name          string
	ResolveDBName bool `json:"resolve_db_name"`
	Values        []interface{}
}

type InfoEntryList

type InfoEntryList []InfoEntry

func (*InfoEntryList) GetString

func (iel *InfoEntryList) GetString(key string) (valstr string, resolve bool)

func (*InfoEntryList) Named

func (iel *InfoEntryList) Named(name string) *InfoEntry

type WaitStatus

type WaitStatus struct {
}

Jump to

Keyboard shortcuts

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