apijuice

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 9 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(mandatoryQueryParams []*structcup.QueryParam, queryParams map[string][]string) error

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

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, msg string, 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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