exception

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

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

Go to latest
Published: Nov 5, 2023 License: Apache-2.0 Imports: 3 Imported by: 12

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[interface{}]Code

GetCodeTable ...

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

Date : 18:05 2023/6/9

func GetMessage

func GetMessage(code interface{}, defaultMessage ...string) string

GetMessage 获取消息信息

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

Date : 12:58 2022/6/26

func InitCodeTableWithCodeList

func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{}, convertDefaultLanguage string)

InitCodeTableWithCodeList 按照code列表初始化

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

Date : 16:19 2023/6/9

func InitCodeTableWithMessage

func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, 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

func ToError

func ToError(e *Exception) error

ToError 转换成内置error

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

Date : 21:37 2022/6/25

Types

type Code

type Code struct {
	Value   interface{}       `json:"value"`   // 状态码的值
	Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述)
	Reason  []*CodeReason     `json:"reason"`  // 产生此错误码的原因描述(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 CodeReason

type CodeReason struct {
	Reason   map[string]string   `json:"reason"`   // 错误原因: 语言 => 原因
	Solution map[string][]string `json:"solution"` // 解决步骤. 语言 => 解决步骤
}

CodeReason 错误码的原因

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

Date : 00:31 2023/11/5

type Exception

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

Exception 异常接口的具体实现

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

Date *: 21:09 2022/6/25

func (*Exception) Error

func (e *Exception) Error() string

func (*Exception) GetCode

func (e *Exception) GetCode() interface{}

func (*Exception) GetData

func (e *Exception) GetData() interface{}

func (*Exception) GetHttpCode

func (e *Exception) GetHttpCode() int

func (*Exception) GetMessage

func (e *Exception) GetMessage() string

func (*Exception) IsCode

func (e *Exception) IsCode(inputCode interface{}) bool

IsCode 判断是否为指定错误码

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

Date : 00:39 2023/9/28

func (*Exception) ToError

func (e *Exception) ToError() error

type IException

type IException interface {
	// Error 兼容 go 内置 error
	Error() string
	// GetCode 获取错误码
	GetCode() interface{}
	// GetMessage *获取错误信息
	GetMessage() string
	// GetData 获取异常时的返回数据
	GetData() interface{}
	// GetHttpCode 获取当前异常要返回的http状态码, 不设置则 默认 200
	GetHttpCode() int
	// ToError 转换为内置error类型
	ToError() error
	// IsCode 是否为指定code
	IsCode(code interface{}) bool
}

IException 异常的接口定义

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

Date *: 21:05 2022/6/25

func New

func New(code interface{}, httpCode int, data interface{}, defaultMessage ...string) IException

New 获取异常实例

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

Date : 21:28 2022/6/25

func NewFromError

func NewFromError(code interface{}, err error) IException

NewFromError 从error转换为Exception

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

Date : 21:36 2022/6/25

func NewFromMessage

func NewFromMessage(code interface{}, message string) IException

NewFromMessage 从 code message 生成exception

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

Date : 22:25 2023/2/11

func NewSuccess

func NewSuccess(data interface{}) IException

NewSuccess 代表Success的异常

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

Date : 22:35 2022/6/25

func NewWithCode

func NewWithCode(code interface{}) IException

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

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

Date : 21:22 2022/6/25

func NewWithCodeAndData

func NewWithCodeAndData(code interface{}, data interface{}) IException

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

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

Date : 21:28 2022/6/25

func NewWithCodeAndHttpCode

func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException

NewWithCodeAndHttpCode 使用 code + http_code 获取实例

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

Date : 21:25 2022/6/25

Jump to

Keyboard shortcuts

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