app

package
v0.0.0-...-15f6d77 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthStatusOK      = "ok"
	HealthStatusWarning = "warning"
	HealthStatusError   = "error"
)

Variables

View Source
var (
	ErrNoRecords = errors.New("no records")
)

Functions

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns if the provided error is related to no records found.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if the provided error is related to validation.

func WrappedErrors

func WrappedErrors(err error) []error

WrappedErrors returns the wrapped validation errors. If err is not a validation error, nil is returned.

Types

type Error

type Error struct {
	Msg string // Human-readable message.
	Err error  // Nested error.
}

Error defines a standard application error.

func NewError

func NewError(msg string, err error) *Error

NewError returns a pointer to app.Error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error string of the first wrapped error. It returns the human-readable message if the wrapped error is nil. If receiver is nil, an empty string is returned.

func (*Error) Message

func (e *Error) Message() string

Message returns the human-readable message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error. Go 1.13+ added two new functions, "errors.Is" and "errors.As" that call "Unwrap", if exists, to check whether any error in Err's chain matches target.

type Health

type Health struct {
	Name      string `json:"name"`
	Status    string `json:"status"` // ok|warning|error
	Core      bool   `json:"core"`   // true for core dependencies
	LatencyMs int64  `json:"latency_ms"`
	Data      struct {
		Message string `json:"message,omitempty"`
		Code    int    `json:"code,omitempty"` // remote HTTP status code
	} `json:"data"`
}

type User

type User struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

A User represents a user entity.

type UserRepository

type UserRepository interface {
	Ping(ctx context.Context) error
	FetchAll(ctx context.Context) ([]User, error)
	FetchByID(ctx context.Context, userID int) (*User, error)
	Add(ctx context.Context, name string) (int, error)
}

UserRepository should be implemented to get access to the data store.

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError defines a standard application error.

func (*ValidationError) Error

func (err *ValidationError) Error() string

Error returns the error field and message as a combined string.

Jump to

Keyboard shortcuts

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