now

package module
v0.0.0-...-4eca472 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2017 License: BSD-3-Clause Imports: 14 Imported by: 0

README

go-now

Client for Zeit Now deployment API

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Installation

go get github.com/manifoldco/go-now

Example

import "github.com/manifoldco/go-now"

n := now.New("your-api-secret")

pkg := map[string]interface{}{
  "index.js": "require('http').Server((req, res) => { res.end('Hello World!'); }).listen();",
  "package": map[string]interface{}{
    "name": "hello-world",
    "scripts": map[string]string{
      "start": "node index",
    },
  },
}
d, err := n.Deployment.New(pkg)

// &{UID: "7Npest0z1zW5QVFfNDBId4BW", Host: "hello-world-abcdefhi.now.sh", State: "BOOTING"} 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerFiles

func DockerFiles(dir string) (*[]string, error)

DockerFiles returns an array of paths for a given Docker project

func NpmFiles

func NpmFiles(dir string) (*[]string, error)

NpmFiles returns an array of paths for a given npm package

func PackageType

func PackageType(dir string) string

PackageType infers the project's type

func StaticFiles

func StaticFiles(dir string) (*[]string, error)

StaticFiles returns an array of paths for a given static project

Types

type Alias

type Alias struct {
	UID     string     `json:"uid,omitempty"`
	OldUID  string     `json:"oldId,omitempty"`
	Alias   string     `json:"alias"`
	Created *time.Time `json:"created,omitempty"`
}

Alias represents a deployment alias object

type Cert

type Cert struct {
	UID     string     `json:"uid"`
	Created *time.Time `json:"created,omitempty"`
}

Cert is the contents of an ssl certificate object

type CertParams

type CertParams struct {
	DomainNames []string `json:"domains"`
	Renew       bool     `json:"renew"`
}

CertParams contains all fields for create

type CertsClient

type CertsClient struct {
	// contains filtered or unexported fields
}

CertsClient contains the methods for the Cert API

func (CertsClient) Delete

func (c CertsClient) Delete(domainName string) ClientError

Delete deletes the domain by its ID

func (CertsClient) List

func (c CertsClient) List() ([]*Cert, ClientError)

List retrieves a list of all the domains under the account

func (CertsClient) New

func (c CertsClient) New(domainNames []string) (Cert, ClientError)

New creates a new cert

func (CertsClient) NewFromParams

func (c CertsClient) NewFromParams(params CertParams) (Cert, ClientError)

NewFromParams creates a new cert from params

func (CertsClient) Renew

func (c CertsClient) Renew(domainNames []string) (Cert, ClientError)

Renew renews and existing cert

type Client

type Client struct {
	URL        string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client contains all methods used for making API requests

func (Client) Authenticated

func (c Client) Authenticated() bool

Authenticated returns whether the secret value is set

func (Client) NewFileRequest

func (c Client) NewFileRequest(method, path string, file *os.File, v interface{}, headers *map[string]string) ClientError

NewFileRequest performs an authenticated file upload for the given params

func (Client) NewRequest

func (c Client) NewRequest(method, path string, body interface{}, v interface{}, headers *map[string]string) ClientError

NewRequest performs an authenticated request for the given params

func (Client) SetHTTPClient

func (c Client) SetHTTPClient(h *http.Client)

SetHTTPClient overrides the default HTTP client used

type ClientError

type ClientError interface {
	StatusCode() int
	Code() string
	Message() string
	Error() string
}

ClientError represents the error return type

func NewError

func NewError(err string) ClientError

NewError construct a new ClientError

func NewZeitError

func NewZeitError(statusCode int, err *ZeitError) ClientError

NewZeitError construct a new ClientError

type Deployment

type Deployment struct {
	UID            string     `json:"uid"`
	Host           string     `json:"host"`
	State          string     `json:"state"`
	StateTimestamp *time.Time `json:"stateTs,omitempty"`
}

Deployment is the contents of a deploy object

type DeploymentAliasParams

type DeploymentAliasParams struct {
	Alias string `json:"alias"`
}

DeploymentAliasParams contains all fields for aliasing

type DeploymentContent

type DeploymentContent interface {
	GetType() DeploymentContentType
	GetName() string
}

DeploymentContent represents a file or directory for deploy

type DeploymentContentType

type DeploymentContentType string

DeploymentContentType represents a DeploymentContent type string

const (
	TypeDir  DeploymentContentType = "directory"
	TypeFile DeploymentContentType = "file"
)

DeploymentContentTypes

type DeploymentDir

type DeploymentDir struct {
	Type     DeploymentContentType `json:"type"`
	Name     string                `json:"name"`
	Children []DeploymentContent   `json:"children"`
}

DeploymentDir is the contents of a directory object for deploy

func (DeploymentDir) GetName

func (d DeploymentDir) GetName() string

GetName implements the DeploymentContent interface

func (DeploymentDir) GetType

GetType implements the DeploymentContent interface

type DeploymentFile

type DeploymentFile struct {
	Type         DeploymentContentType `json:"type"`
	Name         string                `json:"name"`
	UID          string                `json:"uid,omitempty"`
	Scripts      map[string]string     `json:"scripts,omitempty"`
	Dependencies map[string]string     `json:"dependencies,omitempty"`
	Version      string                `json:"version,omitempty"`
	Description  string                `json:"description,omitempty"`
}

DeploymentFile is the contents of a file object for deploy

func (DeploymentFile) GetName

func (d DeploymentFile) GetName() string

GetName implements the DeploymentContent interface

func (DeploymentFile) GetType

GetType implements the DeploymentContent interface

type DeploymentParams

type DeploymentParams struct {
	Env         map[string]string `json:"env"`
	Public      bool              `json:"public"`
	ForceNew    bool              `json:"forceNew"`
	ForceSync   bool              `json:"forceSync"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Type        string            `json:"deploymentType"`
	Files       []FileInfo        `json:"files"`
}

DeploymentParams contains all fields necessary to create a deployment

type DeploymentsClient

type DeploymentsClient struct {
	// contains filtered or unexported fields
}

DeploymentsClient contains the methods for the Deployment API

func (DeploymentsClient) Alias

func (c DeploymentsClient) Alias(ID, alias string) (Alias, ClientError)

Alias applies the supplied alias to the given deployment ID

func (DeploymentsClient) Delete

func (c DeploymentsClient) Delete(ID string) ClientError

Delete deletes the deployment by its ID

func (DeploymentsClient) Files

Files retrieves files of a deployment by its ID

func (DeploymentsClient) Get

Get retrieves a deployment by its ID

func (DeploymentsClient) List

List retrieves a list of all the deployments under the account

func (DeploymentsClient) ListAliases

func (c DeploymentsClient) ListAliases(ID string) ([]Alias, ClientError)

ListAliases retrieves aliases of a deployment by its ID

func (DeploymentsClient) New

New creates a new Deployment

func (DeploymentsClient) Scale

func (c DeploymentsClient) Scale(ID string, min, max int) (Deployment, ClientError)

Scale sets the scale of a deployment to the number provided

func (DeploymentsClient) Upload

func (c DeploymentsClient) Upload(deploymentID, sha string, names []string, size int64, data *os.File) ClientError

Upload performs an upload of the given file to the specified deployment

type Domain

type Domain struct {
	UID         string     `json:"uid"`
	Name        string     `json:"name"`
	Verified    bool       `json:"verified"`
	VerifyToken string     `json:"verifyToken,omitempty"`
	Created     *time.Time `json:"created,omitempty"`
}

Domain is the contents of a domain object

type DomainParams

type DomainParams struct {
	Name       string `json:"name"`
	IsExternal bool   `json:"isExternal"`
}

DomainParams contains all fields for domain create

type DomainsClient

type DomainsClient struct {
	// contains filtered or unexported fields
}

DomainsClient contains the methods for the Domain API

func (DomainsClient) Delete

func (c DomainsClient) Delete(domainName string) ClientError

Delete deletes the domain by its ID

func (DomainsClient) List

func (c DomainsClient) List() ([]Domain, ClientError)

List retrieves a list of all the domains under the account

func (DomainsClient) New

func (c DomainsClient) New(domainName string, external bool) (Domain, ClientError)

New creates a new Domain

func (DomainsClient) NewFromParams

func (c DomainsClient) NewFromParams(params DomainParams) (Domain, ClientError)

NewFromParams creates a new Domain from params

type ErrZeitResponse

type ErrZeitResponse struct {
	StatusCode int
	Err        *ZeitError `json:"err,omitempty"`
	AltErr     *ZeitError `json:"error,omitempty"`
}

ErrZeitResponse represents the body returned on error

func (ErrZeitResponse) ZeitError

func (e ErrZeitResponse) ZeitError() *ZeitError

ZeitError returns the ZeitError depending on which response was given from the api Sometimes Zeit returns `err` sometimes `error` XXX: Reported to Zeit #now slack channel on Aug 24, 2017

type FileHash

type FileHash struct {
	Sha   string
	Names []FileInfo
	Path  string
}

FileHash represents a file's info, including duplicate names

type FileHashMap

type FileHashMap map[string]FileHash

FileHashMap represents a map of files and their hashes

func NewFilesList

func NewFilesList(wd string, paths []string) (*[]FileInfo, *FileHashMap, error)

NewFilesList returns an array of FileInfo arrays for the given list of paths

type FileInfo

type FileInfo struct {
	Sha  string `json:"sha"`
	Size int64  `json:"size"`
	File string `json:"file"`
	Mode uint32 `json:"mode"`
}

FileInfo represents a deployment file to be uploaded

type IncompleteDeployment

type IncompleteDeployment struct {
	ID        string   `json:"deploymentID"`
	URL       string   `json:"url"`
	TotalSize int      `json:"totalSize"`
	Missing   []string `json:"missing"`
	Warnings  []string `json:"warnings"`
}

IncompleteDeployment is the contents of a deploy object before upload

type InviteParams

type InviteParams struct {
	Email string `json:"email"`
}

InviteParams contains possible fields for invite

type Now

type Now struct {
	Certs       *CertsClient
	Deployments *DeploymentsClient
	Domains     *DomainsClient
	Plans       *PlansClient
	Teams       *TeamsClient
	// contains filtered or unexported fields
}

Now contains all the methods required for interacting with Zeit Now's API

func New

func New(secret string) *Now

New returns an authenticated Now api client

func (Now) SetTeamID

func (n Now) SetTeamID(teamID string)

SetTeamID updates the client's global team_id value

type Plan

type Plan struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Amount        int64  `json:"amount"`
	Currency      string `json:"currency"`
	Interval      string `json:"interval"`
	IntervalCount int64  `json:"interval_count"`
}

Plan contains all fields relevant to a plan object

type PlansClient

type PlansClient struct {
	// contains filtered or unexported fields
}

PlansClient contains the methods for the Plan API

func (PlansClient) Current

func (c PlansClient) Current() (Subscription, ClientError)

Current returns the authenticated user's subscription

type RenameParams

type RenameParams struct {
	Name string `json:"name"`
}

RenameParams contains possible fields for rename

type ScaleParams

type ScaleParams struct {
	Min int `json:"min"`
	Max int `json:"max"`
}

ScaleParams contains all fields necessary to set the scale of a deployment

type Subscription

type Subscription struct {
	ID   string `json:"id"`
	Plan Plan   `json:"plan"`
}

Subscription represents a user's subscription state

type Team

type Team struct {
	ID        string     `json:"id"`
	Slug      string     `json:"slug"`
	Name      string     `json:"name"`
	CreatorID string     `json:"creator_id"`
	Created   *time.Time `json:"created,omitempty"`
}

Team is the contents of a team object

type TeamMember

type TeamMember struct {
	UID      string `json:"uid"`
	Role     string `json:"role"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

TeamMember represents a membership to a team

type TeamParams

type TeamParams struct {
	Slug string `json:"slug"`
}

TeamParams contains possible fields for creation

type TeamsClient

type TeamsClient struct {
	// contains filtered or unexported fields
}

TeamsClient contains the methods for the Team API

func (TeamsClient) Delete

func (c TeamsClient) Delete(teamID string) ClientError

Delete deletes the domain by its ID

func (TeamsClient) InviteUser

func (c TeamsClient) InviteUser(teamID, email string) ClientError

InviteUser sends an invite for the specified team to the email provided

func (TeamsClient) List

func (c TeamsClient) List() ([]Team, ClientError)

List retrieves a list of all the domains under the account

func (TeamsClient) Members

func (c TeamsClient) Members(teamID string) ([]TeamMember, ClientError)

Members retrieves all members associated with a team

func (TeamsClient) New

func (c TeamsClient) New(slug string) (Team, ClientError)

New creates a new Team

func (TeamsClient) NewFromParams

func (c TeamsClient) NewFromParams(params TeamParams) (Team, ClientError)

NewFromParams creates a new Team from params

func (TeamsClient) Rename

func (c TeamsClient) Rename(teamID, name string) ClientError

Rename updates the name value for the specified team

type ZeitError

type ZeitError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	URL     string `json:"url"`
}

ZeitError contains the api-specific error response fields

Jump to

Keyboard shortcuts

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