Documentation
¶
Index ¶
- Variables
- func FromJson[T interface{}](response *http.Response) (*T, error)
- func IsPointer(value interface{}) bool
- type ApiError
- type Client
- type Credential
- type ErrorMapping
- type Exception
- type HttpMethod
- type RequestBuilder
- 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 RequestHeaders
- func (r *RequestHeaders) Add(key string, value string, additionalValues ...string)
- func (r *RequestHeaders) AddAll(other *RequestHeaders)
- func (r *RequestHeaders) Clear()
- func (r *RequestHeaders) ContainsKey(key string) bool
- func (r *RequestHeaders) Get(key string) []string
- func (r *RequestHeaders) ListKeys() []string
- func (r *RequestHeaders) Remove(key string)
- func (r *RequestHeaders) RemoveValue(key string, value string)
- type RequestInformation
- 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)
- type RequestOption
- type RequestOptionKey
- 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") )
Functions ¶
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 *RequestInformation, errorMapping ErrorMapping) (*http.Response, error)
}
type Credential ¶
type ErrorMapping ¶
ErrorMapping is a map that maps error codes to human-readable error messages.
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 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) 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 RequestHeaders ¶
type RequestHeaders struct {
// contains filtered or unexported fields
}
RequestHeaders represents a collection of request headers
func NewRequestHeaders ¶
func NewRequestHeaders() *RequestHeaders
NewRequestHeaders creates a new RequestHeaders
func (*RequestHeaders) AddAll ¶
func (r *RequestHeaders) AddAll(other *RequestHeaders)
AddAll adds all headers from the other headers
func (*RequestHeaders) ContainsKey ¶
ContainsKey check if the key exists in the headers
func (*RequestHeaders) ListKeys ¶
func (r *RequestHeaders) ListKeys() []string
ListKeys returns all the keys in the headers
func (*RequestHeaders) Remove ¶
func (r *RequestHeaders) Remove(key string)
Remove removes the specific header and all its values
func (*RequestHeaders) RemoveValue ¶
RemoveValue remove the value for the specific header
type RequestInformation ¶
type RequestInformation struct { // The HTTP method of the request. Method HttpMethod // The Request Headers. Headers *RequestHeaders // 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) 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.
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.