winvps

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 9 Imported by: 0

README

winvps-go-client

A Winvps API client to interact with Winvps service

Test Status

Developer Documentation

The actual API Documentation available on this link.

Usage

import "github.com/fozzyhosting/winvps-go-client"

winClient, err := winvps.NewClient("token")
if err != nil {
  log.Fatalf("Failed to create client: %v", err)
}

machines, _, err := winClient.GetMachines()
Examples

The examples directory contains serveral examples of using this library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

Checks the API response for errors

Types

type AdditionalUser

type AdditionalUser struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Brand

type Brand struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Represens a brand info

type Client

type Client struct {
	UserAgent string
	// contains filtered or unexported fields
}

Represents api client

func NewClient

func NewClient(token string, opts ...Option) (*Client, error)

Creates a new instance of api client

func (*Client) AddMachineIP

func (c *Client) AddMachineIP(name string) (string, []*Job, error)

Add IP to specified machine returns new IP address and Jobs list

func (*Client) CancelJob

func (c *Client) CancelJob(id int) error

Cancel specified job

func (*Client) ChangeMachinePassword added in v1.0.1

func (c *Client) ChangeMachinePassword(name, pass string) (bool, error)

Change VPS machine password

func (*Client) CreateMachine

func (c *Client) CreateMachine(opt *CreateMachineOptions) (string, []*Job, error)

Create a new machine with specified CreateMachineOptions returns new machine name and Jobs list

func (*Client) DeleteMachine

func (c *Client) DeleteMachine(name string) ([]*Job, error)

Create machine deletion job

func (*Client) Do

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

Make an http request, check and parse response

func (*Client) GetBrands

func (c *Client) GetBrands(opts ...*RequestOptions) ([]*Brand, *Pagination, error)

Returns all available brands. Info from Pagination can be used to get brands using RequestOptions default Limit 50

func (*Client) GetJob

func (c *Client) GetJob(id int) (*Job, error)

Returns a single job info

func (*Client) GetJobs

func (c *Client) GetJobs(opts ...*RequestOptions) ([]*Job, *Pagination, error)

Returns all planned and completed jobs. Info from Pagination can be used to get jobs using RequestOptions default Limit 50

func (*Client) GetLocations

func (c *Client) GetLocations(opts ...*RequestOptions) ([]*Location, *Pagination, error)

Returns all available locations. Info from Pagination can be used to get locations using RequestOptions default Limit 50

func (*Client) GetMachine

func (c *Client) GetMachine(name string) (*MachineFull, error)

Return specific machine full info

func (*Client) GetMachineJobs

func (c *Client) GetMachineJobs(name string, opts ...*RequestOptions) ([]*Job, *Pagination, error)

Returns all jobs assigned to machine. Info from Pagination can be used to get jobs using RequestOptions default Limit 50

func (*Client) GetMachineUsers

func (c *Client) GetMachineUsers(name string, opts ...*RequestOptions) ([]*User, *Pagination, error)

Returns list of additional system users. Info from Pagination can be used to get users using RequestOptions default Limit 50

func (*Client) GetMachines

func (c *Client) GetMachines(opts ...*RequestOptions) ([]*Machine, *Pagination, error)

Returns all machines. Limit and Page can be set via RequestOptions default Limit 50

func (*Client) GetMachinesFull

func (c *Client) GetMachinesFull(opts ...*RequestOptions) ([]*MachineFull, *Pagination, error)

Returns all machines with full info. Info from Pagination can be used to get machines using RequestOptions default Limit 50

func (*Client) GetMachinesRunning

func (c *Client) GetMachinesRunning(opts ...*RequestOptions) ([]*Machine, *Pagination, error)

Returns all running machines. Info from Pagination can be used to get machines using RequestOptions default Limit 50

func (*Client) GetMachinesStopped

func (c *Client) GetMachinesStopped(opts ...*RequestOptions) ([]*Machine, *Pagination, error)

Returns all stopped machines. Info from Pagination can be used to get machines using RequestOptions default Limit 50

func (*Client) GetPendingJobs

func (c *Client) GetPendingJobs(opts ...*RequestOptions) ([]*Job, *Pagination, error)

Returns all planned jobs. Info from Pagination can be used to get jobs using RequestOptions default Limit 50

func (*Client) GetProducts

func (c *Client) GetProducts(opts ...*RequestOptions) ([]*Product, *Pagination, error)

Returns all available products. Info from Pagination can be used to get products using RequestOptions default Limit 50

func (*Client) GetTemplates

func (c *Client) GetTemplates(opts ...*RequestOptions) ([]*Template, *Pagination, error)

Returns all available templates. Info from Pagination can be used to get templates using RequestOptions default Limit 50

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, opt interface{}, opts []*RequestOptions) (*http.Request, error)

Creates and validates a new request sets required headers

func (*Client) ReinstallMachine

func (c *Client) ReinstallMachine(name string, opt *ReinstallMachineOptions) ([]*Job, error)

Reinstall machine with specified ReinstallMachineOptions

func (*Client) SendMachineCommand

func (c *Client) SendMachineCommand(name, command string) ([]*Job, error)

Send command to machine. Available commands is: start, stop, restart, enable_rdp, enable_network, restart_mt, run_updates_install

func (*Client) UpdateMachine

func (c *Client) UpdateMachine(name string, opt *UpdateMachineOptions) ([]*Job, error)

Update machine with specified UpdateMachineOptions

type CreateMachineOptions

type CreateMachineOptions struct {
	Description string `json:"description,omitempty"`
	Password    string `json:"password,omitempty"`
	ProductID   int    `json:"product_id,omitempty"`
	TemplateID  int    `json:"template_id,omitempty"`
	BrandID     int    `json:"brand_id,omitempty"`
	DiskType    string `json:"disk_type,omitempty"`
	LocationID  int    `json:"location_id,omitempty"`
	AddDisk     int    `json:"add_disk,omitempty"`
	AddRam      int    `json:"add_ram,omitempty"`
	AddCpu      int    `json:"add_cpu,omitempty"`
	AddBand     int    `json:"add_band,omitempty"`
	AutoStart   int    `json:"auto_start,omitempty"`
	AddIPv6     int    `json:"add_ipv6,omitempty"`
	UiLanguage  string `json:"ui_language,omitempty"`
}

List of available CreateMachine() options

func (*CreateMachineOptions) Validate

func (t *CreateMachineOptions) Validate() error

Validate CreateMachineOptions for required options

type IP

type IP struct {
	Version int    `json:"version"`
	Address string `json:"address"`
}

Represents an IP info

type Job

type Job struct {
	ID        int    `json:"id"`
	ParentID  int    `json:"parent_id"`
	MachineID int    `json:"machine_id"`
	Type      string `json:"type"`
	Status    string `json:"status"`
	StartTime string `json:"start_time"`
}

Represents a winvps job

type Limits

type Limits struct {
	CpuPercent int `json:"cpu_percent"`
	CpuCores   int `json:"cpu_cores"`
	RamMin     int `json:"ram_min"`
	RamMax     int `json:"ram_max"`
	DiskSize   int `json:"disk_size"`
	Bandwidth  int `json:"bandwidth"`
	Traffic    int `json:"traffic"`
}

Represents product limits

type Location

type Location struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Represents a location info

type Machine

type Machine struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Notes  string `json:"notes"`
}

Represents a winvps machine info

type MachineFull

type MachineFull struct {
	*Machine
	IPs    []*IP   `json:"ips"`
	OS     *OS     `json:"os"`
	Config *Limits `json:"config"`
}

Represents a full winvps machine info

type OS

type OS struct {
	TemplateID   string        `json:"template_id"`
	BrandID      int           `json:"brand_id"`
	UpdateStatus *UpdateStatus `json:"update_status"`
}

Represents a winvps OS info

type Option

type Option func(*Client) error

Represents option func for customize api client

func BaseURL

func BaseURL(baseURL string) Option

Set BaseURL for api client

type Pagination

type Pagination struct {
	Total int `json:"total"`
	Limit int `json:"limit"`
	Page  int `json:"page"`
	Pages int `json:"pages"`
}

Represents pagination info

func (*Pagination) NextPage

func (p *Pagination) NextPage() int

Method returns next page if available

func (*Pagination) PreviousPage

func (p *Pagination) PreviousPage() int

Method returns previous page if available

type Product

type Product struct {
	ID     int     `json:"id"`
	Name   string  `json:"name"`
	Limits *Limits `json:"limits"`
}

Represents a winvps product info

type ReinstallMachineOptions

type ReinstallMachineOptions struct {
	Password   string `json:"password,omitempty"`
	TemplateID int    `json:"template_id,omitempty"`
	BrandID    int    `json:"brand_id,omitempty"`
	AutoStart  int    `json:"auto_start,omitempty"`
}

List of available ReinstallMachine() options

type RequestOptions

type RequestOptions struct {
	Limit int `url:"limit,omitempty"`
	Page  int `url:"page,omitempty"`
}

Represents pagination options

type Response

type Response struct {
	Data       json.RawMessage `json:"data"`
	Pagination Pagination      `json:"pagination"`
	Error      string          `json:"error,omitempty"`
}

Represents api response

type Template

type Template struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Represents a winvps template

type UpdateMachineOptions

type UpdateMachineOptions struct {
	Password  string `json:"password,omitempty"`
	ProductID int    `json:"product_id,omitempty"`
	AddDisk   int    `json:"add_disk,omitempty"`
	AddRam    int    `json:"add_ram,omitempty"`
	AddCpu    int    `json:"add_cpu,omitempty"`
	AddBand   int    `json:"add_band,omitempty"`
}

List of available UpdateMachine() options

type UpdateStatus

type UpdateStatus struct {
	HResult        int    `json:"h_result"`
	RebootRequired bool   `json:"reboot_required"`
	ResultCode     int    `json:"result_code"`
	UpdateTime     string `json:"update_time"`
}

type User

type User struct {
	Username string `json:"username"`
	Role     string `json:"role"`
	Password string `json:"password"`
}

Represents a winvps user info

type Validator

type Validator interface {
	Validate() error
}

Used for validate request options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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