utils

package
v0.0.0-...-011315e Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildBy = time.Now()

BuildBy BuildBy

View Source
var ErrorCodeText = map[ErrCode]string{
	Success:      "获取成功",
	Errors:       "遇到错误",
	LoginSuccess: "登陆成功",
	AuthedError:  "登陆超时",
	NotFound:     "没有数据",
}

ErrorCodeText 错误提示

Functions

func GinRecover

func GinRecover(c *gin.Context)

GinRecover Recover

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes 随机字符串

func RegValidator

func RegValidator()

RegValidator 注册自定义验证器

func ReqFromHTML

func ReqFromHTML(c *gin.Context) bool

ReqFromHTML ReqFromHtml

func ShouldBindBodyWith

func ShouldBindBodyWith(c *gin.Context, obj interface{}, bb binding.BindingBody) (err error)

ShouldBindBodyWith is similar with ShouldBindWith, but it stores the request body into the context, and reuse when it is called again.

NOTE: This method reads the body before binding. So you should use ShouldBindWith for better performance if you need to call only once.

func StatusText

func StatusText(code ErrCode) string

StatusText StatusText

Types

type ErrCode

type ErrCode int

ErrCode 错误码类型

const (
	// Success Success
	Success ErrCode = 1
	// Errors 失败
	Errors ErrCode = -1
)
const (
	// AuthedError 认证失败
	AuthedError ErrCode = -iota - 100
	// NotFound 没有数据
	NotFound
)
const (
	// LoginSuccess 登陆成功
	LoginSuccess ErrCode = iota + 100
)

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime JSONTime

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON json格式化时间的方法

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan Scan

func (*JSONTime) ToDate

func (t *JSONTime) ToDate() string

ToDate ToDate

func (*JSONTime) ToString

func (t *JSONTime) ToString() string

ToString ToString

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(b []byte) error

UnmarshalJSON UnmarshalJSON

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value Value

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 成功

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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