Documentation
¶
Index ¶
- Variables
- func FromJson[T any](response *http.Response, v *T) error
- func IsPointer(value interface{}) bool
- func ParseResponse[T Response](response *http.Response, value *T) error
- func ToQueryMap(source interface{}) (map[string]string, error)
- type ApiError
- type Client
- type Credential
- type ErrorMapping
- type Exception
- type HttpMethod
- type IRequestInformation
- type RequestBuilder
- func (rB *RequestBuilder) SendDelete(params interface{}, errorMapping ErrorMapping) error
- func (rB *RequestBuilder) SendGet(params interface{}, errorMapping ErrorMapping, value Response) error
- func (rB *RequestBuilder) SendPost(data map[string]string, params interface{}, errorMapping ErrorMapping, ...) error
- func (rB *RequestBuilder) SendPut(data map[string]string, params interface{}, errorMapping ErrorMapping, ...) error
- func (rB *RequestBuilder) ToDeleteRequestInformation(params interface{}) (*RequestInformation, error)
- func (rB *RequestBuilder) ToGetRequestInformation(params interface{}) (*RequestInformation, error)
- func (rB *RequestBuilder) ToHeadRequestInformation() (*RequestInformation, error)
- func (rB *RequestBuilder) ToPostRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
- func (rB *RequestBuilder) ToPutRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
- func (rB *RequestBuilder) ToRequestInformation(method HttpMethod, data map[string]string, params interface{}) (*RequestInformation, error)
- type RequestInformation
- func (rI *RequestInformation) AddHeaders(rawHeaders interface{}) error
- func (rI *RequestInformation) AddQueryParameters(source interface{}) error
- func (rI *RequestInformation) AddRequestOptions(options []RequestOption)
- func (rI *RequestInformation) GetRequestOptions() []RequestOption
- func (rI *RequestInformation) SetStreamContent(content []byte)
- func (rI *RequestInformation) SetUri(url *url.URL)
- func (rI *RequestInformation) ToRequest() (*http.Request, error)
- func (rI *RequestInformation) ToRequestWithContext(ctx context.Context) (*http.Request, error)
- func (rI *RequestInformation) Url() (string, error)
- type RequestOption
- type RequestOptionKey
- type Response
- type ServiceNowError
- type UrlInformation
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyUri = errors.New("uri cannot be empty") ErrNilPathParameters = errors.New("uri template parameters cannot be nil") ErrNilQueryParamters = errors.New("uri query parameters cannot be nil") ErrMissingBasePathParam = errors.New("pathParameters must contain a value for \"baseurl\" for the URL to be built") ErrMissingBasePathTemplate = errors.New("template must contain a placeholder for \"{+baseurl}\" for the URL to be built") ErrInvalidHeaderType = errors.New("headers must be a pointer or an http.Header") ErrEmptyRawUrl = errors.New("empty raw URL") ErrMissingSchema = errors.New("URL is missing schema") ErrNilResponse = errors.New("Response is nil") )
Functions ¶
func ParseResponse ¶ added in v1.1.0
ParseResponse parses the HTTP Response to the provided type
func ToQueryMap ¶ added in v1.1.0
ToQueryMap converts a struct to query parameter map
Types ¶
type ApiError ¶
type ApiError struct { // Message is the human-readable error message. Message string // ResponseStatusCode is the HTTP response status code associated with the error. ResponseStatusCode int }
ApiError represents an error that occurs during API requests.
type Client ¶
type Client interface {
Send(requestInfo IRequestInformation, errorMapping ErrorMapping) (*http.Response, error)
}
type Credential ¶
type ErrorMapping ¶
ErrorMapping is a map that maps error codes to human-readable error messages.
func NewErrorMapping ¶ added in v1.1.0
func NewErrorMapping() ErrorMapping
NewErrorMapping creates a new instance of the ErrorMapping. It initializes an empty map to store error code to error message mappings.
func (ErrorMapping) Get ¶ added in v1.1.0
func (eM ErrorMapping) Get(code int) (string, bool)
Get retrieves the error message associated with the provided error code. It returns the error message along with a boolean indicating whether the error code was found. If the error code is not found, an empty string is returned along with `false`.
func (ErrorMapping) Len ¶ added in v1.1.0
func (eM ErrorMapping) Len() int
Len returns the number of error code to error message mappings in the ErrorMapping. It provides the total count of error mappings.
func (ErrorMapping) Set ¶ added in v1.1.0
func (eM ErrorMapping) Set(code, err string)
Set sets the error message for the specified error code. It associates the given error code with the provided error message in the mapping.
type Exception ¶
type Exception struct { // Detail is a detailed description of the exception. Detail string // Message is a brief description of the exception. Message string }
Exception represents an exception in the ServiceNow error response.
type HttpMethod ¶
type HttpMethod int
Represents the HTTP method used by a request.
const ( // The HTTP GET method. GET HttpMethod = iota // The HTTP POST method. POST // The HTTP PATCH method. PATCH // The HTTP DELETE method. DELETE // The HTTP OPTIONS method. OPTIONS // The HTTP CONNECT method. CONNECT // The HTTP PUT method. PUT // The HTTP TRACE method. TRACE // The HTTP HEAD method. HEAD )
func (HttpMethod) String ¶
func (m HttpMethod) String() string
String returns the string representation of the HTTP method.
type IRequestInformation ¶ added in v1.1.0
type IRequestInformation interface { AddRequestOptions(options []RequestOption) SetStreamContent(content []byte) AddQueryParameters(source interface{}) error SetUri(url *url.URL) Url() (string, error) ToRequest() (*http.Request, error) ToRequestWithContext(ctx context.Context) (*http.Request, error) AddHeaders(rawHeaders interface{}) error GetRequestOptions() []RequestOption }
type RequestBuilder ¶
type RequestBuilder struct { // PathParameters is a map of path parameters used in the URL template. PathParameters map[string]string // Client is an instance of the HTTP client used to send requests. Client Client // UrlTemplate is the URL template for constructing the request URL. UrlTemplate string }
RequestBuilder represents a builder for constructing HTTP request information.
func NewRequestBuilder ¶
func NewRequestBuilder(client Client, urlTemplate string, pathParameters map[string]string) *RequestBuilder
NewRequestBuilder creates a new instance of the RequestBuilder associated with the given URL and Client. It accepts the URL and Client as parameters and returns a pointer to the created RequestBuilder.
func (*RequestBuilder) SendDelete ¶ added in v1.1.0
func (rB *RequestBuilder) SendDelete(params interface{}, errorMapping ErrorMapping) error
func (*RequestBuilder) SendGet ¶ added in v1.1.0
func (rB *RequestBuilder) SendGet(params interface{}, errorMapping ErrorMapping, value Response) error
func (*RequestBuilder) SendPost ¶ added in v1.1.0
func (rB *RequestBuilder) SendPost(data map[string]string, params interface{}, errorMapping ErrorMapping, value Response) error
func (*RequestBuilder) SendPut ¶ added in v1.1.0
func (rB *RequestBuilder) SendPut(data map[string]string, params interface{}, errorMapping ErrorMapping, value Response) error
func (*RequestBuilder) ToDeleteRequestInformation ¶
func (rB *RequestBuilder) ToDeleteRequestInformation(params interface{}) (*RequestInformation, error)
ToDeleteRequestInformation creates a new HTTP DELETE request's RequestInformation object. It sets the HTTP method to DELETE and includes the specified query parameters.
Parameters:
- params: An interface representing query parameters for the DELETE request.
Returns:
- *RequestInformation: A RequestInformation object representing the DELETE request.
- error: An error if there was an issue creating the request information.
func (*RequestBuilder) ToGetRequestInformation ¶
func (rB *RequestBuilder) ToGetRequestInformation(params interface{}) (*RequestInformation, error)
ToGetRequestInformation creates a new HTTP GET request's RequestInformation object. It sets the HTTP method to GET and includes the specified query parameters.
Parameters:
- params: An interface representing query parameters for the GET request.
Returns:
- *RequestInformation: A RequestInformation object representing the GET request.
- error: An error if there was an issue creating the request information.
func (*RequestBuilder) ToHeadRequestInformation ¶
func (rB *RequestBuilder) ToHeadRequestInformation() (*RequestInformation, error)
ToHeadRequestInformation creates a new HTTP HEAD request's RequestInformation object. It sets the HTTP method to HEAD and includes no request data or query parameters.
Returns:
- *RequestInformation: A RequestInformation object representing the HEAD request.
- error: An error if there was an issue creating the request information.
func (*RequestBuilder) ToPostRequestInformation ¶
func (rB *RequestBuilder) ToPostRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
ToPostRequestInformation creates a new HTTP POST request's RequestInformation object. It sets the HTTP method to POST and includes the specified data in the request body and query parameters.
Parameters:
- data: A map[string]interface{} representing data to be included in the request body.
- params: An interface representing query parameters for the POST request.
Returns:
- *RequestInformation: A RequestInformation object representing the POST request.
- error: An error if there was an issue creating the request information.
func (*RequestBuilder) ToPutRequestInformation ¶
func (rB *RequestBuilder) ToPutRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
Put updates a table item using an HTTP PUT request. It takes a map of table entry data and optional query parameters to send in the request. The method returns a TableItemResponse representing the updated item or an error if the request fails.
Parameters:
- tableEntry: A map containing the data to update the table item.
- params: An optional pointer to TableItemRequestBuilderPutQueryParameters, which can be used to specify query parameters for the request.
Returns:
- *TableItemResponse: A TableItemResponse containing the updated item data.
- error: An error, if the request fails at any point, such as request information creation or JSON deserialization.
func (*RequestBuilder) ToRequestInformation ¶
func (rB *RequestBuilder) ToRequestInformation(method HttpMethod, data map[string]string, params interface{}) (*RequestInformation, error)
ToRequestInformation creates a new HTTP request's RequestInformation object with the specified HTTP method, data in the request body, and query parameters.
Parameters:
- method: The HTTP method for the request (e.g., "GET", "POST", "HEAD", "DELETE").
- data: A map[string]interface{} representing data to be included in the request body.
- params: An interface representing query parameters for the request.
Returns:
- *RequestInformation: A RequestInformation object representing the HTTP request.
- error: An error if there was an issue creating the request information.
type RequestInformation ¶
type RequestInformation struct { // The HTTP method of the request. Method HttpMethod // The Request Headers. Headers http.Header // The Request Body. Content []byte // contains filtered or unexported fields }
RequestInformation represents an abstract HTTP request.
func NewRequestInformation ¶
func NewRequestInformation() *RequestInformation
NewRequestInformation creates a new RequestInformation object with default values.
func (*RequestInformation) AddHeaders ¶ added in v1.1.0
func (rI *RequestInformation) AddHeaders(rawHeaders interface{}) error
func (*RequestInformation) AddQueryParameters ¶
func (rI *RequestInformation) AddQueryParameters(source interface{}) error
AddQueryParameters adds the query parameters to the request by reading the properties from the provided object.
func (*RequestInformation) AddRequestOptions ¶
func (rI *RequestInformation) AddRequestOptions(options []RequestOption)
AddRequestOptions adds an option to the request to be read by the middleware infrastructure.
func (*RequestInformation) GetRequestOptions ¶
func (rI *RequestInformation) GetRequestOptions() []RequestOption
GetRequestOptions returns the options for this request. Options are unique by type. If an option of the same type is added twice, the last one wins.
func (*RequestInformation) SetStreamContent ¶
func (rI *RequestInformation) SetStreamContent(content []byte)
SetStreamContent sets the request body to a binary stream.
func (*RequestInformation) SetUri ¶
func (rI *RequestInformation) SetUri(url *url.URL)
func (*RequestInformation) ToRequest ¶
func (rI *RequestInformation) ToRequest() (*http.Request, error)
ToRequest converts the RequestInformation object into an HTTP request.
func (*RequestInformation) ToRequestWithContext ¶
ToRequestWithContext converts the RequestInformation object into an HTTP request with context.
func (*RequestInformation) Url ¶ added in v1.1.0
func (rI *RequestInformation) Url() (string, error)
type RequestOption ¶
type RequestOption interface { // GetKey returns the key to store the current option under. GetKey() RequestOptionKey }
Represents a request option.
type RequestOptionKey ¶
type RequestOptionKey struct { // The unique key for the option. Key string }
RequestOptionKey represents a key to store a request option under.
type ServiceNowError ¶
type ServiceNowError struct { // Exception is the exception details in the error response. Exception Exception `json:"error"` // Status is the status of the error response. Status string }
ServiceNowError represents an error response from the ServiceNow API.
func (*ServiceNowError) Error ¶
func (e *ServiceNowError) Error() string
Error returns a formatted error message that includes both the exception message and detail.
type UrlInformation ¶
type UrlInformation struct { // The Query Parameters of the request. QueryParameters map[string]string // The path parameters to use for the URL template when generating the URI. PathParameters map[string]string // The Url template for the current request. UrlTemplate string }
UrlInformation represents an abstract Url.
func NewUrlInformation ¶
func NewUrlInformation() *UrlInformation
NewUrlInformation creates a new RequestUri object.
func (*UrlInformation) AddQueryParameters ¶
func (uI *UrlInformation) AddQueryParameters(source interface{}) error
AddQueryParameters adds the query parameters to the request by reading the properties from the provided object.