common

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DevVersion = "0.4.1"

DevVersion is the service current development version.

View Source
var Version = "0.4.1"

Version is the service current released version. Semantic versioning: https://semver.org/

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 GetCurrentVersion added in v0.2.0

func GetCurrentVersion(mode string) string

func GetMinorVersion added in v0.2.0

func GetMinorVersion(version string) string

func HasPrefixes

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

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

func IsVersionGreaterOrEqualThan added in v0.2.0

func IsVersionGreaterOrEqualThan(version, target string) bool

IsVersionGreaterThanOrEqualTo returns true if version is greater than or equal to target.

func IsVersionGreaterThan added in v0.2.0

func IsVersionGreaterThan(version, target string) bool

IsVersionGreaterThan returns true if version is greater than target.

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