api

package
v0.0.0-...-908714d Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 3 Imported by: 0

README

/internal/api

This module provides common structures for REST API errors and response.

TODO: Write more details!!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code             APIErrorCode      `json:"code"`
	Message          string            `json:"message"`
	ValidationErrors validation.Errors `json:"validation_errors"`
}

func NewAPIError

func NewAPIError(code APIErrorCode, err error) *APIError

func NewAPIValidationError

func NewAPIValidationError(code APIErrorCode, valErrs validation.Errors) *APIError

func (*APIError) Error

func (err *APIError) Error() string

func (*APIError) GetHTTPStatusCode

func (err *APIError) GetHTTPStatusCode() int

type APIErrorCode

type APIErrorCode string
const (
	CodeBadRequest          APIErrorCode = "bad_request"
	CodeUnauthorized        APIErrorCode = "unauthorized"
	CodeForbidden           APIErrorCode = "forbidden"
	CodeNotFound            APIErrorCode = "not_found"
	CodeInternalServerError APIErrorCode = "internal_server_error"
	CodeValidationFailed    APIErrorCode = "validation_failed"
)

type APIResponse

type APIResponse struct {
	Error *APIError   `json:"error"`
	Data  interface{} `json:"data"`
}

func NewAPIResponse

func NewAPIResponse(err error, data interface{}) *APIResponse

type RequestValidator

type RequestValidator struct{}

func (*RequestValidator) Validate

func (*RequestValidator) Validate(i interface{}) error

Jump to

Keyboard shortcuts

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