Documentation ¶
Overview ¶
Package netlify provides a client for using the netlify API.
To work with the netlify API, start by instantiating a client:
client := netlify.NewClient(&netlify.Config{AccessToken: AccessToken}) // List sites sites, resp, err := client.Sites.List(&netlify.ListOptions{Page: 1}) // Create a new site site, resp, err := client.Sites.Create(&SiteAttributes{ Name: "site-subdomain", CustomDomain: "www.example.com", Password: "secret", NotificationEmail: "me@example.com", }) // Deploy a directory deploy, resp, err := site.Deploys.Create("/path/to/directory") // Wait for the deploy to process err := deploy.WaitForReady(0) // Get a single site site, resp, err := client.Sites.Get("my-site-id") // Set the domain of the site site.CustomDomain = "www.example.com" // Update the site resp, err := site.Update() // Deploy a new version of the site from a zip file deploy, resp, err := site.Deploys.Create("/path/to/file.zip") deploy.WaitForReady(0) // Configure Continuous Deployment for a site // First get a deploy key deployKey, resp, err := site.DeployKeys.Create() // Then make sure the public key (deployKey.PublicKey) // has access to the repository // Configure the repo resp, err = site.ContinuousDeployment(&nefliy.RepoOptions{ Repo: "netlify/netlify-home", Provider: "github", Dir: "_site", Cmd: "gulp build", Branch: "master", DeployKeyId: deployKey.Id }) if err != nil { // Now make sure to add this URL as a POST webhook to your // repository: site.DeployHook } // Deleting a site resp, err := site.Destroy()
Index ¶
- Constants
- type BuildSettings
- type CertOptions
- type Client
- type Config
- type Deploy
- func (deploy *Deploy) Deploy(dirOrZip string) (*Response, error)
- func (deploy *Deploy) DeployDirWithGitInfo(dir, branch, commitRef string) (*Response, error)
- func (deploy *Deploy) Publish() (*Response, error)
- func (deploy *Deploy) Reload() (*Response, error)
- func (deploy *Deploy) Restore() (*Response, error)
- func (deploy *Deploy) WaitForReady(timeout time.Duration) error
- type DeployInfo
- type DeployKey
- type DeployKeysService
- type DeploysService
- func (s *DeploysService) Create(dirOrZip string) (*Deploy, *Response, error)
- func (s *DeploysService) CreateDraft(dirOrZip string) (*Deploy, *Response, error)
- func (d *DeploysService) Get(id string) (*Deploy, *Response, error)
- func (s *DeploysService) List(options *ListOptions) ([]Deploy, *Response, error)
- type ErrorResponse
- type ListOptions
- type ProcessingSettings
- type RepoOptions
- type RequestOptions
- type Response
- type Site
- type SiteAttributes
- type SitesService
- type Timestamp
Constants ¶
const (
DefaultMaxConcurrentUploads = 10
)
const MaxFilesForSyncDeploy = 1000
const PreProcessingTimeout = time.Minute * 5
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildSettings ¶
type BuildSettings struct { RepoType string `json:"repo_type"` RepoURL string `json:"repo_url"` RepoBranch string `json:"repo_branch"` Cmd string `json:"cmd"` Dir string `json:"dir"` Env map[string]string `json:"env"` CreatedAt Timestamp `json:"created_at"` UpdatedAt Timestamp `json:"updated_at"` }
Settings for continuous deployment
type CertOptions ¶
type CertOptions struct { Certificate string `json:"certificate"` Key string `json:"key"` CaCertificates []string `json:"ca_certificates"` }
Attributes for site.ProvisionCert
type Client ¶
type Client struct { BaseUrl *url.URL UserAgent string Sites *SitesService Deploys *DeploysService DeployKeys *DeployKeysService MaxConcurrentUploads int // contains filtered or unexported fields }
The netlify Client
func (*Client) Request ¶
func (c *Client) Request(method, path string, options *RequestOptions, decodeTo interface{}) (*Response, error)
Request sends an authenticated HTTP request to the netlify API
When error is nil, resp always contains a non-nil Response object ¶
Generally methods on the various services should be used over raw API requests
type Config ¶
type Config struct { AccessToken string ClientId string ClientSecret string BaseUrl string UserAgent string HttpClient *http.Client RequestTimeout time.Duration MaxConcurrentUploads int }
Config is used to configure the netlify client. Typically you'll just want to set an AccessToken
type Deploy ¶
type Deploy struct { Id string `json:"id"` SiteId string `json:"site_id"` UserId string `json:"user_id"` // State of the deploy (uploading/uploaded/processing/ready/error) State string `json:"state"` // Cause of error if State is "error" ErrorMessage string `json:"error_message"` // Shas of files that needs to be uploaded before the deploy is ready Required []string `json:"required"` DeployUrl string `json:"deploy_url"` SiteUrl string `json:"url"` ScreenshotUrl string `json:"screenshot_url"` CreatedAt Timestamp `json:"created_at"` UpdatedAt Timestamp `json:"updated_at"` Branch string `json:"branch,omitempty"` CommitRef string `json:"commit_ref,omitempty"` // contains filtered or unexported fields }
Deploy represents a specific deploy of a site
func (*Deploy) DeployDirWithGitInfo ¶ added in v0.1.3
DeployDirWithGitInfo scans the given directory and deploys the files that have changed on Netlify.
This function allows you to supply git information about the deploy when it hasn't been set previously be a Continuous Deployment process.
type DeployInfo ¶
type DeployInfo struct { Id string `json:"id"` DeployId string `json:"deploy_id"` Required []string `json:"required"` }
Info returned when creating a new deploy
type DeployKey ¶
type DeployKey struct { Id string `json:"id"` PublicKey string `json:"public_key"` CreatedAt Timestamp `json:"created_at"` }
DeployKey for use with continuous deployment setups
type DeployKeysService ¶
type DeployKeysService struct {
// contains filtered or unexported fields
}
DeployKeysService is used to access all DeployKey related API methods
type DeploysService ¶
type DeploysService struct {
// contains filtered or unexported fields
}
DeploysService is used to access all Deploy related API methods
func (*DeploysService) Create ¶
func (s *DeploysService) Create(dirOrZip string) (*Deploy, *Response, error)
Create a new deploy
Example: site.Deploys.Create("/path/to/site-dir", true) If the target is a zip file, it must have the extension .zip
func (*DeploysService) CreateDraft ¶
func (s *DeploysService) CreateDraft(dirOrZip string) (*Deploy, *Response, error)
CreateDraft a new draft deploy. Draft deploys will be uploaded and processed, but won't affect the active deploy for a site.
func (*DeploysService) Get ¶
func (d *DeploysService) Get(id string) (*Deploy, *Response, error)
Get a specific deploy.
func (*DeploysService) List ¶
func (s *DeploysService) List(options *ListOptions) ([]Deploy, *Response, error)
List all deploys. Takes ListOptions to control pagination.
type ErrorResponse ¶
ErrorResponse is returned when a request to the API fails
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type ListOptions ¶
All List methods takes a ListOptions object controlling pagination
type ProcessingSettings ¶
type ProcessingSettings struct { CSS struct { Minify bool `json:"minify"` Bundle bool `json:"bundle"` } `json:"css"` JS struct { Minify bool `json:"minify"` Bundle bool `json:"bundle"` } `json:"js"` HTML struct { PrettyURLs bool `json:"pretty_urls"` } `json:"html"` Images struct { Optimize bool `json:"optimize"` } `json:"images"` Skip bool `json:"skip"` }
Settings for post processing
type RepoOptions ¶
type RepoOptions struct { // GitHub API ID or similar unique repo ID Id string `json:"id"` // Repo path. Full ssh based path for manual repos, // username/reponame for GitHub or BitBucket Repo string `json:"repo"` // Currently "github", "bitbucket" or "manual" Provider string `json:"provider"` // Directory to deploy after building Dir string `json:"dir"` // Build command Cmd string `json:"cmd"` // Branch to pull from Branch string `json:"branch"` // Build environment variables Env *map[string]string `json:"env"` // ID of a netlify deploy key used to access the repo DeployKeyID string `json:"deploy_key_id"` }
Attributes for setting up continuous deployment
type RequestOptions ¶
type RequestOptions struct { JsonBody interface{} RawBody io.Reader RawBodyLength int64 QueryParams *url.Values Headers *map[string]string }
RequestOptions for doing raw requests to the netlify API
type Response ¶
netlify API Response. All API methods on the different client services will return a Response object. For any list operation this object will hold pagination information
type Site ¶
type Site struct { Id string `json:"id"` UserId string `json:"user_id"` // These fields can be updated through the API Name string `json:"name"` CustomDomain string `json:"custom_domain"` DomainAliases []string `json:"domain_aliases"` Password string `json:"password"` NotificationEmail string `json:"notification_email"` State string `json:"state"` Plan string `json:"plan"` SSLPlan string `json:"ssl_plan"` Premium bool `json:"premium"` Claimed bool `json:"claimed"` Url string `json:"url"` AdminUrl string `json:"admin_url"` DeployUrl string `json:"deploy_url"` ScreenshotUrl string `json:"screenshot_url"` SSL bool `json:"ssl"` ForceSSL bool `json:"force_ssl"` BuildSettings *BuildSettings `json:"build_settings"` ProcessingSettings *ProcessingSettings `json:"processing_settings"` DeployHook string `json:"deploy_hook"` CreatedAt Timestamp `json:"created_at"` UpdatedAt Timestamp `json:"updated_at"` // Access deploys for this site Deploys *DeploysService // contains filtered or unexported fields }
Site represents a netlify Site
func (*Site) ContinuousDeployment ¶
func (site *Site) ContinuousDeployment(repoOptions *RepoOptions) (*Response, error)
Configure Continuous Deployment for a site
func (*Site) ProvisionCert ¶
func (site *Site) ProvisionCert(certOptions *CertOptions) (*Response, error)
Provision SSL Certificate for a site. Takes optional CertOptions to set a custom cert/chain/key. Without this netlify will generate the certificate automatically.
type SiteAttributes ¶
type SiteAttributes struct { Name string `json:"name"` CustomDomain string `json:"custom_domain"` Password string `json:"password"` NotificationEmail string `json:"notification_email"` ForceSSL bool `json:"force_ssl"` ProcessingSettings bool `json:"processing_options"` Repo *RepoOptions `json:"repo"` }
Attributes for Sites.Create
type SitesService ¶
type SitesService struct {
// contains filtered or unexported fields
}
SitesService is used to access all Site related API methods
func (*SitesService) Create ¶
func (s *SitesService) Create(attributes *SiteAttributes) (*Site, *Response, error)
Create a new empty site.
func (*SitesService) Get ¶
func (s *SitesService) Get(id string) (*Site, *Response, error)
Get a single Site from the API. The id can be either a site Id or the domain of a site (ie. site.Get("mysite.netlify.com"))
func (*SitesService) List ¶
func (s *SitesService) List(options *ListOptions) ([]Site, *Response, error)
List all sites you have access to. Takes ListOptions to control pagination.
type Timestamp ¶
Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.