Documentation
¶
Overview ¶
Package lwApi is a minimalist API client to LiquidWeb's (https://www.liquidweb.com) API:
https://cart.liquidweb.com/storm/api/docs/v1
https://cart.liquidweb.com/storm/api/docs/bleed
As you might have guessed from the above API documentation links, there are API versions: "v1" and "bleed". As the name suggests, if you always want the latest features and abilities, use "bleed". If you want long term compatibility (at the cost of being a little further behind sometimes), use "v1".
Index ¶
- type Client
- func (client *Client) Call(method string, params interface{}) (interface{}, error)
- func (client *Client) CallInto(method string, params interface{}, into LWAPIRes) error
- func (client *Client) CallIntoInterface(method string, params interface{}, into interface{}) error
- func (client *Client) CallRaw(method string, params interface{}) ([]byte, error)
- type LWAPIConfig
- type LWAPIError
- type LWAPIRes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
A Client holds the packages *LWAPIConfig and *http.Client. To get a *Client, call New.
func New ¶
func New(config *LWAPIConfig) (*Client, error)
New takes a *LWAPIConfig, and gives you a *Client. If there's an error, it is returned. When using this package, this should be the first function you call. Below is an example that demonstrates creating the config and passing it to New.
Example:
username := "ExampleUsername" password := "ExamplePassword" config := lwApi.LWAPIConfig{ Username: &username, Password: &password, Url: "api.liquidweb.com", } apiClient, newErr := lwApi.New(&config) if newErr != nil { panic(newErr) }
func (*Client) Call ¶
Call takes a path, such as "network/zone/details" and a params structure. It is recommended that the params be a map[string]interface{}, but you can use anything that serializes to the right json structure. A `interface{}` and an error are returned, in typical go fasion.
Example:
args := map[string]interface{}{ "uniq_id": "ABC123", } got, gotErr := apiClient.Call("bleed/asset/details", args) if gotErr != nil { panic(gotErr) }
func (*Client) CallInto ¶
CallInto is like call, but instead of returning an interface you pass it a struct which is filled, much like the json.Unmarshal function. The struct you pass must satisfy the LWAPIRes interface. If you embed the LWAPIError struct from this package into your struct, this will be taken care of for you.
Example:
type ZoneDetails struct { lwApi.LWAPIError AvlZone string `json:"availability_zone"` Desc string `json:"description"` GatewayDevs []string `json:"gateway_devices"` HvType string `json:"hv_type"` ID int `json:"id"` Legacy int `json:"legacy"` Name string `json:"name"` Status string `json:"status"` SourceHVs []string `json:"valid_source_hvs"` } var zone ZoneDetails err = apiClient.CallInto("network/zone/details", paramers, &zone) if err != nil { log.Fatal(err) } fmt.Printf("Got struct %#v\n", zone)
func (*Client) CallIntoInterface ¶
Similar to CallInto(), but populates an interface without needing to satisfy the LWAPIRes interface. Example:
type ZoneDetails struct { AvlZone string `json:"availability_zone"` Desc string `json:"description"` GatewayDevs []string `json:"gateway_devices"` HvType string `json:"hv_type"` ID int `json:"id"` Legacy int `json:"legacy"` Name string `json:"name"` Status string `json:"status"` SourceHVs []string `json:"valid_source_hvs"` } var zone ZoneDetails err = apiClient.CallIntoInterface("network/zone/details", params, &zone)
func (*Client) CallRaw ¶
CallRaw is just like Call, except it returns the raw json as a byte slice. However, in contrast to Call, CallRaw does *not* check the API response for LiquidWeb specific exceptions as defined in the type LWAPIError. As such, if calling this function directly, you must check for LiquidWeb specific exceptions yourself.
Example:
args := map[string]interface{}{ "uniq_id": "ABC123", } got, gotErr := apiClient.CallRaw("bleed/asset/details", args) if gotErr != nil { panic(gotErr) } // Check got now for LiquidWeb specific exceptions, as described above.
type LWAPIConfig ¶
type LWAPIConfig struct { Username *string Password *string Token *string Url string Timeout uint Insecure bool }
A LWAPIConfig holds the configuration details used to call the API with the client.
type LWAPIError ¶
type LWAPIError struct { ErrorMsg string `json:"error,omitempty"` ErrorClass string `json:"error_class,omitempty"` ErrorFullMsg string `json:"full_message,omitempty"` }
A LWAPIError is used to identify error responses when JSON unmarshalling json from a byte slice.
func (LWAPIError) Error ¶
func (e LWAPIError) Error() string
Given a LWAPIError, returns a string containing the ErrorClass and ErrorFullMsg.
func (LWAPIError) HadError ¶
func (e LWAPIError) HadError() bool
Given a LWAPIError, returns boolean if ErrorClass was present or not. You can use this function to determine if a LWAPIRes response indicates an error or not.