app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// original context
	context.Context
}

Context carries the context of the current execution.

func FromContext

func FromContext(ctx context.Context) Context

FromContext returns a new Context from a context.Context

func (*Context) SetTenantID

func (sc *Context) SetTenantID(tenantID string) *Context

SetTenantID sets the user id

func (*Context) SetTraceID

func (sc *Context) SetTraceID(traceID string) *Context

SetTraceID sets the trace id

func (*Context) SetUserID

func (sc *Context) SetUserID(userID string) *Context

SetUserID sets the user id

func (*Context) TenantID

func (sc *Context) TenantID() (string, bool)

TenantID returns the tenant id

func (*Context) TraceID

func (sc *Context) TraceID() string

TraceID returns the trace identifier for the current flow. If not present, it will generate a new UUID.V4 as traceID.

func (*Context) UserID

func (sc *Context) UserID() (string, bool)

UserID returns the user id

type ContextKey

type ContextKey string
const (
	TraceIDKey  ContextKey = "trace_id"
	UserIDKey   ContextKey = "user_id"
	TenantIDKey ContextKey = "tenant_id"
)

type Error

type Error struct {
	// contains filtered or unexported fields
}

Application Error

func NewError

func NewError(code string, errType ErrorType, severity ErrorSeverity, msg string) *Error

NewError creates a application new error

func NewErrorCancelled

func NewErrorCancelled(code string, msg string) *Error

NewErrorCancelled creates an error of type cancelled

func NewErrorConflict

func NewErrorConflict(code string, msg string) *Error

NewErrorConflict creates an error of type conflict

func NewErrorInternal

func NewErrorInternal(code string, msg string) *Error

NewErrorInternal creates an error of type internal

func NewErrorNotFound

func NewErrorNotFound(code string, msg string) *Error

NewErrorNotFound creates an error of type not found

func NewErrorPermission

func NewErrorPermission(code string, msg string) *Error

NewErrorPermission creates an error of type permission

func NewErrorTimeout

func NewErrorTimeout(code string, msg string) *Error

NewErrorTimeout creates an error of type timeout

func NewErrorUnauthorised

func NewErrorUnauthorised(code string, msg string) *Error

NewErrorUnauthorised creates an error of type unauthorised

func NewErrorValidation

func NewErrorValidation(code string, msg string) *Error

NewErrorValidation creates an error of type validation

func (*Error) AddValidationError

func (e *Error) AddValidationError(err FieldValidationError)

Add validation errors

func (Error) Cause

func (e Error) Cause() error

Get the original error cause

func (Error) Code

func (e Error) Code() string

Error code

func (Error) Detail

func (e Error) Detail() string

Get the error detail

func (Error) Error

func (e Error) Error() string

Error message

func (*Error) SetDetail

func (e *Error) SetDetail(detail string) *Error

Set the error detail

func (*Error) SetSeverity

func (e *Error) SetSeverity(severity ErrorSeverity) *Error

Set the original error severity

func (Error) Severity

func (e Error) Severity() ErrorSeverity

Get the error severity

func (Error) Type

func (e Error) Type() ErrorType

Error type

func (Error) ValidationErrors

func (e Error) ValidationErrors() FieldValidationErrors

Get validation errors

func (*Error) Wrap

func (e *Error) Wrap(err error) *Error

wrap the original error cause

type ErrorSeverity

type ErrorSeverity string

Error Severity

const (
	// ErrorSeverityLow - expected errors like validation
	ErrorSeverityLow ErrorSeverity = "low"
	// ErrorSeverityMedium - errors that are not urgent to look into.
	ErrorSeverityMedium ErrorSeverity = "medium"
	// ErrorSeverityHigh - errors that shouldn't happen but the system is still working.
	ErrorSeverityHigh ErrorSeverity = "high"
	// ErrorSeverityCritical - errors that impact the system from working.
	ErrorSeverityCritical ErrorSeverity = "critical"
)

type ErrorType

type ErrorType string

ErrorType defines the type of an error

const (
	// ErrorInternal error
	ErrorInternal ErrorType = "internal"
	// ErrorNotFound error
	ErrorNotFound ErrorType = "not_found"
	// ErrorValidation error
	ErrorValidation ErrorType = "validation"
	// ErrorPermission error
	ErrorPermission ErrorType = "permission"
	// ErrorUnauthorised error
	ErrorUnauthorised ErrorType = "unauthorised"
	// ErrorConflict error
	ErrorConflict ErrorType = "conflict"
	// ErrorTimeout error
	ErrorTimeout ErrorType = "timeout"
	// ErrorCancelled error
	ErrorCancelled ErrorType = "cancelled"
)

type FieldValidationError

type FieldValidationError struct {
	// contains filtered or unexported fields
}

func NewFieldValidationError

func NewFieldValidationError(identifier string, messages ...string) FieldValidationError

New Validation Error

type FieldValidationErrors

type FieldValidationErrors map[string][]string

Validation Error

Jump to

Keyboard shortcuts

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