rest

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LinkedResourceUpdateErrorFormat = "" /* 285-byte string literal not displayed */
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptedAsyncResponse

type AcceptedAsyncResponse struct {
	Body     any
	Location string
	Scheme   string
}

AcceptedAsyncResponse represents an HTTP 202 with a JSON payload and location header.

This is used when a request to create an existing resource is processed asynchronously.

func (*AcceptedAsyncResponse) Apply

Apply renders Accepted HTTP Response into http.ResponseWriter with Location header for asynchronous operation and returns an error if it fails.

type AsyncOperationResponse

type AsyncOperationResponse struct {
	Body        any
	Location    string
	Code        int
	ResourceID  resources.ID
	OperationID uuid.UUID
	APIVersion  string
	RootScope   string // Everything before providers namespace for constructing an Async operation header. Used for AWS planes
	PathBase    string // Base Path. Used for AWS planes

	// RetryAfter is the value of the Retry-After header in seconds (as a string). This determines the client's polling interval.
	// Defaults to v1.DefaultRetryAfter. Consider setting a smaller value if your operation is expected to complete quickly.
	RetryAfter time.Duration
}

AsyncOperationResponse represents the response for an async operation request.

func NewAsyncOperationResponse

func NewAsyncOperationResponse(body any, location string, code int, resourceID resources.ID, operationID uuid.UUID, apiVersion string, rootScope string, pathBase string) *AsyncOperationResponse

NewAsyncOperationResponse creates an AsyncOperationResponse

func (*AsyncOperationResponse) Apply

Apply renders asynchronous operationStatuses response with Location/Azure-AsyncOperation URL headers and Retry-After header, which allows client to retry.

type AsyncOperationResultResponse

type AsyncOperationResultResponse struct {
	Headers map[string]string
}

AsyncOperationResultResponse

func (*AsyncOperationResultResponse) Apply

Apply sets the response headers and status code to http.StatusAccepted and returns nil.

type BadRequestResponse

type BadRequestResponse struct {
	Body v1.ErrorResponse
}

BadRequestResponse represents an HTTP 400 with an error message in ARM error format.

This is used for any operation that fails due to bad data with a simple error message.

func (*BadRequestResponse) Apply

Apply renders the general BadRequest HTTP response into http.ResponseWriter by serializing ErrorResponse.

type ClientAuthenticationFailed

type ClientAuthenticationFailed struct {
	Body v1.ErrorResponse
}

ClientAuthenticationFailed represents an HTTP 401 with an ARM error payload.

func (*ClientAuthenticationFailed) Apply

Apply writes a response with status code 401 Unauthorized and a JSON body to the response writer. It returns an error if there is an issue marshaling the body or writing it to the response writer.

type ConflictResponse

type ConflictResponse struct {
	Body v1.ErrorResponse
}

ConflictResponse represents an HTTP 409 with an ARM error payload.

This is used for delete operations.

func (*ConflictResponse) Apply

Apply renders 409 Conflict HTTP response into http.ResponseWriter by setting Content-Type and serializing response.

type CreatedAsyncResponse

type CreatedAsyncResponse struct {
	Body     any
	Location string
	Scheme   string
}

CreatedAsyncResponse represents an HTTP 201 with a JSON payload and location header.

This is used when a request to create a new resource is processed asynchronously.

func (*CreatedAsyncResponse) Apply

Apply renders Created HTTP Response into http.ResponseWriter with Location header for asynchronous operation and returns an error if it fails.

type CreatedResponse

type CreatedResponse struct {
	Body any
}

CreatedResponse represents an HTTP 201 with a JSON payload.

This is used when a request to create a new resource is processed synchronously.

func (*CreatedResponse) Apply

Apply renders CreatedResponse to http.ResponseWriter by serializing empty body and set 201 Created response code and returns an error if any of these steps fail.

type InternalServerErrorResponse

type InternalServerErrorResponse struct {
	Body v1.ErrorResponse
}

func (*InternalServerErrorResponse) Apply

Apply renders 500 InternalServerError HTTP response into http.ResponseWriter by setting Content-Type and serializing response.

type MethodNotAllowedResponse

type MethodNotAllowedResponse struct {
	Body v1.ErrorResponse
}

MethodNotAllowedResponse represents an HTTP 405 with an ARM error payload.

func (*MethodNotAllowedResponse) Apply

Apply renders a HTTP response by serializing Body in JSON and setting 405 response code and returns an error if it fails.

type NoContentResponse

type NoContentResponse struct {
}

NoContentResponse represents an HTTP 204.

This is used for delete operations.

func (*NoContentResponse) Apply

Apply renders NoContent HTTP Response into http.ResponseWriter.

type NotFoundResponse

type NotFoundResponse struct {
	Body v1.ErrorResponse
}

NotFoundResponse represents an HTTP 404 with an ARM error payload.

This is used for GET operations when the response does not exist.

func (*NotFoundResponse) Apply

Apply renders 404 NotFound HTTP response into http.ResponseWriter by setting Content-Type and serializing response.

type OKResponse

type OKResponse struct {
	Body    any
	Headers map[string]string
}

OKResponse represents an HTTP 200 with a JSON payload.

This is used when modification to an existing resource is processed synchronously.

func (*OKResponse) Apply

func (r *OKResponse) Apply(ctx context.Context, w http.ResponseWriter, req *http.Request) error

Apply sets the response headers and body, and writes the response to the http.ResponseWriter with a status code of 200. If an error occurs while marshaling the body or writing the response, an error is returned.

type PreconditionFailedResponse

type PreconditionFailedResponse struct {
	Body v1.ErrorResponse
}

PreconditionFailedResponse represents an HTTP 412 with an ARM error payload.

func (*PreconditionFailedResponse) Apply

Apply renders 412 PreconditionFailed HTTP response into http.ResponseWriter by setting Content-Type and serializing response.

type Response

type Response interface {
	// Apply modifies the ResponseWriter to send the desired details back to the client.
	Apply(ctx context.Context, w http.ResponseWriter, req *http.Request) error
}

Response represents a category of HTTP response (eg. OK with payload).

func NewAcceptedAsyncResponse

func NewAcceptedAsyncResponse(body any, location string, scheme string) Response

NewAcceptedAsyncResponse creates an AcceptedAsyncResponse

func NewAsyncOperationResultResponse

func NewAsyncOperationResultResponse(headers map[string]string) Response

NewAsyncOperationResultResponse creates a new AsyncOperationResultResponse with the given headers.

func NewBadRequestARMResponse

func NewBadRequestARMResponse(body v1.ErrorResponse) Response

NewBadRequestARMResponse creates a BadRequestResponse with error message.

func NewBadRequestResponse

func NewBadRequestResponse(message string) Response

NewBadRequestResponse creates a BadRequestResponse with a given error message.

func NewClientAuthenticationFailedARMResponse

func NewClientAuthenticationFailedARMResponse() Response

NewClientAuthenticationFailedARMResponse creates a ClientAuthenticationFailed Response with CodeInvalidAuthenticationInfo code and its message.

func NewConflictResponse

func NewConflictResponse(message string) Response

NewConflictResponse creates a ConflictResponse for conflicting operations and resources.

func NewCreatedAsyncResponse

func NewCreatedAsyncResponse(body any, location string, scheme string) Response

NewCreatedAsyncResponse creates a new HTTP Response for asynchronous operation.

func NewCreatedResponse

func NewCreatedResponse(body any) Response

NewCreatedResponse creates a Created HTTP Response object with the given data.

func NewDependencyMissingResponse

func NewDependencyMissingResponse(message string) Response

NewDependencyMissingResponse creates a DependencyMissingResponse with a given error message.

func NewInternalServerErrorARMResponse

func NewInternalServerErrorARMResponse(body v1.ErrorResponse) Response

NewInternalServerErrorARMResponse creates a new InternalServerErrorResponse with the given error message.

func NewLinkedResourceUpdateErrorResponse

func NewLinkedResourceUpdateErrorResponse(resourceID resources.ID, oldProp *rpv1.BasicResourceProperties, newProp *rpv1.BasicResourceProperties) Response

NewLinkedResourceUpdateErrorResponse represents a HTTP 400 with an error message when user updates environment id and application id.

func NewMethodNotAllowedResponse

func NewMethodNotAllowedResponse(target string, message string) Response

NewMethodNotAllowedResponse creates a MethodNotAllowedResponse with the given message and target resource.

func NewNoContentResponse

func NewNoContentResponse() Response

NewNoContentResponse creates a new NoContentResponse object.

func NewNotFoundAPIVersionResponse

func NewNotFoundAPIVersionResponse(resourceType string, namespace string, apiVersion string) Response

NewNotFoundAPIVersionResponse creates Response for unsupported api version. (message is consistent with ARM).

func NewNotFoundMessageResponse

func NewNotFoundMessageResponse(message string) Response

NewNotFoundMessageResponse represents an HTTP 404 with string message.

func NewNotFoundResponse

func NewNotFoundResponse(id resources.ID) Response

NewNotFoundResponse creates a NotFoundResponse with resource id.

func NewOKResponse

func NewOKResponse(body any) Response

NewOKResponse creates an OKResponse that will write a 200 OK with the provided body as JSON. Set the body to nil to write an empty 200 OK.

func NewOKResponseWithHeaders

func NewOKResponseWithHeaders(body any, headers map[string]string) Response

NewOKResponseWithHeaders creates an OKResponse that will write a 200 OK with the provided body as JSON. Set the body to nil to write an empty 200 OK.

func NewPreconditionFailedResponse

func NewPreconditionFailedResponse(target string, message string) Response

NewPreconditionFailedResponse creates a new PreconditionFailedResponse with the given target resource and message.

func NewValidationErrorResponse

func NewValidationErrorResponse(errors validator.ValidationErrors) Response

NewValidationErrorResponse creates a BadRequest response for invalid API validation.

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Body v1.ErrorResponse
}

ValidationErrorResponse represents an HTTP 400 with validation errors in ARM error format.

func (*ValidationErrorResponse) Apply

Apply renders BadRequest HTTP response into http.ResponseWriter by serializing invalid API validation error response and setting Content-Type.

Jump to

Keyboard shortcuts

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