response

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 9 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildBy = time.Now()

BuildBy BuildBy

View Source
var DuplicateEntryKey, _ = regexp.Compile(
	`Duplicate entry '(.*)' for key '(.*)\.(.*)'`,
)

DuplicateEntryKey DuplicateEntryKey

View Source
var (
	ErrCodeTextArray = []ErrorCodeTextInterface{
		ErrorCodeText,
	}
)
View Source
var ErrorCodeText = ErrorCodeTextInterface{

	Success: "获取成功",
	Errors:  "遇到错误",

	LoginSuccess:  "登陆成功",
	StatusCreated: "添加成功",

	AuthedError:    "登陆超时",
	NotFound:       "没有数据",
	RepeatEmail:    "邮箱已存在",
	RepeatUserName: "用户名已存在",
	BindJSONErr:    "绑定失败,请检查参数",

	InvalidJSONData:  "JSON参数错误",
	InvalidFormData:  "Form参数错误",
	InvalidQueryData: "Url参数错误",

	NoRoute:  "路由不存在",
	NoMethod: "方法不存在",
}

ErrorCodeText 错误提示

View Source
var RecoverErrHtml = false

Functions

func Error added in v1.0.8

func Error(err interface{})

Error Error

func IsReqFromHTML added in v1.0.8

func IsReqFromHTML(c *gin.Context) bool

IsReqFromHTML ReqFromHtml

func LogError

func LogError(err interface{}, tips string)

LogError LogError

func PushErrCodeTextMap added in v1.0.8

func PushErrCodeTextMap(_map ErrorCodeTextInterface)

func Recover added in v1.0.8

func Recover(c *gin.Context)

Recover 使用defer调用阻止panic中止程序

func StatusText

func StatusText(code ErrCode) string

StatusText StatusText

Types

type ErrCode

type ErrCode int

ErrCode 错误码类型

const (

	// Errors 失败
	Errors ErrCode = -1
	// NoRoute NoRoute
	NoRoute ErrCode = http.StatusNotFound
	// NoMethod NoMethod
	NoMethod ErrCode = http.StatusMethodNotAllowed
)
const (
	// Success Success
	Success ErrCode = iota + 240
	// LoginSuccess 登陆成功
	LoginSuccess

	StatusCreated ErrCode = http.StatusCreated
)
const (
	// AuthedError 认证失败
	AuthedError ErrCode = -iota - 100
	// NotFound 没有数据
	NotFound
	// RepeatEmail 邮箱已存在
	RepeatEmail
	// RepeatUserName 用户名已存在
	RepeatUserName
	// BindJSONErr 绑定json失败
	BindJSONErr

	InvalidJSONData
	InvalidQueryData
	InvalidFormData
)

type ErrorCodeTextInterface added in v1.0.8

type ErrorCodeTextInterface map[ErrCode]string

type RecoverRenderType added in v1.0.21

type RecoverRenderType func(c *gin.Context, code int, result *Result)
var RecoverRender RecoverRenderType = func(c *gin.Context, code int, result *Result) {
	c.HTML(code, "err.html", result)
}

type Result

type Result struct {
	Code    ErrCode     `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	BuildBy time.Time   `json:"build_by"`
}

Result Result

func JSON

func JSON(code ErrCode, message string, data interface{}) Result

JSON JSON

func JSONError

func JSONError(message string, data interface{}) Result

JSONError JSONError

func JSONSuccess

func JSONSuccess(message string, data interface{}) Result

JSONSuccess 成功

func ParseError

func ParseError(r interface{}) Result

ParseError ParseError

Jump to

Keyboard shortcuts

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