common

package
v0.6.10 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnAuthenticated     = "E100"
	UnAuthorized        = "E101"
	BadRequest          = "E102"
	InternalServerError = "E103"
	ResourceNotFound    = "E104"
	UnknownError        = "E105"
)

Variables

This section is empty.

Functions

func ErrorMessage added in v0.4.24

func ErrorMessage(code string) string

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

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

type ErrorResponse struct {
	Code    string `json:"code,notnull" validate:"required"`
	Message string `json:"message,notnull" validate:"required"`
}

type Response

type Response struct {
	Code   int              `json:"code,omitempty"`
	Status string           `json:"status,omitempty"`
	Result interface{}      `json:"result,omitempty"`
	Errors []*util.ApiError `json:"errors,omitempty"`
}

global response body used across api

Jump to

Keyboard shortcuts

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