common

package
v2.2.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const DirShardingNum = float64(50000)

DirShardingNum 文件夹分组基数

Variables

View Source
var (
	MustGetMyContext = defaults.MustGetContext
	MustGetContext   = defaults.MustGetContext
	NewMockContext   = defaults.NewMockContext
)
View Source
var (

	//ErrUserNotLoggedIn 用户未登录
	ErrUserNotLoggedIn = echo.NewError(`User not logged in`, code.Unauthenticated)
	//ErrUserNotFound 用户不存在
	ErrUserNotFound = echo.NewError(`User does not exist`, code.UserNotFound)
	//ErrUserNoPerm 用户无权限
	ErrUserNoPerm = echo.NewError(`User has no permission`, code.NonPrivileged)
	//ErrUserDisabled 用户已被禁用
	ErrUserDisabled = echo.NewError(`User has been disabled`, code.UserDisabled)
	//ErrBalanceNoEnough 余额不足
	ErrBalanceNoEnough = echo.NewError(`Balance is not enough`, code.BalanceNoEnough)
	//ErrCaptcha 验证码错误
	ErrCaptcha = echo.NewError(`Captcha is incorrect`, code.CaptchaError)

	//ErrRepeatOperation 重复操作
	ErrRepeatOperation = echo.NewError(`Repeat operation`, code.RepeatOperation)
	//ErrUnsupported 不支持
	ErrUnsupported = echo.NewError(`Unsupported`, code.Unsupported)
	//ErrOperationTimeout 操作超时
	ErrOperationTimeout = echo.NewError(`Operation timeout`, code.OperationTimeout)
	//ErrOperationFail 操作失败
	ErrOperationFail = echo.NewError(`Operation fail`, code.Failure)

	//ErrResponseFormatError 响应格式错误
	ErrResponseFormatError = echo.NewError(`Response format error`, code.AbnormalResponse)
	//ErrRequestTimeout 提交超时
	ErrRequestTimeout = echo.NewError(`Request timeout`, code.RequestTimeout)
	//ErrRequestFail 提交失败
	ErrRequestFail = echo.NewError(`Request fail`, code.RequestFailure)

	// ErrIgnoreConfigChange 忽略配置文件更改
	ErrIgnoreConfigChange = errors.New(`Ignore configuration file changes`)

	// ErrNext 需要继续向下检查
	ErrNext = errors.New("Next")
)
View Source
var (
	// Sorts 获取数据查询时的排序方式
	Sorts                = clientPagination.Sorts
	Paging               = dbPagination.Paging
	PagingWithPagination = dbPagination.PagingWithPagination
	PagingWithLister     = dbPagination.PagingWithLister
	PagingWithListerCond = dbPagination.PagingWithListerCond
	PagingWithSelectList = dbPagination.PagingWithSelectList
	NewLister            = dbPagination.NewLister
	NewListParam         = dbPagination.NewListParam
	NewOffsetLister      = dbPagination.NewOffsetLister
)
View Source
var DefaultReturnToURLVarName = `return_to`
View Source
var (

	// ErrIncorrectFileOwnerID .
	ErrIncorrectFileOwnerID = errors.New("Incorrect File Owner ID")
)
View Source
var LogParsers = map[string]func(line *tail.Line) (interface{}, error){}

LogParsers 日志格式解析器

View Source
var OnRemoveOwnerFile = func(ctx echo.Context, typ string, id interface{}, ownerDir string) error {
	return nil
}

OnRemoveOwnerFile 当删除文件时的通用操作

View Source
var OnUpdateOwnerFilePath = func(ctx echo.Context,
	src string, typ string, id interface{},
	newSavePath string, newViewURL string) error {
	return nil
}

OnUpdateOwnerFilePath 当更新文件路径时的通用操作

View Source
var (
	SonyflakeStartDate = `2018-09-01 08:08:08`
)

Functions

func BatchAdd

func BatchAdd(ctx echo.Context, field string, adder Adder, before func(string) error, seperators ...string) (added []string, err error)

BatchAdd 批量添加(常用于批量添加分类) BatchAdd(ctx, `ident,>name`, adder, before, `=`) 可以通过在字段名称前面添加“>”前缀来指定表单字段名称,如果不指定则默认使用第一个作为表单字段名

func CaptchaInfo

func CaptchaInfo(hostAlias string, captchaName string, args ...string) echo.H

CaptchaInfo 新验证码信息

func ClearHTML

func ClearHTML(title string) string

ClearHTML 清除所有HTML标签及其属性,一般用处理文章标题等不含HTML标签的字符串

func Crypto

func Crypto() codec.Codec

func Decrypt

func Decrypt(secret string, datas ...*string)

Decrypt 数据解密

func DecryptedByRandomSecret

func DecryptedByRandomSecret(ctx echo.Context, sessionKey string, datas ...*string)

DecryptedByRandomSecret 用上次设置的随机密码解密

func DeleteRandomSecret

func DeleteRandomSecret(ctx echo.Context, sessionKey string)

DeleteRandomSecret 删除随机密码

func DirSharding

func DirSharding(id uint64) uint64

DirSharding 文件夹分组(暂不使用)

func Encrypt

func Encrypt(secret string, datas ...*string)

Encrypt 数据加密

func Err

func Err(ctx echo.Context, err error) (ret interface{})

Err 获取错误信息

func GenSecret

func GenSecret(sizes ...int) string

GenSecret 生成随机密钥

func HTMLFilter

func HTMLFilter() *bluemonday.Policy

HTMLFilter 构建自定义的HTML标签过滤器

func IsCaptchaErrCode

func IsCaptchaErrCode(code stdCode.Code) bool

IsCaptchaErrCode 是否验证码错误码

func IsCaptchaError

func IsCaptchaError(err error) bool

IsCaptchaError 用户验证码错误

func IsError

func IsError(err interface{}) bool

IsError 是否是错误信息

func IsMessage

func IsMessage(err interface{}) bool

IsMessage 判断err是否为Message

func IsOk

func IsOk(err interface{}) bool

IsOk 是否是成功信息

func IsRightUploadFile

func IsRightUploadFile(ctx echo.Context, src string) error

IsRightUploadFile 是否是正确的上传文件

func IsUserDisabled

func IsUserDisabled(err error) bool

IsUserDisabled 用户是否被禁用

func IsUserNoPerm

func IsUserNoPerm(err error) bool

IsUserNoPerm 用户是否没有操作权限

func IsUserNotFound

func IsUserNotFound(err error) bool

IsUserNotFound 用户是否不存在

func IsUserNotLoggedIn

func IsUserNotLoggedIn(err error) bool

IsUserNotLoggedIn 用户是否未登录

func LogShow

func LogShow(ctx echo.Context, logFile string, extensions ...echo.H) error

LogShow 获取日志内容用于显示

func ModifyAsThumbnailName

func ModifyAsThumbnailName(originName, thumbnailName string) string

ModifyAsThumbnailName 将指向临时文件夹的缩略图路径改为新位置上的缩略图路径 originName 为新位置上的原始图路径 thumbnailName 为临时位置上的缩略图路径

func MoveAvatarToUserDir

func MoveAvatarToUserDir(ctx echo.Context, src string, typ string, id uint64) (string, error)

MoveAvatarToUserDir 移动临时文件夹中的头像到用户目录

func MoveEmbedTemporaryFiles

func MoveEmbedTemporaryFiles(ctx echo.Context, content string, typ string, id interface{}) (int, string, error)

MoveEmbedTemporaryFiles 转移被嵌入到文本内容中临时文件

func MoveUploadedFileToOwnerDir

func MoveUploadedFileToOwnerDir(ctx echo.Context, src string, typ string, id interface{}) (string, error)

MoveUploadedFileToOwnerDir 移动上传的文件到所有者目录

func MoveUploadedFileToOwnerDirCommon

func MoveUploadedFileToOwnerDirCommon(ctx echo.Context, src string, typ string, id interface{}, isAvatar bool) (string, error)

MoveUploadedFileToOwnerDirCommon 移动上传的文件到所有者目录

func MyCleanTags

func MyCleanTags(value string) string

func MyCleanText

func MyCleanText(value string) string

func MyRemoveXSS

func MyRemoveXSS(content string) string

func NewSonyflake

func NewSonyflake(startDate string, machineIDs ...uint16) (*sonyflake.Sonyflake, error)

NewSonyflake 19位

func NextID

func NextID(machineIDs ...uint16) (uint64, error)
func NoLink() *bluemonday.Policy

func OkString

func OkString(err interface{}) string

OkString 获取成功信息

func ParseSQL

func ParseSQL(sqlFile string, isFile bool, installer func(string) error) (err error)

func ReadCache

func ReadCache(dir string, name string) (content []byte, err error)

ReadCache 读缓存文件

func RemoveAvatar

func RemoveAvatar(ctx echo.Context, typ string, id uint64) error

RemoveAvatar 删除头像

func RemoveBytesXSS

func RemoveBytesXSS(content []byte, noLinks ...bool) []byte

func RemoveCache

func RemoveCache(dir string, names ...string) (err error)

RemoveCache 删除缓存文件

func RemoveReaderXSS

func RemoveReaderXSS(reader io.Reader, noLinks ...bool) *bytes.Buffer

func RemoveUploadedFile

func RemoveUploadedFile(ctx echo.Context, typ string, id interface{}) error

RemoveUploadedFile 删除被上传的文件

func RemoveXSS

func RemoveXSS(content string, noLinks ...bool) string

RemoveXSS 清除不安全的HTML标签和属性,一般用于处理文章内容

func ReplacePrefix

func ReplacePrefix(m factory.Model, field string, oldPrefix string, newPrefix string) error

ReplacePrefix 替换前缀数据

func Replacex

func Replacex(s string, oldAndNew map[string]string) string

Replacex 根据map替换

func ReturnToURL

func ReturnToURL(ctx echo.Context, varNames ...string) string

func SendErr

func SendErr(ctx echo.Context, err error)

SendErr 记录错误信息 (SendFail的别名)

func SendFail

func SendFail(ctx echo.Context, msg string)

SendFail 记录失败信息

func SendOk

func SendOk(ctx echo.Context, msg string)

SendOk 记录成功信息

func SetRandomSecret

func SetRandomSecret(ctx echo.Context, sessionKey string, storeKey ...string)

SetRandomSecret 设置随机密码

func SetSonyflake

func SetSonyflake(startDate string, machineIDs ...uint16) (err error)

func SonyflakeInit

func SonyflakeInit(machineIDs ...uint16)

func UniqueID

func UniqueID(machineIDs ...uint16) (string, error)

func ValidFileOwnerID

func ValidFileOwnerID(id string) error

ValidFileOwnerID 验证文件宿主ID

func VerifyAndSetCaptcha

func VerifyAndSetCaptcha(ctx echo.Context, hostAlias string, captchaName string, args ...string) echo.Data

VerifyAndSetCaptcha 验证码验证并设置新验证码信息

func VerifyCaptcha

func VerifyCaptcha(ctx echo.Context, hostAlias string, captchaName string, args ...string) echo.Data

VerifyCaptcha 验证码验证

func WithReturnToURL

func WithReturnToURL(ctx echo.Context, urlStr string, varNames ...string) string

func WriteCache

func WriteCache(dir string, name string, content []byte) (err error)

WriteCache 写缓存文件

Types

type Adder

type Adder interface {
	Set(interface{}, ...interface{})
	Add() (interface{}, error)
}

Adder interface

type ConfigFromDB

type ConfigFromDB interface {
	ConfigFromDB() echo.H
}

type Errors

type Errors []error

Errors 多个错误信息

func (Errors) Error

func (e Errors) Error() string

func (Errors) String

func (e Errors) String() string

type List

type List = dbPagination.List

type Lister

type Lister = dbPagination.Lister

type Messager

type Messager interface {
	Successor
	error
}

Messager 信息接口

var DefaultNopMessage Messager = &NopMessage{}

DefaultNopMessage 默认空消息

func Message

func Message(err interface{}) Messager

Message 获取err中的信息接口

type NopMessage

type NopMessage struct {
}

NopMessage 空消息

func (*NopMessage) Error

func (n *NopMessage) Error() string

Error 错误信息

func (*NopMessage) String

func (n *NopMessage) String() string

String 信息字符串

func (*NopMessage) Success

func (n *NopMessage) Success() string

Success 成功信息

type OffsetListFunc

type OffsetListFunc = dbPagination.OffsetListFunc

type OffsetLister

type OffsetLister = dbPagination.OffsetLister

type PageListFunc

type PageListFunc = dbPagination.PageListFunc

type StatusColor

type StatusColor string

StatusColor 状态色

func HTTPStatusColor

func HTTPStatusColor(httpCode int) StatusColor

HTTPStatusColor HTTP状态码相应颜色

func (StatusColor) Bootstrap

func (s StatusColor) Bootstrap() string

Bootstrap 前端框架 bootstrap css 状态样式

func (StatusColor) String

func (s StatusColor) String() string

func (StatusColor) Terminal

func (s StatusColor) Terminal() func(string, ...interface{})

Terminal 控制台样式

type Success

type Success struct {
	Value string
}

Success 成功信息

func (*Success) String

func (s *Success) String() string

func (*Success) Success

func (s *Success) Success() string

Success 成功信息

type Successor

type Successor interface {
	Success() string
}

Successor 成功信息接口

func NewOk

func NewOk(v string) Successor

NewOk 创建成功信息

func Ok

func Ok(v string) Successor

Ok 操作成功

Jump to

Keyboard shortcuts

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