apijuice

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package apijuice provides utility functions for writing HTTP responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMandatoryQueryParams added in v1.7.4

func CheckMandatoryQueryParams(queryParams map[string][]string, mandatoryQueryParams ...*structcup.QueryParam) error

CheckMandatoryQueryParams checks if the mandatory query parameters are present in the request.

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, errorCode int)

WriteErrorResponse writes an error response to the response writer with appropriate headers.

It does NOT return an error because it is used to write an error response.

Instead, if an error occurs internally, it writes the error to the response writer with http.Error.

func WriteGzipErrorResponse added in v1.7.6

func WriteGzipErrorResponse(w http.ResponseWriter, errorCode int)

WriteGzipErrorResponse writes an error response to the response writer with appropriate headers.

It does NOT return an error because it is used to write an error response.

Instead, if an error occurs internally, it writes the error to the response writer with http.Error.

This method does NOT check for the Accept-Encoding header.

This method overrides the Content-Length header with the length of the compressed data.

Use this method only if you are sure that the client can handle gzip compression.

func WriteGzipJSONResponse

func WriteGzipJSONResponse(w http.ResponseWriter, data interface{}, code int) error

WriteGzipJSONResponse compresses the JSON data and writes it to the response writer with appropriate headers.

The Content-Encoding header is set to gzip and the Content-Type header is set to application/json.

The Content-Length header is set with the length of the compressed data.

The status code is set based on the provided code parameter.

If the data cannot be serialized to JSON, an error is returned.

If the compressed data cannot be written to the response writer, an error is returned.

This method does NOT check for the Accept-Encoding header.

This method overrides the Content-Length header with the length of the compressed data.

Use this method only if you are sure that the client can handle gzip compression.

func WriteJSONResponse added in v1.7.6

func WriteJSONResponse(w http.ResponseWriter, data interface{}, code int) error

WriteJSONResponse writes the JSON data to the response writer with appropriate headers.

The Content-Type header is set to application/json.

The Content-Length header is set with the length of the uncompressed data.

The Content-Lenght is not set if the Content-Encoding header is set to gzip.

The status code is set based on the provided code parameter.

If the data cannot be serialized to JSON, an error is returned.

If the uncompressed data cannot be written to the response writer, an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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