common

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".

func GenUUID

func GenUUID() string

func HasPrefixes

func HasPrefixes(src string, prefixes ...string) bool

HasPrefixes returns true if the string s has any of the given prefixes.

func Min added in v0.7.0

func Min(x, y int) int

func ValidateEmail added in v0.4.1

func ValidateEmail(email string) bool

ValidateEmail validates the email.

Types

type Code

type Code int

Code is the error code.

const (
	// 0 ~ 99 general error.
	Ok             Code = 0
	Internal       Code = 1
	NotAuthorized  Code = 2
	Invalid        Code = 3
	NotFound       Code = 4
	Conflict       Code = 5
	NotImplemented Code = 6
)

Application error codes.

func ErrorCode

func ErrorCode(err error) Code

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

type Error

type Error struct {
	// Machine-readable error code.
	Code Code

	// Embedded error.
	Err error
}

Error represents an application-specific error. Application errors can be unwrapped by the caller to extract out the code & message.

Any non-application error (such as a disk error) should be reported as an Internal error and the human user should only see "Internal error" as the message. These low-level internal error details should only be logged and reported to the operator of the application (not the end user).

func Errorf

func Errorf(code Code, err error) *Error

Errorf is a helper function to return an Error with a given code and error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

Jump to

Keyboard shortcuts

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