Documentation ¶
Index ¶
- Constants
- Variables
- func TranslateErrorToStatusCode(err error) int
- func ValidateStruct[Td any](dto *Td) error
- type BaseHttpResponse
- func GenerateBaseResponse(result any, success bool, resultCode ResultCode) *BaseHttpResponse
- func GenerateBaseResponseWithAnyError(result any, success bool, resultCode ResultCode, err any) *BaseHttpResponse
- func GenerateBaseResponseWithError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse
- func GenerateBaseResponseWithValidationError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse
- type ResultCode
- type ServiceError
- type ValidationError
Constants ¶
View Source
const ( // Token UnExpectedError = "unexpected error" ClaimsNotFound = "claims not found" TokenRequired = "token required" TokenExpired = "token expired" TokenInvalid = "token invalid" // User PermissionDenied = "Permission denied" // DB RecordNotFound = "record not found" )
Variables ¶
View Source
var StatusCodeMapping = map[string]int{ RecordNotFound: 400, }
Functions ¶
func ValidateStruct ¶
Types ¶
type BaseHttpResponse ¶
type BaseHttpResponse struct { Result any `json:"result"` Success bool `json:"success"` ResultCode ResultCode `json:"resultCode"` ValidationErrors *[]ValidationError `json:"validationErrors"` Error any `json:"error"` }
func GenerateBaseResponse ¶
func GenerateBaseResponse(result any, success bool, resultCode ResultCode) *BaseHttpResponse
func GenerateBaseResponseWithAnyError ¶
func GenerateBaseResponseWithAnyError(result any, success bool, resultCode ResultCode, err any) *BaseHttpResponse
func GenerateBaseResponseWithError ¶
func GenerateBaseResponseWithError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse
func GenerateBaseResponseWithValidationError ¶
func GenerateBaseResponseWithValidationError(result any, success bool, resultCode ResultCode, err error) *BaseHttpResponse
type ResultCode ¶
type ResultCode int
const ( Success ResultCode = 0 BadRequestError ResultCode = 40000 ValidationErrorCode ResultCode = 40001 NotFoundError ResultCode = 40401 CustomRecovery ResultCode = 50001 InternalError ResultCode = 50002 DBConnectionError ResultCode = 50003 )
type ServiceError ¶
type ServiceError struct { EndUserMessage string `json:"endUserMessage"` TechnicalMessage string `json:"technicalMessage"` Err error }
func (*ServiceError) Error ¶
func (s *ServiceError) Error() string
type ValidationError ¶
Click to show internal directories.
Click to hide internal directories.