package module
v0.0.0-...-537772e Latest Latest

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

Go to latest
Published: Jun 21, 2014 License: MIT Imports: 18 Imported by: 0



Package ghastly provides a golang interface for using the Fastly ( CDN's API.



View Source
const DefaultMaxIdleConnsPerHost = 2

DefaultMaxIdleConnsPerHost is the default value of Transport's MaxIdleConnsPerHost.


This section is empty.


func ParseJson

func ParseJson(data io.ReadCloser) (map[string]interface{}, error)

func ParseJsonArray

func ParseJsonArray(data io.ReadCloser) ([]interface{}, error)

func ProxyFromEnvironment

func ProxyFromEnvironment(req *http.Request) (*url.URL, error)

ProxyFromEnvironment returns the URL of the proxy to use for a given request, as indicated by the environment variables $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy). An error is returned if the proxy environment is invalid. A nil URL and nil error are returned if no proxy is defined in the environment, or a proxy should not be used for the given request.

func ProxyURL

func ProxyURL(fixedURL *url.URL) func(*http.Request) (*url.URL, error)

ProxyURL returns a proxy function (for use in a Transport) that always returns the same URL.


type Client

type Client struct {
	ApiKey    string
	User      string
	Password  string
	BaseUrl   string
	Http      *http.Client
	PurgeHttp *http.Client

func (*Client) Delete

func (c *Client) Delete(url string, contentType ...string) (*http.Response, error)

Convenience wrapper for DELETE requests.

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

Convenience wrapper around http.Client.Get.

func (*Client) GetParams

func (c *Client) GetParams(baseURL string, queryParams map[string]string) (*http.Response, error)

Convenience wrapper for GET requests with query parameters.

func (*Client) Post

func (c *Client) Post(url string, bodyType string, body io.Reader) (*http.Response, error)

Convenience wrapper around http.Client.Post.

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) (*http.Response, error)

Convenience wrapper around http.Client.PostForm.

func (*Client) PostFormParams

func (c *Client) PostFormParams(url string, params map[string]string) (*http.Response, error)

Post a form to the server with a map[string]string of paramaters.

func (*Client) Purge

func (c *Client) Purge(purgeUrl string, contentType ...string) (*http.Response, error)

Send a PURGE request.

func (*Client) Put

func (c *Client) Put(url string, data url.Values, contentType ...string) (*http.Response, error)

Convenience wrapper for PUT requests.

func (*Client) PutParams

func (c *Client) PutParams(url string, params map[string]string) (*http.Response, error)

Convenience wrapper for PUT requests, taking a map of strings to create the url.Values to send.

type Domain

type Domain struct {
	Name      string
	Comment   string
	ServiceId string
	Version   int64
	Locked    bool
	// contains filtered or unexported fields

func (*Domain) Delete

func (d *Domain) Delete() error

Delete a domain, for the version the domain belongs to.

func (*Domain) Update

func (d *Domain) Update(params map[string]string) error

Update a domain, for the version the domain belongs to. Possible parameters for the domain are "name" and "comment".

type DomainCheck

type DomainCheck struct {
	Cname    string
	IsProper bool

type Ghastly

type Ghastly struct {

func New

func New(opts map[string]string) (*Ghastly, error)

Initialize a new ghastly object, create the HTTP client, and log in.

func (*Ghastly) GetService

func (g *Ghastly) GetService(id string) (*Service, error)

Get a service with the ID string.

func (*Ghastly) ListServices

func (g *Ghastly) ListServices() ([]*Service, error)

List the current services.

func (*Ghastly) NewService

func (g *Ghastly) NewService(name string) (*Service, error)

Create a new service.

func (*Ghastly) PurgeURL

func (g *Ghastly) PurgeURL(url string) (string, error)

Purge a URL from the CDN.

func (*Ghastly) SearchServices

func (g *Ghastly) SearchServices(searchStr string) (*Service, error)

Search for a service by name. The API does not appear to permit wildcards at this time.

type Service

type Service struct {
	Id            string
	Name          string
	CustomerId    string
	PublishKey    string
	Comment       string
	ActiveVersion int64
	UpdatedAt     time.Time
	CreatedAt     time.Time
	// contains filtered or unexported fields

A Service is a particular website, app, etc. served through Fastly. They are configured with different versions, which have backends, domains, etc.

func (*Service) Delete

func (s *Service) Delete() error

Delete a service and everything attached to it.

func (*Service) Details

func (s *Service) Details() (*Service, error)

Get detailed information about a service.

func (*Service) GetVersion

func (s *Service) GetVersion(number int64) (*Version, error)

Get a particular version of this service identified by the version number.

func (*Service) NewVersion

func (s *Service) NewVersion() (*Version, error)

Create a brand new, pristine version of a service, with nothing in it.

func (*Service) PurgeAll

func (s *Service) PurgeAll() error

Purge everything from a service.

func (*Service) PurgeKey

func (s *Service) PurgeKey(key string) error

Purge a service of items tagged with a particular key.

func (*Service) TaskURL

func (s *Service) TaskURL(taskPath string) string

Make the base URL for this service for performing tasks.

func (*Service) Update

func (s *Service) Update(params map[string]string) error

Update a service's attributes with a map of strings for params. Currently the only meaningful attribute that can be updated here is the service's name.

type Transport

type Transport struct {

	// Proxy specifies a function to return a proxy for a given
	// Request. If the function returns a non-nil error, the
	// request is aborted with the provided error.
	// If Proxy is nil or returns a nil *URL, no proxy is used.
	Proxy func(*http.Request) (*url.URL, error)

	// Dial specifies the dial function for creating TCP
	// connections.
	// If Dial is nil, net.Dial is used.
	Dial func(network, addr string) (net.Conn, error)

	// TLSClientConfig specifies the TLS configuration to use with
	// tls.Client. If nil, the default configuration is used.
	TLSClientConfig *tls.Config

	// DisableKeepAlives, if true, prevents re-use of TCP connections
	// between different HTTP requests.
	DisableKeepAlives bool

	// DisableCompression, if true, prevents the Transport from
	// requesting compression with an "Accept-Encoding: gzip"
	// request header when the Request contains no existing
	// Accept-Encoding value. If the Transport requests gzip on
	// its own and gets a gzipped response, it's transparently
	// decoded in the Response.Body. However, if the user
	// explicitly requested gzip it is not automatically
	// uncompressed.
	DisableCompression bool

	// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
	// (keep-alive) to keep per-host.  If zero,
	// DefaultMaxIdleConnsPerHost is used.
	MaxIdleConnsPerHost int

	// ResponseHeaderTimeout, if non-zero, specifies the amount of
	// time to wait for a server's response headers after fully
	// writing the request (including its body, if any). This
	// time does not include the time to read the response body.
	ResponseHeaderTimeout time.Duration

	// PurgeBaseURL, used to craft PURGE requests for individual items where
	// the URL in the PURGE command (ex. PURGE is
	// not on the server the PURGE command is being sent to (like
	PurgeBaseURL *url.URL
	// contains filtered or unexported fields

Transport is an implementation of RoundTripper that supports http, https, and http proxies (for either http or https with CONNECT). Transport can also cache connections for future re-use.

func (*Transport) CancelRequest

func (t *Transport) CancelRequest(req *http.Request)

CancelRequest cancels an in-flight request by closing its connection.

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

CloseIdleConnections closes any connections which were previously connected from previous requests but are now sitting idle in a "keep-alive" state. It does not interrupt any connections currently in use.

func (*Transport) RegisterProtocol

func (t *Transport) RegisterProtocol(scheme string, rt http.RoundTripper)

RegisterProtocol registers a new protocol with scheme. The Transport will pass requests using the given scheme to rt. It is rt's responsibility to simulate HTTP request semantics.

RegisterProtocol can be used by other packages to provide implementations of protocol schemes like "ftp" or "file".

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip implements the RoundTripper interface.

For higher-level HTTP client support (such as handling of cookies and redirects), see Get, Post, and the Client type.

type Version

type Version struct {
	Number    int64
	ServiceId string
	Active    bool
	Locked    bool
	Comment   string
	Testing   bool
	Staging   bool
	Deployed  bool
	Network   VersionNetwork
	// contains filtered or unexported fields

A version of the configuration for a particular service. Backends, domains, etc. belong to a particular version.

func (*Version) CheckAllDomains

func (v *Version) CheckAllDomains() ([]*DomainCheck, error)

Check all domains associated with a version of a service.

func (*Version) CheckDomain

func (v *Version) CheckDomain(name string) (*DomainCheck, error)

Check one domain associated with a service.

func (*Version) Clone

func (v *Version) Clone() (*Version, error)

Clone this version of the service, returning the new version.

func (*Version) GetDomain

func (v *Version) GetDomain(name string) (*Domain, error)

Get a domain associated with this version

func (*Version) ListDomains

func (v *Version) ListDomains() ([]*Domain, error)

List all domains associated with a version of a service.

func (*Version) NewDomain

func (v *Version) NewDomain(params map[string]string) (*Domain, error)

Create a new domain for a particular version of a service. Possible parameters are "name" and "comment".

type VersionNetwork

type VersionNetwork struct {
	Name                string
	Description         string
	AvailableAll        bool
	AvailableRestricted bool
	AvailablePrivate    bool
	CustomerId          string

Jump to

Keyboard shortcuts

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