Documentation ¶
Index ¶
- Constants
- func ErrorMessage(code string) string
- func ExtractBoolQueryParam(r *http.Request, paramName string) (bool, error)
- func ExtractIntArrayFromQueryParam(r *http.Request, paramName string) ([]int, error)
- func ExtractIntArrayQueryParam(w http.ResponseWriter, r *http.Request, paramName string) ([]int, error)
- func ExtractIntPathParam(w http.ResponseWriter, r *http.Request, paramName string) (int, error)
- func ExtractIntQueryParam(w http.ResponseWriter, r *http.Request, paramName string, defaultValue int) (int, error)
- func WriteApiJsonResponse(w http.ResponseWriter, result interface{}, statusCode int, errCode string, ...)
- func WriteApiJsonResponseStructured(w http.ResponseWriter, apiResponse *ApiResponse, statusCode int)
- func WriteJsonResp(w http.ResponseWriter, err error, respBody interface{}, status int)
- func WriteOctetStreamResp(w http.ResponseWriter, r *http.Request, byteArr []byte, defaultFilename string)
- type ApiResponse
- type ErrorResponse
- type Response
Constants ¶
View Source
const ( UnAuthenticated = "E100" UnAuthorized = "E101" BadRequest = "E102" InternalServerError = "E103" ResourceNotFound = "E104" UnknownError = "E105" CONTENT_DISPOSITION = "Content-Disposition" CONTENT_TYPE = "Content-Type" CONTENT_LENGTH = "Content-Length" APPLICATION_JSON = "application/json" )
View Source
const TokenHeaderKey = "token"
Variables ¶
This section is empty.
Functions ¶
func ErrorMessage ¶ added in v0.4.24
func ExtractBoolQueryParam ¶ added in v0.7.2
func ExtractIntArrayFromQueryParam ¶ added in v0.7.2
ExtractIntArrayFromQueryParam returns list of all ids in []int extracted from query param use this method over ExtractIntArrayQueryParam if there is list of query params
func ExtractIntArrayQueryParam ¶ added in v0.7.0
func ExtractIntArrayQueryParam(w http.ResponseWriter, r *http.Request, paramName string) ([]int, error)
ExtractIntArrayQueryParam don't use this func, doesn't handle all cases to capture query params use ExtractIntArrayFromQueryParam over this func to capture int array from query param.
func ExtractIntPathParam ¶ added in v0.7.0
func ExtractIntQueryParam ¶ added in v0.7.0
func WriteApiJsonResponse ¶ added in v0.4.24
func WriteApiJsonResponse(w http.ResponseWriter, result interface{}, statusCode int, errCode string, errorMessage string)
func WriteApiJsonResponseStructured ¶ added in v0.4.24
func WriteApiJsonResponseStructured(w http.ResponseWriter, apiResponse *ApiResponse, statusCode int)
func WriteJsonResp ¶
func WriteJsonResp(w http.ResponseWriter, err error, respBody interface{}, status int)
use of writeJsonRespStructured is preferable. it api exists due to historical reason err.message is used as internal message for ApiError object in resp
func WriteOctetStreamResp ¶ added in v0.6.23
Types ¶
type ApiResponse ¶ added in v0.4.24
type ApiResponse struct { Success bool `json:"success,notnull" validate:"required"` Error *ErrorResponse `json:"error,omitempty"` Result interface{} `json:"result,omitempty"` }
type ErrorResponse ¶ added in v0.4.24
Click to show internal directories.
Click to hide internal directories.