lade

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: BSD-3-Clause Imports: 23 Imported by: 1

README

Go Lade

Build Status Go.Dev Reference Release

Go Lade is a Go client library for the Lade V1 API.

Installation

go get github.com/lade-io/go-lade

Usage

Currently, the only authentication method is password credentials. You can enter your username and password to create a new token:

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/lade-io/go-lade"
	"golang.org/x/crypto/ssh/terminal"
	"golang.org/x/oauth2"
)

func main() {
	conf := &oauth2.Config{
		ClientID: lade.DefaultClientID,
		Scopes:   lade.DefaultScopes,
		Endpoint: lade.Endpoint,
	}

	ctx := context.Background()
	username, password := getCredentials()

	token, err := conf.PasswordCredentialsToken(ctx, username, password)
	if err != nil {
		log.Fatal(err)
	}

	httpClient := conf.Client(ctx, token)
	client := lade.NewClient(httpClient)

	user, err := client.User.Me()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", user)
}

func getCredentials() (string, string) {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Username: ")
	username, _ := reader.ReadString('\n')

	fmt.Print("Password: ")
	bytePassword, _ := terminal.ReadPassword(0)
	password := string(bytePassword)
	fmt.Println()

	return strings.TrimSpace(username), strings.TrimSpace(password)
}

Documentation

Index

Constants

View Source
const (
	DefaultClientID = "lade-client"
)

Variables

View Source
var (
	DefaultScopes = []string{"app", "user", "offline"}
	Endpoint      = oauth2.Endpoint{
		AuthURL:   "https://lade.io/login/oauth2/authorize",
		TokenURL:  "https://lade.io/login/oauth2/token",
		AuthStyle: oauth2.AuthStyleInHeader,
	}
)
View Source
var ErrNotFound = &APIError{
	Type:    "not_found",
	Message: "Resource not found",
	Status:  http.StatusNotFound,
}
View Source
var ErrServerError = &APIError{
	Type:    "server_error",
	Message: "Unexpected server error",
	Status:  http.StatusInternalServerError,
}

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Type    string `json:"error"`
	Message string `json:"error_description"`
	Status  int    `json:"-"`
}

func (*APIError) Error

func (e *APIError) Error() string

type Addon

type Addon struct {
	ID           int       `json:"id"`
	Name         string    `json:"name"`
	Owner        *User     `json:"owner"`
	Service      *Service  `json:"service"`
	PlanID       string    `json:"plan_id"`
	Region       *Region   `json:"region"`
	Release      string    `json:"release"`
	Public       bool      `json:"public"`
	Status       string    `json:"status"`
	Hostname     string    `json:"hostname"`
	Port         int       `json:"port"`
	Database     string    `json:"database"`
	Username     string    `json:"username"`
	Password     string    `json:"password"`
	BackupLimit  int       `json:"backup_limit"`
	BackupWindow string    `json:"backup_window"`
	CreatedAt    time.Time `json:"created_at"`
}

type AddonClient

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

func (*AddonClient) Create

func (a *AddonClient) Create(opts *AddonCreateOpts) (addon *Addon, err error)

func (*AddonClient) Delete

func (a *AddonClient) Delete(addon *Addon) error

func (*AddonClient) Get

func (a *AddonClient) Get(id string) (addon *Addon, err error)

func (*AddonClient) Head added in v0.1.3

func (a *AddonClient) Head(id string) error

func (*AddonClient) List

func (a *AddonClient) List() (addons []*Addon, err error)

func (*AddonClient) Update

func (a *AddonClient) Update(id string, opts *AddonUpdateOpts) (addon *Addon, err error)

type AddonCreateOpts

type AddonCreateOpts struct {
	Name     string `json:"name"`
	Service  string `json:"service"`
	PlanID   string `json:"plan_id"`
	RegionID string `json:"region_id"`
	Release  string `json:"release"`
	Public   bool   `json:"public"`
}

type AddonService

type AddonService interface {
	Create(opts *AddonCreateOpts) (*Addon, error)
	Delete(addon *Addon) error
	Get(id string) (*Addon, error)
	Head(id string) error
	List() ([]*Addon, error)
	Update(id string, opts *AddonUpdateOpts) (*Addon, error)
}

type AddonUpdateOpts

type AddonUpdateOpts struct {
	PlanID  string `json:"plan_id"`
	Release string `json:"release"`
	Public  bool   `json:"public"`
}

type App

type App struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	Owner     *User     `json:"owner"`
	Region    *Region   `json:"region"`
	Status    string    `json:"status"`
	Hostname  string    `json:"hostname"`
	CreatedAt time.Time `json:"created_at"`
}

type AppClient

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

func (*AppClient) Create

func (a *AppClient) Create(opts *AppCreateOpts) (app *App, err error)

func (*AppClient) Delete

func (a *AppClient) Delete(app *App) error

func (*AppClient) Get

func (a *AppClient) Get(id string) (app *App, err error)

func (*AppClient) Head added in v0.1.3

func (a *AppClient) Head(id string) error

func (*AppClient) List

func (a *AppClient) List() (apps []*App, err error)

type AppCreateOpts

type AppCreateOpts struct {
	Name     string `json:"name"`
	RegionID string `json:"region_id"`
}

type AppService

type AppService interface {
	Create(opts *AppCreateOpts) (*App, error)
	Delete(app *App) error
	Get(id string) (*App, error)
	Head(id string) error
	List() ([]*App, error)
}

type Attachment

type Attachment struct {
	ID        int       `json:"id"`
	AppID     int       `json:"app_id"`
	AddonID   int       `json:"addon_id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

type AttachmentClient

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

func (*AttachmentClient) Create

func (a *AttachmentClient) Create(appID, addonID string, opts *AttachmentCreateOpts) (
	attachments []*Attachment, err error)

func (*AttachmentClient) Delete

func (a *AttachmentClient) Delete(appID, addonID string) error

func (*AttachmentClient) List

func (a *AttachmentClient) List(appID, addonID string) (attachments []*Attachment, err error)

type AttachmentCreateOpts

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

type AttachmentService

type AttachmentService interface {
	Create(appID, addonID string, opts *AttachmentCreateOpts) ([]*Attachment, error)
	Delete(appID, addonID string) error
	List(appID, addonID string) ([]*Attachment, error)
}

type Backup

type Backup struct {
	ID        int       `json:"id"`
	Type      string    `json:"type"`
	AddonID   int       `json:"addon_id"`
	Resource  string    `json:"resource"`
	SizeGB    int       `json:"size_gb"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}

type Client

type Client struct {
	Addon      AddonService
	App        AppService
	Attachment AttachmentService
	Container  ContainerService
	Domain     DomainService
	Env        EnvService
	Log        LogService
	Plan       PlanService
	Process    ProcessService
	Quota      QuotaService
	Region     RegionService
	Release    ReleaseService
	Service    ServiceService
	User       UserService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client) *Client

func (*Client) SetAPIURL

func (c *Client) SetAPIURL(apiURL string)

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

type ConnHandler

type ConnHandler func(net.Conn) error

type Container

type Container struct {
	ID        string    `json:"id"`
	AppID     int       `json:"app_id"`
	PlanID    string    `json:"plan_id"`
	Process   *Process  `json:"process"`
	Number    int       `json:"number"`
	CreatedAt time.Time `json:"created_at"`
}

type ContainerClient

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

func (*ContainerClient) List

func (c *ContainerClient) List(appID string) (containers []*Container, err error)

type ContainerService

type ContainerService interface {
	List(appID string) ([]*Container, error)
}

type Domain

type Domain struct {
	ID        int       `json:"id"`
	AppID     int       `json:"app_id"`
	Hostname  string    `json:"hostname"`
	CreatedAt time.Time `json:"created_at"`
}

type DomainClient

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

func (*DomainClient) Create

func (d *DomainClient) Create(appID string, opts *DomainCreateOpts) (domain *Domain, err error)

func (*DomainClient) Delete

func (d *DomainClient) Delete(domain *Domain) error

func (*DomainClient) Get

func (d *DomainClient) Get(appID, domainID string) (domain *Domain, err error)

func (*DomainClient) Head added in v0.1.3

func (d *DomainClient) Head(appID, domainID string) error

func (*DomainClient) List

func (d *DomainClient) List(appID string) (domains []*Domain, err error)

type DomainCreateOpts

type DomainCreateOpts struct {
	Hostname string `json:"hostname"`
}

type DomainService

type DomainService interface {
	Create(appID string, opts *DomainCreateOpts) (*Domain, error)
	Delete(domain *Domain) error
	Get(appID, domainID string) (*Domain, error)
	Head(appID, domainID string) error
	List(appID string) ([]*Domain, error)
}

type Env

type Env struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

type EnvClient

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

func (*EnvClient) List

func (e *EnvClient) List(appID string) (envs []*Env, err error)

func (*EnvClient) Set

func (e *EnvClient) Set(appID string, opts *EnvSetOpts) (envs []*Env, err error)

func (*EnvClient) Unset

func (e *EnvClient) Unset(appID string, opts *EnvUnsetOpts) error

type EnvService

type EnvService interface {
	List(appID string) ([]*Env, error)
	Set(appID string, opts *EnvSetOpts) ([]*Env, error)
	Unset(appID string, opts *EnvUnsetOpts) error
}

type EnvSetOpts

type EnvSetOpts struct {
	Envs []*Env `json:"envs"`
}

func (*EnvSetOpts) AddEnv

func (e *EnvSetOpts) AddEnv(name, value string)

type EnvUnsetOpts

type EnvUnsetOpts struct {
	Names []string `json:"names"`
}

type File

type File struct {
	Body io.Reader
	Name string
}

func GetTarFile

func GetTarFile() (*File, error)

type LogClient

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

func (*LogClient) AddonStream

func (l *LogClient) AddonStream(addonID string, opts *LogStreamOpts, handler LogHandler) error

func (*LogClient) AppStream

func (l *LogClient) AppStream(appID string, opts *LogStreamOpts, handler LogHandler) error

func (*LogClient) ReleaseStream

func (l *LogClient) ReleaseStream(release *Release, opts *LogStreamOpts, handler LogHandler) error

type LogEntry

type LogEntry struct {
	Line   string `json:"line"`
	Name   string `json:"name"`
	Source string `json:"source"`
}

type LogHandler

type LogHandler func(context.CancelFunc, *LogEntry)

type LogService

type LogService interface {
	AppStream(appID string, opts *LogStreamOpts, handler LogHandler) error
	AddonStream(addonID string, opts *LogStreamOpts, handler LogHandler) error
	ReleaseStream(release *Release, opts *LogStreamOpts, handler LogHandler) error
}

type LogStreamOpts

type LogStreamOpts struct {
	Follow bool      `qstring:"follow,omitempty"`
	Since  time.Time `qstring:"since,omitempty"`
	Tail   int       `qstring:"tail,omitempty"`
}

type Plan

type Plan struct {
	ID           string  `json:"id"`
	Cpu          int     `json:"cpu"`
	Ram          int     `json:"ram"`
	Disk         int     `json:"disk"`
	PriceHourly  float64 `json:"price_hourly"`
	PriceMonthly float64 `json:"price_monthly"`
}

type PlanClient

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

func (*PlanClient) Default added in v0.1.1

func (p *PlanClient) Default() (plan *Plan, err error)

func (*PlanClient) List

func (p *PlanClient) List() (plans []*Plan, err error)

func (*PlanClient) User added in v0.1.1

func (p *PlanClient) User(id string) (plans []*Plan, err error)

type PlanOpts added in v0.1.4

type PlanOpts struct {
	ID string `qstring:"id,omitempty"`
}

type PlanService

type PlanService interface {
	Default() (*Plan, error)
	List() ([]*Plan, error)
	User(id string) ([]*Plan, error)
}

type Process

type Process struct {
	ID        int       `json:"id"`
	Type      string    `json:"type"`
	AppID     int       `json:"app_id"`
	ReleaseID int       `json:"release_id"`
	PlanID    string    `json:"plan_id"`
	Command   string    `json:"command"`
	Count     int       `json:"count"`
	Number    int       `json:"number"`
	Replicas  int       `json:"replicas"`
	CreatedAt time.Time `json:"created_at"`
}

type ProcessClient

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

func (*ProcessClient) Attach

func (p *ProcessClient) Attach(appID string, number int, handler ConnHandler) error

func (*ProcessClient) Create

func (r *ProcessClient) Create(appID string, opts *ProcessCreateOpts) (process *Process, err error)

func (*ProcessClient) List

func (p *ProcessClient) List(appID string) (processes []*Process, err error)

func (*ProcessClient) Resize

func (p *ProcessClient) Resize(appID string, number int, opts *ProcessResizeOpts) error

func (*ProcessClient) Update

func (p *ProcessClient) Update(appID string, opts *ProcessUpdateOpts) (processes []*Process, err error)

type ProcessCreateOpts

type ProcessCreateOpts struct {
	PlanID  string `json:"plan_id"`
	Command string `json:"command"`
}

type ProcessResizeOpts

type ProcessResizeOpts struct {
	Height uint `json:"height"`
	Width  uint `json:"width"`
}

type ProcessService

type ProcessService interface {
	Attach(appID string, number int, handler ConnHandler) error
	Create(appID string, opts *ProcessCreateOpts) (*Process, error)
	List(appID string) ([]*Process, error)
	Resize(appID string, number int, opts *ProcessResizeOpts) error
	Update(appID string, opts *ProcessUpdateOpts) ([]*Process, error)
}

type ProcessUpdateOpts

type ProcessUpdateOpts struct {
	Processes []*Process `json:"processes"`
}

func (*ProcessUpdateOpts) AddProcess

func (p *ProcessUpdateOpts) AddProcess(ptype, planID string, replicas int)

type Quota added in v0.1.1

type Quota struct {
	ID     int    `json:"id"`
	PlanID string `json:"plan_id"`
	UserID int    `json:"user_id"`
	Quota  int    `json:"quota"`
}

type QuotaClient added in v0.1.1

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

func (*QuotaClient) Max added in v0.1.1

func (q *QuotaClient) Max() (quota *Quota, err error)

type QuotaService added in v0.1.1

type QuotaService interface {
	Max() (*Quota, error)
}

type Region

type Region struct {
	ID       string     `json:"id"`
	Name     string     `json:"name"`
	Country  string     `json:"country"`
	Location pgeo.Point `json:"location"`
}

type RegionClient

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

func (*RegionClient) List

func (r *RegionClient) List() (regions []*Region, err error)

type RegionService

type RegionService interface {
	List() ([]*Region, error)
}

type Release

type Release struct {
	ID        int       `json:"id"`
	Version   int       `json:"version"`
	AppID     int       `json:"app_id"`
	RepoID    int       `json:"repo_id"`
	Active    bool      `json:"active"`
	Branch    string    `json:"branch"`
	Commit    string    `json:"commit"`
	CreatedAt time.Time `json:"created_at"`
}

type ReleaseClient

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

func (*ReleaseClient) Create

func (r *ReleaseClient) Create(appID string, opts *ReleaseCreateOpts) (release *Release, err error)

func (*ReleaseClient) Latest

func (r *ReleaseClient) Latest(appID string) (release *Release, err error)

func (*ReleaseClient) List

func (r *ReleaseClient) List(appID string) (releases []*Release, err error)

type ReleaseCreateOpts

type ReleaseCreateOpts struct {
	Source *File `json:"source,omitnested"`
}

type ReleaseService

type ReleaseService interface {
	Create(appID string, opts *ReleaseCreateOpts) (*Release, error)
	Latest(appID string) (*Release, error)
	List(appID string) ([]*Release, error)
}

type Repo

type Repo struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	OwnerID   int       `json:"owner_id"`
	GitURL    string    `json:"git_url"`
	Tags      []string  `json:"tags"`
	CreatedAt time.Time `json:"created_at"`
}

type Service

type Service struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	Title     string    `json:"title"`
	Repo      *Repo     `json:"repo"`
	Connector string    `json:"connector"`
	Query     string    `json:"query"`
	CreatedAt time.Time `json:"created_at"`
}

type ServiceClient

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

func (*ServiceClient) Get

func (s *ServiceClient) Get(id string) (service *Service, err error)

func (*ServiceClient) List

func (s *ServiceClient) List() (services []*Service, err error)

type ServiceService

type ServiceService interface {
	Get(id string) (*Service, error)
	List() ([]*Service, error)
}

type User

type User struct {
	ID        int       `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Name      string    `json:"name"`
	RegionID  string    `json:"region_id"`
	CreatedAt time.Time `json:"created_at"`
}

type UserClient

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

func (*UserClient) Me added in v0.1.1

func (u *UserClient) Me() (user *User, err error)

type UserService

type UserService interface {
	Me() (*User, error)
}

Jump to

Keyboard shortcuts

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