gotransip

package module
v5.8.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 20 Imported by: 84

README

gotransip - TransIP API client for Go

Go Report Card Documentation

This is the Go client for the TransIP API. To use it you need an account with TransIP, enable API usage and setup a private API key.

NOTE: While the TransIP API's PHP client code is automatically generated, the Go client isn't. We try to follow the current PHP version as close as possible, but if something is not working 100% like you'd expect, please open an issue and of course: you're welcome to contribute!

Example usage

To print a list of your account's VPSes:

package main

import (
  "fmt"

  "github.com/transip/gotransip"
  "github.com/transip/gotransip/vps"
)

func main() {
  // create new TransIP API SOAP client
  c, err := gotransip.NewSOAPClient(gotransip.ClientConfig{
    AccountName: "accountname",
    PrivateKeyPath:  "/path/to/api/private.key"
  })
  if err != nil {
    panic(err.Error())
  }

  // get list of VPSes
  list, err := vps.GetVpses(c)
  if err != nil {
    panic(err.Error())
  }

  // print name and description for each VPS
  for _, v := range list {
    fmt.Printf("vps: %s (%s)\n", v.Name, v.Description)
  }
}

Documentation

For detailed descriptions of all functions, check out the TransIP API documentation. Details about the usage of the Go client can be found on godoc.org.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIMode

type APIMode string

APIMode specifies in which mode the API is used. Currently this is only supports either readonly or readwrite

var (
	// APIModeReadOnly specifies that no changes can be made from API calls
	APIModeReadOnly APIMode = "readonly"
	// APIModeReadWrite specifies that changes can be made from API calls
	APIModeReadWrite APIMode = "readwrite"
)

type CancellationTime

type CancellationTime string

CancellationTime represents the possible ways of canceling a contract

var (
	// CancellationTimeEnd specifies to cancel the contract when the contract was
	// due to end anyway
	CancellationTimeEnd CancellationTime = "end"
	// CancellationTimeImmediately specifies to cancel the contract immediately
	CancellationTimeImmediately CancellationTime = "immediately"
)

type Client

type Client interface {
	Call(SoapRequest, interface{}) error // execute request on client
}

Client is the interface which all clients should implement

type ClientConfig

type ClientConfig struct {
	AccountName    string
	PrivateKeyPath string
	PrivateKeyBody []byte
	Mode           APIMode
}

ClientConfig is a tool to easily create a new Client object

type FakeSOAPClient

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

FakeSOAPClient is a client doing nothing except implementing the gotransip.Client interface you can however set a fixture XML body which Call will try to Unmarshal into result useful for testing

func (FakeSOAPClient) Call

func (f FakeSOAPClient) Call(req SoapRequest, result interface{}) error

Call doesn't do anything except fill the XML unmarshalled result

func (*FakeSOAPClient) FixtureFromFile

func (f *FakeSOAPClient) FixtureFromFile(file string) (err error)

FixtureFromFile reads file and sets content as FakeSOAPClient's fixture

type ParamsContainer

type ParamsContainer interface {
	Len() int
	Add(string, interface{})
}

ParamsContainer is the interface a type should implement to be able to hold SOAP parameters

type SOAPClient

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

SOAPClient represents a TransIP API SOAP client, implementing the Client interface

func NewSOAPClient

func NewSOAPClient(c ClientConfig) (SOAPClient, error)

NewSOAPClient returns a new SOAPClient object for given config ClientConfig's PrivateKeyPath will override potentially given PrivateKeyBody

func (SOAPClient) Call

func (c SOAPClient) Call(req SoapRequest, result interface{}) error

Call performs given SOAP request and fills the response into result

type SoapRequest

type SoapRequest struct {
	Service string
	Method  string

	Padding []string
	// contains filtered or unexported fields
}

SoapRequest holds all information for perfoming a SOAP request Arguments to the request can be specified with AddArgument If padding is defined, the SOAP response will be parsed after it being padded with items in Padding in reverse order

func (*SoapRequest) AddArgument

func (sr *SoapRequest) AddArgument(key string, value interface{})

AddArgument adds an argument to the SoapRequest; the arguments ared used to fill the XML request body as well as to create a valid signature for the request

type TestParamsContainer

type TestParamsContainer struct {
	Prm string
}

TestParamsContainer is only useful for unit testing the ParamsContainer implementation of other type

func (*TestParamsContainer) Add

func (t *TestParamsContainer) Add(key string, value interface{})

Add just makes sure we use Len(), key and value in the result so it can be tested

func (TestParamsContainer) Len

func (t TestParamsContainer) Len() int

Len returns current length of test data in TestParamsContainer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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