common

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.1.3"

Version is the service current released version.

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.

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

	// 101 ~ 199 db error
	DbConnectionFailure    Code = 101
	DbStatementSyntaxError Code = 102
	DbExecutionError       Code = 103
)

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