common

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

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

Pangu-common

提供一些常用的工具类,如:日志、golang 集合工具类、gin 工具方法、统一返回结构体等等。

Documentation

Index

Constants

View Source
const (

	// CURD 常用业务状态码
	SuccessCode int    = 200
	SuccessMsg  string = "操作成功"

	ParameterVerificationError    int = 400
	ParameterVerificationErrorMsg     = "参数校验错误"

	SystemErrorCode int    = 500
	SystemErrorMsg  string = "系统错误"
)

Variables

View Source
var (
	SuccessResult        = NewResultError(200, "success")
	BizErrResult         = NewResultError(400, "biz error")
	MethodNotAllowResult = NewResultError(405, "method not allow")
	NotFoundResult       = NewResultError(404, "not found")
	ServerErrorResult    = NewResultError(500, "server error")
)
View Source
var (
	ErrorCode = map[int]string{
		SuccessCode: SuccessMsg,
	}
)

Functions

func ErrMsg

func ErrMsg(code int) string

Types

type MessageError

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

MessageError 自定义消息错误

func Error

func Error(err error) *MessageError

集中判断常见错误

func New

func New(code int) *MessageError

func NewMessageError

func NewMessageError(parent error, code int) *MessageError

func NewSecondMsg

func NewSecondMsg(parent error, code int, msg string) *MessageError

func (*MessageError) Code

func (m *MessageError) Code() int

func (*MessageError) Error

func (m *MessageError) Error() string

func (*MessageError) Parent

func (m *MessageError) Parent() error

func (*MessageError) SecondMsg

func (m *MessageError) SecondMsg() string

type Model

type Model struct {
	Id        int        `json:"id" gorm:"column:id; AUTO_INCREMENT;"`
	CreatedAt *time.Time `json:"createdAt" gorm:"column:created_at;type:datetime;not null;default:current_timestamp;comment:创建时间"`
	CreatedBy int        `json:"createdBy" gorm:"column:created_by;type:int; unsigned;not null;default:0"`
	UpdatedAt *time.Time `` /* 126-byte string literal not displayed */
	UpdatedBy int        `json:"updatedBy" gorm:"column:updated_by;type:int; unsigned;not null;default:0"`
}

type Page

type Page struct {
	Total   int64       `json:"total"`
	Current uint32      `json:"current"`
	Size    uint32      `json:"size"`
	Records interface{} `json:"records"`
	Desc    []string    `json:"desc"`
	Asc     []string    `json:"asc"`
	// contains filtered or unexported fields
}

func NewPage

func NewPage(current, size uint32, out interface{}) *Page

func NewPageSort

func NewPageSort(current, size uint32, desc []string, asc []string, records interface{}) *Page

func (*Page) Bean

func (p *Page) Bean(bean interface{}) *Page

func (*Page) Bind

func (p *Page) Bind(records interface{}, bean interface{}) *Page

func (*Page) Columns

func (p *Page) Columns(columns ...string)

func (*Page) GetBean

func (p *Page) GetBean() interface{}

func (*Page) GetColumns

func (p *Page) GetColumns() string

func (*Page) GetCurrent

func (p *Page) GetCurrent() uint32

func (*Page) GetSize

func (p *Page) GetSize() uint32

func (*Page) Offset

func (p *Page) Offset() uint32

func (*Page) SetTotal

func (p *Page) SetTotal(total int64)

type Result

type Result struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

Result 统一返回结果

func ResError

func ResError(bizerr ResultError) *Result

func ServerError

func ServerError() *Result

func Success

func Success(data interface{}) *Result

type ResultError

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

func NewResultError

func NewResultError(code int, msg string) ResultError

NewResultError 创建业务逻辑错误结构体,默认为业务逻辑错误

func (ResultError) Code

func (e ResultError) Code() int

func (ResultError) Error

func (e ResultError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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