gcode

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package gcode provides universal error code definition and common error codes implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	CodeNil                       = newLocalCode(-1, "", nil)
	CodeOK                        = newLocalCode(0, "OK", nil)
	CodeInternalError             = newLocalCode(50, "Internal Error", nil)
	CodeValidationFailed          = newLocalCode(51, "Validation Failed", nil)
	CodeDbOperationError          = newLocalCode(52, "Database Operation Error", nil)
	CodeInvalidParameter          = newLocalCode(53, "Invalid Parameter", nil)
	CodeMissingParameter          = newLocalCode(54, "Missing Parameter", nil)
	CodeInvalidOperation          = newLocalCode(55, "Invalid Operation", nil)
	CodeInvalidConfiguration      = newLocalCode(56, "Invalid Configuration", nil)
	CodeMissingConfiguration      = newLocalCode(57, "Missing Configuration", nil)
	CodeNotImplemented            = newLocalCode(58, "Not Implemented", nil)
	CodeNotSupported              = newLocalCode(59, "Not Supported", nil)
	CodeOperationFailed           = newLocalCode(60, "Operation Failed", nil)
	CodeNotAuthorized             = newLocalCode(61, "Not Authorized", nil)
	CodeSecurityReason            = newLocalCode(62, "Security Reason", nil)
	CodeServerBusy                = newLocalCode(63, "Server Is Busy", nil)
	CodeUnknown                   = newLocalCode(64, "Unknown Error", nil)
	CodeNotFound                  = newLocalCode(65, "Not Found", nil)
	CodeInvalidRequest            = newLocalCode(66, "Invalid Request", nil)
	CodeNecessaryPackageNotImport = newLocalCode(67, "Necessary Package Not Import", nil)
	CodeInternalPanic             = newLocalCode(68, "Internal Panic", nil)
	CodeBusinessValidationFailed  = newLocalCode(300, "Business Validation Failed", nil)
)

Common error code definition. There are reserved internal error codes by framework: code < 1000.

Functions

func Release

func Release(c Code)

Release puts the Code back to the pool. It should be called when the Code is no longer needed.

Types

type Code

type Code interface {
	// Code returns the integer number of current error code.
	Code() int

	// Message returns the brief message for current error code.
	Message() string

	// Detail returns the detailed information of current error code,
	// which is mainly designed as an extension field for error code.
	Detail() interface{}
}

Code is universal error code interface definition.

func New

func New(code int, message string, detail interface{}) Code

New creates and returns an error code. Note that it returns an interface object of Code.

func WithCode

func WithCode(code Code, detail interface{}) Code

WithCode creates and returns a new error code based on given Code. The code and message is from given `code`, but the detail is from given `detail`.

Jump to

Keyboard shortcuts

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