common

package
v0.6.20 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: AGPL-3.0 Imports: 36 Imported by: 76

Documentation

Index

Constants

View Source
const (
	ConfigName  = `ConfigFromFile`
	SettingName = `ConfigFromDB`
)
View Source
const (
	BoolY = `Y`
	BoolN = `N`
)
View Source
const (
	ContentTypeHTML     = `html`
	ContentTypeMarkdown = `markdown`
	ContentTypeText     = `text`
)
View Source
const DirShardingNum = float64(50000)

DirShardingNum 文件夹分组基数

Variables

View Source
var (
	MustGetMyContext = defaults.MustGetContext
	MustGetContext   = defaults.MustGetContext
	NewMockContext   = defaults.NewMockContext
)
View Source
var (
	// Sorts 获取数据查询时的排序方式
	Sorts                      = clientPagination.Sorts
	Paging                     = dbPagination.Paging
	PagingWithPagination       = dbPagination.PagingWithPagination
	PagingWithPosition         = dbPagination.PagingWithPosition
	PagingWithLister           = dbPagination.PagingWithLister
	PagingWithOffsetLister     = dbPagination.PagingWithOffsetLister
	PagingWithListerCond       = dbPagination.PagingWithListerCond
	PagingWithSelectList       = dbPagination.PagingWithSelectList
	PagingWithList             = dbPagination.PagingWithList
	PagingWithOffsetSelectList = dbPagination.PagingWithOffsetSelectList
	PagingWithOffsetList       = dbPagination.PagingWithOffsetList
	NewLister                  = dbPagination.NewLister
	NewListParam               = dbPagination.NewListParam
	NewOffsetLister            = dbPagination.NewOffsetLister
)
View Source
var (
	ErrInvalidIPAddress = errors.New("Invalid IP address")
	ErrNotSet           = errors.New("Not set")
)
View Source
var (
	SonyflakeStartDate = `2018-09-01 08:08:08`
)

Functions

func AddLinks(ctx echo.Context, title string, url string, icon string, color ...string) *echo.KVList

func BackendURL

func BackendURL(ctx echo.Context) string

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 BoolToFlag

func BoolToFlag(v bool) string

func ClearHTML

func ClearHTML(title string) string

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

func ContentEncode

func ContentEncode(content string, contypes ...string) string

func CookieConfig

func CookieConfig() scookie.Config

func CopyFormDataFrom

func CopyFormDataFrom(ctx echo.Context, formData map[string][]string)

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 EncErrMsg added in v0.2.0

func EncErrMsg(msg string) string

func EncOkMsg added in v0.2.0

func EncOkMsg(msg string) string

func Encrypt

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

Encrypt 数据加密

func Err

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

Err 获取错误信息

func ExtendConfig

func ExtendConfig() echo.H

func FlagToBool

func FlagToBool(v string) bool

func Float32Sum

func Float32Sum(numbers ...float32) float32

func Float64Sum

func Float64Sum(numbers ...float64) float64

func FloorNumber

func FloorNumber(page int, pageSize int, index int) int

FloorNumber 楼层号

func GenPassword

func GenPassword() (string, error)

func GenSecret

func GenSecret(sizes ...uint) string

GenSecret 生成随机密钥

func GetBoolFlag

func GetBoolFlag(value string, defaults ...string) string

func GetContype

func GetContype(value string, defaults ...string) string

func GetEditableJSFormData

func GetEditableJSFormData(ctx echo.Context, checkers ...map[string]func(*string) bool) (pk string, field string, value string, err error)

func GetEncMsg added in v0.2.0

func GetEncMsg(ctx echo.Context) (ret interface{})

func GetEnumValue

func GetEnumValue(enums []string, value string, defaults string) string

func GetLocalIP

func GetLocalIP(ver ...int) (string, error)

GetLocalIP 获取本机网卡IP

func GetLocalIPs

func GetLocalIPs() (ipv4 []string, ipv6 []string, err error)

GetLocalIPs 获取本机网卡IP

func GetLocalIPv4

func GetLocalIPv4() (ipv4 string, err error)

GetLocalIPv4 获取本机网卡IPv4

func GetLocalIPv6

func GetLocalIPv6() (ipv6 string, err error)

GetLocalIPv6 获取本机网卡IPv6

func GetNowTime

func GetNowTime(ctx echo.Context) time.Time

GetNowTime 获取当前时间(同一个context中只获取一次)

func GetSavedNextURL added in v0.3.25

func GetSavedNextURL(ctx echo.Context, defaultURL string) string

func HPoolGet

func HPoolGet() echo.H

func HPoolRelease

func HPoolRelease(m echo.H)

func HTMLFilter

func HTMLFilter() *bluemonday.Policy

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

func IDSharding

func IDSharding(id uint64, shardingNum float64) uint64

IDSharding 按照ID进行分片

func IPv4ToMachineID

func IPv4ToMachineID(ipv4 string) (uint16, error)

func If

func If[T any](condition bool, yesValue T, noValue T) T

func IsAnonymousMode

func IsAnonymousMode(ownerType string) bool

func IsBoolFlag

func IsBoolFlag(value string) bool

func IsContype

func IsContype(value string) bool

func IsIPv4

func IsIPv4(host string) bool

IsIPv4 Returns true if input is IPv4

func IsIPv6

func IsIPv6(host string) bool

IsIPv6 Returns true if input is IPv6

func LookPath

func LookPath(bin string, otherPaths ...string) (string, error)

LookPath 获取二进制可执行文件路径

func MD5Sharding

func MD5Sharding(str interface{}, length ...int) string

MD5Sharding 按照MD5进行分片

func MarkdownPickoutCodeblock

func MarkdownPickoutCodeblock(content string) (repl []string, newContent string)

func MarkdownRestorePickout

func MarkdownRestorePickout(repl []string, content string) string

func MonthSharding

func MonthSharding(ctx echo.Context) string

MonthSharding 按照日期月进行分片

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 NewStrictPolicy

func NewStrictPolicy() *bluemonday.Policy

func NewUGCPolicy

func NewUGCPolicy() *bluemonday.Policy

func NextID

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

func OSAbsPath

func OSAbsPath(ppath string) string

func Ok

func Ok(v string) nerrors.Successor

Ok 操作成功

func ParseMachineIDFromEnvVar

func ParseMachineIDFromEnvVar() (uint16, error)

func RemoveBytesXSS

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

func RemoveReaderXSS

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

func RemoveXSS

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

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

func ReverseURL added in v0.3.29

func ReverseURL(u string) string

func SeekLinesWithoutComments

func SeekLinesWithoutComments(r io.Reader) (string, error)

func SendErr

func SendErr(ctx echo.Context, err error)

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

func SendFail

func SendFail(ctx echo.Context, msg string, storeInCookie ...bool)

SendFail 记录失败信息

func SendOk

func SendOk(ctx echo.Context, msg string, storeInCookie ...bool)

SendOk 记录成功信息

func SetProcessError added in v0.3.0

func SetProcessError(f func(ctx echo.Context, err error) error)

func SetRandomSecret

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

SetRandomSecret 设置随机密码

func SetSonyflake

func SetSonyflake(startDate string, machineIDs ...uint16) (sonyFlake *sonyflake.Sonyflake, err error)

func Setting

func Setting(group ...string) echo.H

func SonyflakeInit

func SonyflakeInit(machineIDs ...uint16) *sonyflake.Sonyflake

func SplitSingleMutibytes

func SplitSingleMutibytes(content string) string

func SplitSingleMutibytesBytes

func SplitSingleMutibytesBytes(content []byte) []byte

func StringMapPoolGet

func StringMapPoolGet() param.StringMap

func StringMapPoolRelease

func StringMapPoolRelease(m param.StringMap)

func SystemAPIKey

func SystemAPIKey() string

func TemplateTags

func TemplateTags(keys ...string) echo.H

func Tx

func URLValuesPoolGet

func URLValuesPoolGet() url.Values

func URLValuesPoolRelease

func URLValuesPoolRelease(m url.Values)

func UniqueID

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

func WithEncErrMsg added in v0.2.0

func WithEncErrMsg(msg string) string

func WithEncOkMsg added in v0.2.0

func WithEncOkMsg(msg string) string

func WithoutCommentsLineParser

func WithoutCommentsLineParser(exec func(string) error) func(string) error

func YearSharding

func YearSharding(ctx echo.Context) string

YearSharding 按照日期年进行分片

Types

type APIKeyGetter

type APIKeyGetter interface {
	APIKey() string
}

APIKeyGetter API Key

type Adder

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

Adder interface

type ConfigFromDB

type ConfigFromDB interface {
	ConfigFromDB() echo.H
}

type CookieConfigGetter

type CookieConfigGetter interface {
	CookieConfig() scookie.Config
}

type Cryptor added in v0.2.0

type Cryptor interface {
	Encode(raw string, keys ...string) string
	Decode(encrypted string, keys ...string) string
	Encode256(raw string, keys ...string) string
	Decode256(encrypted string, keys ...string) string
}

func CryptorConfig added in v0.2.0

func CryptorConfig() Cryptor

type ExtendConfigGetter

type ExtendConfigGetter interface {
	GetExtend() echo.H
}

type List

type List = dbPagination.List

type Lister

type Lister = dbPagination.Lister

type OffsetListFunc

type OffsetListFunc = dbPagination.OffsetListFunc

type OffsetLister

type OffsetLister = dbPagination.OffsetLister

type PageListFunc

type PageListFunc = dbPagination.PageListFunc

type SortedURLValues

type SortedURLValues []*URLValues

func NewSortedURLValues

func NewSortedURLValues(query string) SortedURLValues

func (*SortedURLValues) Add

func (s *SortedURLValues) Add(key, value string)

func (SortedURLValues) ApplyCond

func (s SortedURLValues) ApplyCond(cond *db.Compounds)

func (*SortedURLValues) Del

func (s *SortedURLValues) Del(key string)

func (SortedURLValues) Get

func (s SortedURLValues) Get(key string) string

func (SortedURLValues) Has

func (s SortedURLValues) Has(key string) bool

func (*SortedURLValues) ParseQuery

func (s *SortedURLValues) ParseQuery(query string) (err error)

ParseQuery 解析 URL Query copy from standard library src/net/url/url.go: func parseQuery(m Values, query string) (err error)

func (*SortedURLValues) Set

func (s *SortedURLValues) Set(key, value string)

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 URLValues

type URLValues struct {
	Key    string
	Values []string
}

Jump to

Keyboard shortcuts

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