Documentation ¶
Index ¶
- func CallAPI(method, url string, content *[]byte, h ...string) (*http.Response, error)
- func CallGetAPI(url string, h ...string) (header http.Header, responseByteArr []byte, err error)
- func ContentTypeIsJSON(header http.Header) bool
- func Delete(url string, authenticator common.Authenticator) (err error)
- func DeleteWithTokenAndRequester(url string, token string, r requester.SendRequestFunction) (err error)
- func Get(url string, authenticator common.Authenticator) (*http.Response, error)
- func GetJSON(url string, authenticator common.Authenticator, val interface{}) (err error)
- func GetJSONWithTokenAndRequester(url string, token string, requester requester.SendRequestFunction, ...) (err error)
- func Head(url string, authenticator common.Authenticator) (*http.Response, error)
- func NewHTTPClient() *http.Client
- func PostJSON(url string, authenticator common.Authenticator, inputValue interface{}, ...) (err error)
- func PostJSONWithTokenAndRequester(url string, token string, requestor requester.SendRequestFunction, ...) (err error)
- func PutJSON(url string, authenticator common.Authenticator, inputValue interface{}, ...) (err error)
- func PutJSONWithTokenAndRequester(url string, token string, requestor requester.SendRequestFunction, ...) (err error)
- func Strcat(strs ...string) string
- func Transport(t *http.Transport) error
- type BoolWrapper
- type Float64Wrapper
- type HTTPStatus
- type Int64Wrapper
- type RFC8601DateTime
- func (r RFC8601DateTime) After(other RFC8601DateTime) bool
- func (r RFC8601DateTime) Before(other RFC8601DateTime) bool
- func (r RFC8601DateTime) Equal(other RFC8601DateTime) bool
- func (r RFC8601DateTime) MarshalJSON() ([]byte, error)
- func (r *RFC8601DateTime) Time() time.Time
- func (r *RFC8601DateTime) UnmarshalJSON(data []byte) error
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallAPI ¶
CallAPI sends an HTTP request using "method" to "url". For uploading / sending file, caller needs to set the "content". Otherwise, set it to zero length []byte. If Header fields need to be set, then set it in "h". "h" needs to be even numbered, i.e. pairs of field name and the field content.
fileContent, err := ioutil.ReadFile("fileName.ext");
resp, err := CallAPI("PUT", "http://domain/hello/", &fileContent, "Name", "world")
is similar to: curl -X PUT -H "Name: world" -T fileName.ext http://domain/hello/
func CallGetAPI ¶
CallGetAPI invokes HTTP GET request.
func ContentTypeIsJSON ¶
ContentTypeIsJSON determines if the content-type is application/json
func Delete ¶
func Delete(url string, authenticator common.Authenticator) (err error)
Delete sends an Http Request with using the "DELETE" method and with an "X-Auth-Token" header set to the specified token value. The request is made by the specified client.
func DeleteWithTokenAndRequester ¶
func DeleteWithTokenAndRequester(url string, token string, r requester.SendRequestFunction) (err error)
DeleteWithTokenAndRequester sends an Http Request with using the "DELETE" method and with an "X-Auth-Token" header set to the specified token value. The request is made by the specified client.
func Get ¶
Get sends an HTTP Request with using the "GET" method and with an "Accept" header set to "*/*" and the authentication token set to the specified token value. The request is made by the specified client. The response is a straight net/http.Response The caller is responsible for closing the response body!
func GetJSON ¶
func GetJSON(url string, authenticator common.Authenticator, val interface{}) (err error)
GetJSON sends an Http Request with using the "GET" method and with an "Accept" header set to "application/json" and the authentication token set to the specified token value. The request is made by the specified client. The val interface should be a pointer to the structure that the json response should be decoded into.
func GetJSONWithTokenAndRequester ¶
func GetJSONWithTokenAndRequester(url string, token string, requester requester.SendRequestFunction, val interface{}) (err error)
GetJSONWithTokenAndRequester sends an Http Request with using the "GET" method and with an "Accept" header set to "application/json" and the authentication token set to the specified token value. The request is made by the specified client. The val interface should be a pointer to the structure that the json response should be decoded into.
func Head ¶
Head sends an HTTP Request with using the "HEAD" method and with an "Accept" header set to "*/*" and the authentication token set to the specified token value. The request is made by the specified client. The response is a straight net/http.Response The caller is responsible for closing the response body!
func NewHTTPClient ¶
NewHTTPClient creates an HTTP client using our transport for SSL purposes.
func PostJSON ¶
func PostJSON(url string, authenticator common.Authenticator, inputValue interface{}, outputValue interface{}) (err error)
PostJSON sends an Http Request with using the "POST" method and with a "Content-Type" header with application/json and "X-Auth-Token" header if a value is specified. The inputValue is encoded to json and sent in the body of the request. The response json body is decoded into the outputValue. If the response does sends an invalid or error status code then an error will be returned.
func PostJSONWithTokenAndRequester ¶
func PostJSONWithTokenAndRequester(url string, token string, requestor requester.SendRequestFunction, inputValue interface{}, outputValue interface{}) (err error)
PostJSONWithTokenAndRequester sends an Http Request with using the "POST" method and with a "Content-Type" header with application/json and "X-Auth-Token" header if a value is specified. The inputValue is encoded to json and sent in the body of the request. The response json body is decoded into the outputValue. If the response does sends an invalid or error status code then an error will be returned.
func PutJSON ¶
func PutJSON(url string, authenticator common.Authenticator, inputValue interface{}, outputValue interface{}) (err error)
PutJSON sends an Http Request with using the "PUT" method and with a "Content-Type" header with application/json and X-Auth-Token" header set to the specified token value. The inputValue is encoded to json and sent in the body of the request. The response json body is decoded into the outputValue. If the response does sends a non 200 status code then an error will be returned.
func PutJSONWithTokenAndRequester ¶
func PutJSONWithTokenAndRequester(url string, token string, requestor requester.SendRequestFunction, inputValue interface{}, outputValue interface{}) (err error)
PutJSONWithTokenAndRequester sends an Http Request with using the "PUT" method and with a "Content-Type" header with application/json and X-Auth-Token" header set to the specified token value. The inputValue is encoded to json and sent in the body of the request. The response json body is decoded into the outputValue. If the response does sends a non 200 status code then an error will be returned.
func Strcat ¶
Strcat concatenates all input strings. Refer the following link for "Fastest string contatenation": http://golang-examples.tumblr.com/post/86169510884/fastest-string-contatenation
Types ¶
type BoolWrapper ¶
BoolWrapper is a wrapper type for dealing with inconsistent bool responses from OpenStack. In some cases, OpenStack will use "" to represent a null / non-existent boolean, as opposed to false or null. This is analogous to the NullBool type in the database/sql package.
func (BoolWrapper) MarshalJSON ¶
func (n BoolWrapper) MarshalJSON() ([]byte, error)
MarshalJSON converts a BoolWrapper to a []byte.
func (*BoolWrapper) UnmarshalJSON ¶
func (n *BoolWrapper) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the bytes to a BoolWrapper
func (BoolWrapper) Value ¶
func (n BoolWrapper) Value() (Value, error)
Value implements the driver Valuer interface.
type Float64Wrapper ¶
Float64Wrapper is a wrapper type for dealing with inconsistent float responses from OpenStack. In some cases, OpenStack will use "" to represent a null / non-existent float, as opposed to 0 or null. This is analogous to the NullFloat64 type in the database/sql package.
func (Float64Wrapper) MarshalJSON ¶
func (n Float64Wrapper) MarshalJSON() ([]byte, error)
MarshalJSON converts a Float64 wrapper to a []byte.
func (*Float64Wrapper) UnmarshalJSON ¶
func (n *Float64Wrapper) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the bytes to a Float64Wrapper
func (Float64Wrapper) Value ¶
func (n Float64Wrapper) Value() (Value, error)
Value implements the driver Valuer interface.
type HTTPStatus ¶
type HTTPStatus struct { StatusCode int Message string Header http.Header // contains filtered or unexported fields }
HTTPStatus is the error that that is returned when an error status code occurs. Allows developers to use this information in understanding the type of error that occurs for a particular request.
func CheckHTTPResponseStatusCode ¶
func CheckHTTPResponseStatusCode(resp *http.Response) (HTTPStatus, error)
CheckHTTPResponseStatusCode compares http response header StatusCode against expected statuses. Primary function is to ensure StatusCode is in the 20x (return nil). Ok: 200. Created: 201. Accepted: 202. No Content: 204. Otherwise return error message.
func NewHTTPStatus ¶
func NewHTTPStatus(response *http.Response, errorMessage string) HTTPStatus
NewHTTPStatus with specified values.
func (HTTPStatus) Error ¶
func (httpStatus HTTPStatus) Error() string
Error ensures that HTTPStatus implements the Error interface.
func (*HTTPStatus) GetBody ¶
func (httpStatus *HTTPStatus) GetBody() ([]byte, error)
GetBody gets the full body of the response.
type Int64Wrapper ¶
Int64Wrapper is a wrapper type for dealing with inconsistent integer responses from OpenStack. In some cases, OpenStack will use "" to represent a null / non-existent integer, as opposed to 0 or null. This is analogous to the NullInt64 type in the database/sql package.
func (Int64Wrapper) MarshalJSON ¶
func (n Int64Wrapper) MarshalJSON() ([]byte, error)
MarshalJSON converts a Int64 wrapper to a []byte.
func (*Int64Wrapper) UnmarshalJSON ¶
func (n *Int64Wrapper) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the bytes to a Int64Wrapper
func (*Int64Wrapper) Value ¶
func (n *Int64Wrapper) Value() (Value, error)
Value implements the driver Valuer interface.
type RFC8601DateTime ¶
type RFC8601DateTime struct {
// contains filtered or unexported fields
}
RFC8601DateTime is a type for decoding and encoding json date times that follow RFC 8601 format. The type currently decodes and encodes with exactly precision to seconds. If more formats of RFC8601 need to be supported additional work will be needed.
func NewDateTime ¶
func NewDateTime(input time.Time) RFC8601DateTime
NewDateTime creates a new RFC8601DateTime from a time.Time
func NewDateTimeFromString ¶
func NewDateTimeFromString(input string) (val RFC8601DateTime, err error)
NewDateTimeFromString creates a new RFC8601DateTime taking a string as input. It must follow the "2006-01-02T15:04:05" pattern.
func (RFC8601DateTime) After ¶
func (r RFC8601DateTime) After(other RFC8601DateTime) bool
After compares the DateTime to the other value and returns true if its after than the other value or false if not.
func (RFC8601DateTime) Before ¶
func (r RFC8601DateTime) Before(other RFC8601DateTime) bool
Before compares the DateTime to the other value and returns true if its before than the other value or false if not.
func (RFC8601DateTime) Equal ¶
func (r RFC8601DateTime) Equal(other RFC8601DateTime) bool
Equal compares the DateTime to the other value and returns true if its equal to the other value or false if not.
func (RFC8601DateTime) MarshalJSON ¶
func (r RFC8601DateTime) MarshalJSON() ([]byte, error)
MarshalJSON converts a RFC8601DateTime to a []byte.
func (*RFC8601DateTime) Time ¶
func (r *RFC8601DateTime) Time() time.Time
Time will return the embedded Time instance
func (*RFC8601DateTime) UnmarshalJSON ¶
func (r *RFC8601DateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the bytes give to a RFC8601DateTime Errors will occur if the bytes when converted to a string don't match the format "2006-01-02T15:04:05".