Documentation ¶
Overview ¶
Package api groups packages simplifying Dynatrace API access.
Notably it contains the following packages
- github.com/dynatrace/dynatrace-configuration-as-code-core/api/rest containing an extended rest client with optional features like rate-limiting, request logging, etc.
- github.com/dynatrace/dynatrace-configuration-as-code-core/api/auth containing methods for creating authenticated rest clients
- github.com/dynatrace/dynatrace-configuration-as-code-core/api/clients containing client implementations for specific Dynatrace APIs
Index ¶
- func DecodeJSON[T any](r Response) (T, error)
- func DecodeJSONObjects[T any](r ListResponse) ([]T, error)
- func DecodePaginatedJSONObjects[T any](p PagedListResponse) ([]T, error)
- func NewAPIErrorFromResponse(resp *http.Response) error
- func NewRequestInfoFromRequest(request *http.Request) rest.RequestInfo
- type APIError
- type ListResponse
- type MultipartResponse
- type PagedListResponse
- type Part
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON tries to unmarshal the Response.Data of the given Response r into an object of T.
func DecodeJSONObjects ¶
func DecodeJSONObjects[T any](r ListResponse) ([]T, error)
DecodeJSONObjects unmarshalls Objects contained in the given ListResponse into a slice of T. To decode the full JSON response contained in ListResponse use Response.DecodeJSON.
func DecodePaginatedJSONObjects ¶ added in v0.2.0
func DecodePaginatedJSONObjects[T any](p PagedListResponse) ([]T, error)
DecodePaginatedJSONObjects unmarshalls all objects contained in the given PagedListResponse into a slice of T. Alternative ways to access data are to use PagedListResponse as a []ListResponse and decode each ListResponse or to access and decode the entries as []byte via PagedListResponse.All.
func NewAPIErrorFromResponse ¶ added in v0.6.0
func NewRequestInfoFromRequest ¶ added in v0.7.0
func NewRequestInfoFromRequest(request *http.Request) rest.RequestInfo
Types ¶
type APIError ¶
type APIError struct { StatusCode int `json:"statusCode"` // StatusCode is the HTTP response status code returned by the API. Body []byte `json:"body"` // Body is the HTTP payload returned by the API. Request rest.RequestInfo `json:"request"` // Request is information about the original request that led to this response error. }
APIError represents an error returned by an API with associated information.
func NewAPIErrorFromResponseAndBody ¶ added in v0.6.0
func (APIError) Error ¶
Error returns a string representation of the APIError, providing details about the failed API request. It includes the HTTP method, URL, status code, and response body.
Returns: - string: A string representing the error message.
func (APIError) Is4xxError ¶ added in v0.7.0
func (APIError) Is5xxError ¶ added in v0.7.0
type ListResponse ¶
ListResponse represents a multi-object API response It contains both the full JSON Data, and a slice of Objects for more convenient access
type MultipartResponse ¶ added in v0.6.0
type MultipartResponse struct { StatusCode int Parts []Part Request rest.RequestInfo }
MultipartResponse represent an HTTP multipart response. Each field part of a multipart content is in the map indexed with the name of the part.
func NewMultipartResponse ¶ added in v0.6.0
func NewMultipartResponse(resp *http.Response, parts ...Part) *MultipartResponse
func (*MultipartResponse) GetPartWithName ¶ added in v0.6.0
func (mr *MultipartResponse) GetPartWithName(name string) (Part, bool)
func (*MultipartResponse) IsSuccess ¶ added in v0.6.0
func (mr *MultipartResponse) IsSuccess() bool
type PagedListResponse ¶ added in v0.2.0
type PagedListResponse []ListResponse
PagedListResponse is a list of ListResponse values. It is used by return values of APIs that support pagination. Each ListResponse entry possibly contains multiple objects of the fetched resource type. To get all response objects in a single slice of []byte you can call All().
In case of any individual API request being unsuccessful, PagedListResponse will contain only that failed ListResponse.
func (PagedListResponse) All ¶ added in v0.2.0
func (p PagedListResponse) All() [][]byte
All returns all objects of a PagedListResponse in one slice
func (PagedListResponse) AsAPIError ¶ added in v0.2.0
func (p PagedListResponse) AsAPIError() (APIError, bool)
AsAPIError converts a PagedListResponse pointer to an APIError if it represents a 4xx or 5xx error. If the PagedListResponse does not represent an error, it returns an empty APIError and false. Unlike a normal Response, a PagedListResponse represents several individual API responses as a slice. In case of any response being unsuccessful, PagedListResponse will contain only that response by convention - this fact is used by this method.
Parameters: - [ (PagedListResponse): The PagedListResponse object to convert to an APIError.
Returns:
- (APIError, bool): An APIError containing error information and a boolean indicating whether the conversion was successful (true for errors, false otherwise).
type Response ¶
type Response struct { StatusCode int `json:"-"` Header http.Header Data []byte `json:"-"` Request rest.RequestInfo `json:"-"` }
Response represents an API response
func AsResponseOrError ¶ added in v0.7.0
AsResponseOrError is a helper function to convert an http.Response or error to a Response or error. It ensures that the response body is always read to completion and closed. Any non-successful (i.e. not 2xx) status code results in an APIError.
func NewResponseFromHTTPResponseAndBody ¶ added in v0.6.0
func (Response) AsAPIError ¶
AsAPIError converts a Response object to an APIError if it represents a 4xx or 5xx error. If the Response does not represent an error, it returns an empty APIError and false.
Parameters: - r (Response): The Response object to convert to an APIError.
Returns:
- (APIError, bool): An APIError containing error information and a boolean indicating whether the conversion was successful (true for errors, false otherwise).
func (Response) Is4xxError ¶
Is4xxError returns true if the response indicates a 4xx client error HTTP status code. A status code between 400 and 499 (inclusive) is considered a client error.
func (Response) Is5xxError ¶
Is5xxError returns true if the response indicates a 5xx server error HTTP status code. A status code between 500 and 599 (inclusive) is considered a server error.
Directories ¶
Path | Synopsis |
---|---|
Package auth simplifies creating token and oAuth authenticated http.Client for use with rest.Client
|
Package auth simplifies creating token and oAuth authenticated http.Client for use with rest.Client |
Package clients contains simple CRUD clients for the Dynatrace API.
|
Package clients contains simple CRUD clients for the Dynatrace API. |
automation
Package automation (api/clients/automation) provides a simple CRUD client for the Automations API.
|
Package automation (api/clients/automation) provides a simple CRUD client for the Automations API. |
buckets
Package buckets (api/clients/buckets) provides a simple CRUD client for the Grail Bucket API.
|
Package buckets (api/clients/buckets) provides a simple CRUD client for the Grail Bucket API. |
Package rest provides an extended rest.Client with optional behaviours like rate limiting, request/response logging, etc.
|
Package rest provides an extended rest.Client with optional behaviours like rate limiting, request/response logging, etc. |