exception

package module
v0.0.0-...-a0d52fc Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: Apache-2.0 Imports: 6 Imported by: 13

README

exception

对异常定义的封装

Documentation

Overview

Package exception ...

Description : exception ...

Author : go_developer@163.com<白茶清欢>

Date : 2022-06-25 21:11

Package exception ...

Description : exception ...

Author : go_developer@163.com<白茶清欢>

Date : 2022-06-25 21:03

Package exception ...

Description : exception ...

Author : go_developer@163.com<白茶清欢>

Date : 2023-06-09 15:54

Package exception ...

Description : exception ...

Author : go_developer@163.com<白茶清欢>

Date *: 2022-06-25 21:04

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCodeTable

func GetCodeTable() map[any]Code

GetCodeTable ...

Author : go_developer@163.com<白茶清欢>

Date : 18:05 2023/6/9

func GetMessage

func GetMessage(code any, defaultMessage ...string) string

GetMessage 根据code获取文案

Author : go_developer@163.com<白茶清欢>

Date : 21:16 2022/6/25

func InitCodeTableWithCodeList

func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode any, convertDefaultLanguage string)

InitCodeTableWithCodeList 按照code列表初始化

Author : go_developer@163.com<白茶清欢>

Date : 16:19 2023/6/9

func InitCodeTableWithMessage

func InitCodeTableWithMessage(table map[any]map[string]string, convertDefaultSuccessCode any, convertDefaultLanguage string)

InitCodeTableWithMessage 初始化码表, 同时只指定代表业务成功的状态码以及使用的语言

Author : go_developer@163.com<白茶清欢>

Date : 20:55 2022/6/25

func IsSuccess

func IsSuccess(e *Exception) bool

IsSuccess 判断一个异常是否为成功

Author : go_developer@163.com<白茶清欢>

Date : 21:34 2022/6/25

func MessageWithoutCode

func MessageWithoutCode()

MessageWithoutCode 关闭在文案后追加状态码

Author : go_developer@163.com<白茶清欢>

Date : 21:15 2022/6/25

Types

type Code

type Code struct {
	Value   any               `json:"value"`   // 状态码的值
	Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述)
	Reason  map[string]string `json:"reason"`  // 产生此错误码的原因描述(key -> 语言 , value -> 对应语言的原因列表)
	Resolve map[string]string `json:"resolve"` // 解决此错误码的方案描述(key -> 语言 , value -> 对应语言的方案列表)
}

Code 状态码的结构

Author : go_developer@163.com<白茶清欢>

Date : 15:55 2023/6/9

func GetCodeList

func GetCodeList() []Code

GetCodeList ...

Author : go_developer@163.com<白茶清欢>

Date : 18:04 2023/6/9

type Exception

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

Exception 异常接口的具体实现

Author : go_developer@163.com<白茶清欢>

Date *: 21:09 2022/6/25

func (*Exception) Code

func (e *Exception) Code() any

func (*Exception) Data

func (e *Exception) Data() any

func (*Exception) Error

func (e *Exception) Error() string

func (*Exception) GetStack

func (e *Exception) GetStack() string

func (*Exception) IsCode

func (e *Exception) IsCode(inputCode any) bool

IsCode 判断是否为指定错误码

Author : go_developer@163.com<白茶清欢>

Date : 00:39 2023/9/28

func (*Exception) Message

func (e *Exception) Message() string

func (*Exception) ToError

func (e *Exception) ToError() error

type IException

type IException interface {
	// Error 兼容 go 内置 error
	Error() string
	// Code 获取错误码
	Code() any
	// Message 获取错误信息
	Message() string
	// Data 获取异常时的返回数据
	Data() any
	// ToError 转换为内置error类型
	ToError() error
	// IsCode 是否为指定code
	IsCode(code any) bool
	// GetStack 获取调用堆栈
	GetStack() string
}

IException 异常的接口定义

Author : go_developer@163.com<白茶清欢>

Date *: 21:05 2022/6/25

func New

func New(code any, data any, defaultMessage ...string) IException

New 获取异常实例

Author : go_developer@163.com<白茶清欢>

Date : 21:28 2022/6/25

func NewFromError

func NewFromError(code any, err error) IException

NewFromError 从error转换为Exception

Author : go_developer@163.com<白茶清欢>

Date : 21:36 2022/6/25

func NewFromMessage

func NewFromMessage(code any, message string) IException

NewFromMessage 从 code message 生成exception

Author : go_developer@163.com<白茶清欢>

Date : 22:25 2023/2/11

func NewSuccess

func NewSuccess(data any) IException

NewSuccess 代表Success的异常

Author : go_developer@163.com<白茶清欢>

Date : 22:35 2022/6/25

func NewWithCode

func NewWithCode(code any) IException

NewWithCode 仅使用错误码实例化异常

Author : go_developer@163.com<白茶清欢>

Date : 21:22 2022/6/25

func NewWithCodeAndData

func NewWithCodeAndData(code any, data map[string]any) IException

NewWithCodeAndData 使用 code + data 获取异常实例

Author : go_developer@163.com<白茶清欢>

Date : 21:28 2022/6/25

Jump to

Keyboard shortcuts

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