go_hetzner_robot

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 10 Imported by: 2

README

go-hetzner-robot

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest submits an HTTP request.

func DoRequestWithClient

func DoRequestWithClient(
	ctx context.Context,
	client *http.Client,
	req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	// Services used for communicating with the API
	Server ServerService
	Order  OrderService
	// contains filtered or unexported fields
}

Client manages communication with Hetzner Robot API.

func New

func New(username, password string, httpClient *http.Client, opts ...ClientOpt) (*Client, error)

New returns a new Hetzner Robot API client instance.

func NewClient

func NewClient(username, password string, httpClient *http.Client) *Client

NewClient returns a new Hetzner Robot API client.

func (*Client) Do

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

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the Hetzner Robot API request completion callback

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"message"`

	// Error code
	Code string `json:"code"`

	// HTTP Status Code
	Status int `json:"status"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type OrderService

type OrderService interface {
	ListServerMarketProducts(context.Context, *ProductSearchRequest) ([]Product, *Response, error)
}

OrderService is an interface for interfacing with the order endpoints of the Hetzner Robot API See: https://robot.your-server.de/doc/webservice/en.html#get-order-server-product

type OrderServiceOp

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

OrderServiceOp handles communication with the order related methods of the Hetzner Robot API.

func (*OrderServiceOp) ListServerMarketProducts

func (s *OrderServiceOp) ListServerMarketProducts(ctx context.Context, opt *ProductSearchRequest) ([]Product, *Response, error)

ListServerMarketProducts returns a product overview of currently offered server market products

type Product

type Product struct {
	ID             int      `json:"id"`
	Name           string   `json:"name"`
	Description    []string `json:"description"`
	Traffic        string   `json:"traffic"`
	Dist           []string `json:"dist"`
	Arch           []int    `json:"arch"`
	Lang           []string `json:"lang"`
	CPU            string   `json:"cpu"`
	CPUBenchmark   int      `json:"cpu_benchmark"`
	MemorySize     int      `json:"memory_size"`
	HddSize        int      `json:"hdd_size"`
	HddText        string   `json:"hdd_text"`
	HddCount       int      `json:"hdd_count"`
	Datacenter     string   `json:"datacenter"`
	NetworkSpeed   string   `json:"network_speed"`
	Price          string   `json:"price"`
	PriceSetup     string   `json:"price_setup"`
	PriceVat       string   `json:"price_vat"`
	PriceSetupVat  string   `json:"price_setup_vat"`
	FixedPrice     bool     `json:"fixed_price"`
	NextReduce     int      `json:"next_reduce"`
	NextReduceDate string   `json:"next_reduce_date"`
}

Product represents a Hetzner Robot Product

type ProductSearchRequest

type ProductSearchRequest struct {
	// CPU model name
	CPU string `url:"cpu,omitempty"`
	// Minimum CPU benchmark value
	MinCPUBenchmark string `url:"min_cpu_benchmark,omitempty"`
	// Maximum CPU benchmark value
	MaxCPUBenchmark string `url:"max_cpu_benchmark,omitempty"`
	// Minimum memory size in GB
	MinMemorySize string `url:"min_memory_size,omitempty"`
	// Maximum memory size in GB
	MaxMemorySize string `url:"max_memory_size,omitempty"`
	// Minimum drive size in GB
	MinHDDSize string `url:"min_hdd_size,omitempty"`
	// Maximum drive size in GB
	MaxHDDSize string `url:"max_hdd_size,omitempty"`
	// Minimum drive count
	MinHDDCount string `url:"min_hdd_count,omitempty"`
	// Maximum drive count
	MaxHDDCount string `url:"max_hdd_count,omitempty"`
	// Full text search
	Search string `url:"search,omitempty"`
	// Minimum monthly price
	MinPrice string `url:"min_price,omitempty"`
	// Maximum monthly price
	MaxPrice string `url:"max_price,omitempty"`
}

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

type Response

type Response struct {
	*http.Response
}

Response is a Hetzner Robot response. This wraps the standard http.Response returned from Hetzner Robot.

type Server

type Server struct {
	ServerIP     string `json:"server_ip"`
	ServerNumber int    `json:"server_number"`
	ServerName   string `json:"server_name"`
	Product      string `json:"product"`
	Dc           string `json:"dc"`
	Traffic      string `json:"traffic"`
	Flatrate     bool   `json:"flatrate"`
	Status       string `json:"status"`
	Throttled    bool   `json:"throttled"`
	Cancelled    bool   `json:"cancelled"`
	PaidUntil    string `json:"paid_until"`
}

Server represents a Hetzner ordered Server

type ServerService

type ServerService interface {
	ListServers(context.Context) ([]Server, *Response, error)
}

ServerService is an interface for interfacing with the order endpoints of the Hetzner Robot API See: https://robot.your-server.de/doc/webservice/en.html#get-order-server-product

type ServerServiceOp

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

ServerServiceOp handles communication with the server related methods of the Hetzner Robot API.

func (*ServerServiceOp) ListServers

func (s *ServerServiceOp) ListServers(ctx context.Context) ([]Server, *Response, error)

ListServers queries data of all servers

Jump to

Keyboard shortcuts

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