api

package
v0.9.1-0...-2836688 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 6 Imported by: 31

Documentation

Overview

Package api groups packages simplifying Dynatrace API access.

Notably it contains the following packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON[T any](r Response) (T, error)

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 IsNotFoundError added in v0.9.0

func IsNotFoundError(err error) bool

func NewAPIErrorFromResponse added in v0.6.0

func NewAPIErrorFromResponse(resp *http.Response) error

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 NewAPIErrorFromResponseAndBody(resp *http.Response, body []byte) APIError

func (APIError) Error

func (r APIError) Error() string

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 (r APIError) Is4xxError() bool

func (APIError) Is5xxError added in v0.7.0

func (r APIError) Is5xxError() bool

type ClientError

type ClientError struct {
	// Wrapped is the original error returned by the rest.Client.
	Wrapped error

	// Identifier is an optional string used to uniquely identify
	// the resource or entity involved in the failed operation.
	Identifier string

	// Operation is the HTTP method (e.g., GET, POST, PUT, DELETE) http/method.go
	// used in the request that caused the error.
	Operation string

	// Resource specifies the Dynatrace API resource involved in the request,
	// such as "segments", "documents", etc.
	Resource string

	// Reason provides a human-readable explanation of why the error occurred.
	Reason string
}

ClientError represents a custom error type used in the client package to wrap errors returned by the rest.Client. It provides additional context such as the operation, resource, and reason for the error.

func (ClientError) Error

func (e ClientError) Error() string

func (ClientError) Unwrap

func (e ClientError) Unwrap() error

type ListResponse

type ListResponse struct {
	Response
	Objects [][]byte `json:"-"`
}

ListResponse represents a multi-object API response It contains both the full JSON Data, and a slice of Objects for more convenient access

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

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

func AsResponseOrError(httpResponse *http.Response, err error) (*Response, error)

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. Deprecated: To create new Response use NewResponseFromHTTPResponse

func NewResponseFromHTTPResponse added in v0.8.0

func NewResponseFromHTTPResponse(httpResponse *http.Response) (Response, error)

NewResponseFromHTTPResponse is a constructor which convert a http.Response to a Response. It ensures that the response body of http.Response 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 NewResponseFromHTTPResponseAndBody(resp *http.Response, body []byte) Response

type RuntimeError

type RuntimeError struct {
	// Wrapped is the original error that triggered this runtime failure.
	// It contains the low-level error details.
	Wrapped error

	// Resource is the name of the resource involved in the failed operation.
	// This helps identify which part of the system or API the error relates to.
	Resource string

	// Reason explains why the runtime assumption failed or what condition was not met.
	// This is useful for understanding the nature of the failure.
	Reason string

	// Identifier optionally provides a specific ID or key related to the resource.
	// If set, it will be included in the error message for more precise context.
	Identifier string
}

RuntimeError represents an error that occurs when the program makes assumptions about the structure or content of data returned from an API, which are required for constructing a valid follow-up request. It wraps the original error and provides additional context.

func (RuntimeError) Error

func (e RuntimeError) Error() string

func (RuntimeError) Unwrap

func (e RuntimeError) Unwrap() error

type ValidationError

type ValidationError struct {
	// Field is the name of the field that failed validation.
	Field string

	// Reason provides a human-readable explanation of why the validation failed.
	Reason string
}

ValidationError represents a client-side validation error that occurs during request construction. It is not an error returned from a validation endpoint of the API, but rather indicates that the request does not meet certain requirements before being sent.

func (ValidationError) Error

func (e ValidationError) Error() string

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL