Documentation
¶
Index ¶
- Variables
- func ErrorResponseJSON(w http.ResponseWriter, httpCode int, internalCode int, err error)
- func ResponseJSON(w http.ResponseWriter, v any)
- func SetCookieName(name string)
- func SuccessfulResultMap() map[string]any
- type ApiError
- type CreatedObjectId
- type InternalError
- type ListResult
- type Response
Constants ¶
This section is empty.
Variables ¶
var CookieName = "session"
CookieName is the name of the cookie used to store the session ID.
Functions ¶
func ErrorResponseJSON ¶
func ErrorResponseJSON(w http.ResponseWriter, httpCode int, internalCode int, err error)
ErrorResponseJSON sends error http response
func ResponseJSON ¶
func ResponseJSON(w http.ResponseWriter, v any)
ResponseJSON sends OK JSON response
func SetCookieName ¶
func SetCookieName(name string)
SetCookieName sets the name of the cookie used to store the session ID.
func SuccessfulResultMap ¶
SuccessfulResultMap returns a map with success flag set to true and default message.
Types ¶
type ApiError ¶
type ApiError struct {
HttpStatus int `json:"http_status,omitempty"`
ErrorCode int `json:"code"`
Message any `json:"message"`
Timestamp any `json:"timestamp"`
}
ApiError represents a structure for encoding API error responses in JSON format.
func NewApiErrFromInternalErr ¶
func NewApiErrFromInternalErr(e InternalError, code ...int) *ApiError
NewApiErrFromInternalErr creates and returns a new instance of ApiError based on an internal error. It sets the HTTP status code to the specified value or defaults to http.StatusBadRequest if not provided.
func NewApiError ¶
NewApiError creates and returns a new instance of ApiError with the specified error code and message. It automatically sets the timestamp to the current time in RFC1123 format.
type CreatedObjectId ¶
type CreatedObjectId struct {
Id any `json:"id,omitempty" yaml:"id,omitempty"`
UUID any `json:"uuid,omitempty" yaml:"uuid,omitempty"`
}
CreatedObjectId represents a structure for encoding the ID and UUID of a created entity.
type InternalError ¶
type ListResult ¶
type ListResult struct {
Results any `json:"results,omitempty" yaml:"results,omitempty"`
Count int32 `json:"count" yaml:"count"`
}
ListResult represents a structure for encoding API list of results in JSON format.
type Response ¶
type Response struct {
Success bool `json:"success" yaml:"success"`
Timestamp string `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Data any `json:"data,omitempty" yaml:"data,omitempty"`
CreatedObjectId
RequestStatus *ApiError `json:"request_status" yaml:"request_status,omitempty"`
}
Response represents a structure for encoding API responses in JSON format.
func SuccessfulResult ¶
func SuccessfulResult() Response
SuccessfulResult returns a Response instance with success flag set to true and default message.