status

package
v2.0.0-...-7abe87e Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package status is a handling status with code, msg, cause and stack.

Index

Constants

View Source
const (
	// OK status
	OK int32 = 0

	// UnknownError status
	UnknownError int32 = -1
)

Variables

This section is empty.

Functions

func Catch

func Catch(statPtr **Status, realStat ...*bool)

Catch recovers the panic and returns status. NOTE:

Set `realStat` to true if a `Status` type is recovered

Example:

var stat *Status
defer Catch(&stat)

func CatchWithStack

func CatchWithStack(statPtr **Status, realStat ...*bool)

CatchWithStack recovers the panic and returns status copy with stack. NOTE:

Set `realStat` to true if a `Status` type is recovered

Example:

var stat *Status
defer CatchWithStack(&stat)

func Check

func Check(err error, code int32, msg string, whenError ...func())

Check if err!=nil, create a status with stack, and panic. NOTE:

If err!=nil and msg=="", error text is set to msg

func Panic

func Panic(stat *Status)

Panic panic. TODO: remove

func Throw

func Throw(code int32, msg string, cause ...interface{})

Throw creates a status with stack, and panic.

func WrapError

func WrapError(cause interface{}, fields Map) error

WrapError wraps an error with fields. NOTE:

if cause==nil, return nil

Types

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type Map

type Map = map[string]interface{}

Map is alias of map[string]interface{} type.

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func GetStackTrace

func GetStackTrace(skip int) StackTrace

GetStackTrace gets the stack trace.

func PanicStackTrace

func PanicStackTrace() StackTrace

PanicStackTrace gets the panic stack trace.

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status a handling status with code, msg, cause and stack.

func FromJSON

func FromJSON(b []byte, tagStack bool) (*Status, error)

FromJSON parses the JSON bytes to a status object.

func FromQuery

func FromQuery(b []byte, tagStack bool) *Status

FromQuery parses the query bytes to a status object.

func New

func New(code int32, msg string, cause ...interface{}) *Status

New creates a handling status with code, msg and cause. NOTE:

code=0 means no error

func NewWithStack

func NewWithStack(code int32, msg string, cause ...interface{}) *Status

NewWithStack creates a handling status with code, msg and cause and stack. NOTE:

code=0 means no error

func (*Status) Cause

func (s *Status) Cause() error

Cause returns the cause of the status for debugging (optional). NOTE:

If s.OK() is false, the return value is never nil;
When empty, the msg is returned by default

func (*Status) Clear

func (s *Status) Clear()

Clear clears the status.

func (*Status) Code

func (s *Status) Code() int32

Code returns the status code.

func (*Status) Copy

func (s *Status) Copy(newCause interface{}, newStackSkip ...int) *Status

Copy returns the copy of Status.

func (*Status) DecodeQuery

func (s *Status) DecodeQuery(b []byte)

DecodeQuery parses the given b containing query args to the status object.

func (*Status) EncodeQuery

func (s *Status) EncodeQuery() []byte

EncodeQuery encodes the status object into query bytes.

func (*Status) Format

func (s *Status) Format(state fmt.State, verb rune)

Format formats the status object according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

func (*Status) JSONString

func (s *Status) JSONString() string

JSONString returns JSON string for the status object.

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

MarshalJSON marshals the status object into JSON, implements json.Marshaler interface.

func (*Status) Msg

func (s *Status) Msg() string

Msg returns the status msg displayed to the user (optional). NOTE:

When empty, the reason is returned by default

func (*Status) NewCheck

func (s *Status) NewCheck(err error, whenError ...func())

NewCheck if err!=nil, copies the status with stack, and panic.

func (*Status) NewThrow

func (s *Status) NewThrow(cause ...interface{})

NewThrow copies the status with stack, and panic.

func (*Status) OK

func (s *Status) OK() bool

OK returns whether is OK status (code=0).

func (*Status) QueryString

func (s *Status) QueryString() string

QueryString returns query string for the status object.

func (*Status) SetCause

func (s *Status) SetCause(cause interface{}) *Status

SetCause sets a new cause to the status object.

func (*Status) SetCode

func (s *Status) SetCode(code int32) *Status

SetCode sets a new code to the status object.

func (*Status) SetMsg

func (s *Status) SetMsg(msg string) *Status

SetMsg sets a new msg to the status object.

func (*Status) StackTrace

func (s *Status) StackTrace() StackTrace

StackTrace returns stack trace.

func (*Status) String

func (s *Status) String() string

String prints status info.

func (*Status) TagStack

func (s *Status) TagStack(skip ...int) *Status

TagStack marks stack information.

func (*Status) UnknownError

func (s *Status) UnknownError() bool

UnknownError returns whether is UnknownError status (code=-1).

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON description of self.

Jump to

Keyboard shortcuts

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