Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth interface { ModifyRequest(request *Request) error ModifyHTTPRequest(httpReq *http.Request) error }
Auth is the interface needed for different ways to authenticate to the SoftLayer API
type BasicAuth ¶
type BasicAuth struct { // Username is the SoftLayer Username Username string // APIKey is the SoftLayer API key APIKey string }
BasicAuth will use HTTP basic auth to authenticate
func (BasicAuth) ModifyHTTPRequest ¶
ModifyHTTPRequest will add basic auth to the http.Request
func (BasicAuth) ModifyRequest ¶
ModifyRequest is noop for BasicAuth
type Client ¶
type Client struct { // Endpoint is the URL to the SoftLayer API Endpoint string // Auth is the authentication mechanism to use when making requests Auth Auth // HTTPClient is a golang HTTP client HTTPClient *http.Client // Debug is a flag which tells if request/response is logged Debug bool }
Client is the SoftLayer API Client
func (*Client) Call ¶
Call performs the API call. The result parameter will have the API response marshalled into it
Example (BasicAPICall) ¶
ExampleBasicAPICall demonstrates using a type provided by softlayer-go-gen
package main import ( "log" softlayer_account "github.com/sudorandom/softlayer-go-gen/methods/softlayer_account" gentypes "github.com/sudorandom/softlayer-go-gen/types" slapi "github.com/sudorandom/softlayer-go/slapi" ) var ( username = "INSERT_USERNAME" apiKey = "INSERT_API_KEY" ) func main() { client := slapi.Client{ Endpoint: "https://api.softlayer.com/rest/v3.1/", Auth: slapi.BasicAuth{Username: username, APIKey: apiKey}, } req := softlayer_account.GetObject() req.Mask = `mask[id,companyName]` // Make API call with basic account type basicAccount := &gentypes.SoftLayer_Account{} err := client.Call(req, basicAccount) if err != nil { log.Fatal(err) } log.Println("Basic:") log.Println(basicAccount.Id) log.Println(basicAccount.CompanyName) }
Output:
Example (CustomAPICall) ¶
ExampleCustomAPICall demonstrates using a user-defined type
package main import ( "log" softlayer_account "github.com/sudorandom/softlayer-go-gen/methods/softlayer_account" gentypes "github.com/sudorandom/softlayer-go-gen/types" slapi "github.com/sudorandom/softlayer-go/slapi" ) var ( username = "INSERT_USERNAME" apiKey = "INSERT_API_KEY" ) func main() { client := slapi.Client{ Endpoint: "https://api.softlayer.com/rest/v3.1/", Auth: slapi.BasicAuth{Username: username, APIKey: apiKey}, } req := softlayer_account.GetObject() req.Mask = `mask[id,virtualGuests,companyName]` // Make API call with a custom type, myCustomAccount type myCustomAccount struct { ID int64 `json:"id"` CompanyName string `json:"companyName"` VirtualGuests []*gentypes.SoftLayer_Virtual_Guest `json:"virtualGuests"` } customAccount := &myCustomAccount{} err := client.Call(req, customAccount) if err != nil { log.Fatal(err) } log.Println("Custom Extended:") log.Println(customAccount.ID) log.Println(customAccount.CompanyName) log.Println(customAccount.VirtualGuests) }
Output:
type Request ¶
type Request struct { // Service is the SoftLayer API service Service string // Method is the SoftLayer API method Method string // ID is the InitParameter for the request ID interface{} // Parameters are API parameters for the request Parameters []interface{} // Mask is the mask for the request Mask string // Filter is the filter for the request Filter map[string]interface{} // Limit is the result limit for the request Limit int // Offset is the result offset for the request Offset int // Headers is extra headers that can be used to mutate the request Headers map[string]interface{} }
Request holds request-level information
type SoftLayerAPIError ¶
type SoftLayerAPIError struct { // Error code Code string `json:"code"` // Error string String string `json:"error"` }
SoftLayerAPIError is an error returned when there's an error returned from the SoftLayer API
func (SoftLayerAPIError) Error ¶
func (err SoftLayerAPIError) Error() string
Error shows a nice error string