api

package
v0.0.0-...-66b7006 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PANIC            = "Panic"
	NotFound         = "NotFound"
	MethodNotAllowed = "MethodNotAllowed"

	InvalidJson      = "InvalidJson"
	JsonEncodeFailed = "JsonEncodeFailed"
	SystemError      = "SystemError"

	EncryptionFailed    = "EncryptionFailed"
	TokenCreationFailed = "TokenCreationFailed"

	AccountExists        = "AccountExists"
	UpdateFailed         = "UpdateFailed"
	AccountCreateFailed  = "AccountCreateFailed"
	ProfileCreateFailed  = "ProfileCreateFailed"
	EmailExistsInAccount = "EmailExistsInAccount"
	ProfileNotFound      = "ProfileNotFound"
	InvalidEmail         = "InvalidEmail"
	InvalidForgotToken   = "InvalidForgotToken"
	InvalidPassword      = "InvalidPassword"
	PasswordMismatch     = "PasswordMismatch"
	InvalidField         = "InvalidField"
	ProfileLocked        = "ProfileLocked"
	NotAuthorized        = "NotAuthorized"

	IncorrectPassword = "IncorrectPassword"
	InvalidToken      = "InvalidToken"
	TokenExpired      = "TokenExpired"
	MissingToken      = "MissingToken"

	ProfileInactive = "ProfileInactive"
	AccountInactive = "AccountInactive"

	MissingField = "MissingField"
	FieldSize    = "FieldSize"

	InvalidWeekStart = "InvalidWeekStart"
	InvalidRole      = "InvalidRole"
	InvalidTimezone  = "InvalidTimezone"

	InvalidClient  = "InvalidClient"
	InvalidTask    = "InvalidTask"
	InvalidProject = "InvalidProject"
)

Error Codes

View Source
const (
	SuccessStatus = "success"
	ErrorStatus   = "error"
)

Variables

This section is empty.

Functions

func BadInputs

func BadInputs(w http.ResponseWriter, message string, code string, field string)

func CloseBody

func CloseBody(body io.ReadCloser)

func ErrorJson

func ErrorJson(w http.ResponseWriter, e *Error, httpStatusCode int)

Writes an error JSON response

func Json

func Json(w http.ResponseWriter, r *http.Request, data interface{})

Writes a successful JSON response and marshals the value type as the data element

func JsonWithStatus

func JsonWithStatus(w http.ResponseWriter, r *http.Request, data interface{}, statusCode int)

Writes a JSON response with the given header status code and marshals the value type as the data element

func TimeJson

func TimeJson(t time.Time) string

Standard Time JSON format

func WarnJson

func WarnJson(w http.ResponseWriter, e *Error, httpStatusCode int)

Writes an error JSON response

Types

type Error

type Error struct {
	Err     error
	Message string
	Code    string
	Detail  map[string]interface{}
}

func NewError

func NewError(errorDetail interface{}, message string, code string, details ...ErrorDetail) *Error

Standardize the creation and reporting of errors using a generic Err type

func NewFieldError

func NewFieldError(errorDetail interface{}, message string, code string, field string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

func (*Error) String

func (e *Error) String() string

type ErrorDetail

type ErrorDetail struct {
	Key   string
	Value interface{}
}

func NewErrorDetail

func NewErrorDetail(key string, value interface{}) ErrorDetail

Jump to

Keyboard shortcuts

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