gutils

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 9 Imported by: 0

README

go 工具集

包含以下几个主要功能:

  • aliyun 目录, aliyun 相关
  • convert 目录, 数据类型转换
  • datetime 目录,时间相关,包含一个 JSONTIME,用于处理 JSON
  • db 目录, 数据库相关,包含分页
  • encrypt 目录,加密相关,如: AES / DES / MD5 等
  • files 目录,文件相关
  • media 目录,多媒体相关,包含二维码生成 / TTS 等
  • runtime 目录, 运行时和系统状态相关
  • web 目录,处理 HTTP 请求等
  • crontab.go, 封装了定时任务
  • math.go, 数学计算
  • print.go, 简化了打印函数
  • random.go, 生成随机字符 / 数字
  • string.go, 字符串相关,包含一些常用的正则

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RESpace     = regexp.MustCompile(`\s+`)                                           //匹配一个或多个空白符的正则表达式
	RENumber    = regexp.MustCompile(`([0-9\.]+)`)                                    //数字
	REHex       = regexp.MustCompile(`([a-fA-F0-9]+)`)                                //16进制
	RETimeRange = regexp.MustCompile(`\d{4}-\d{2}-\d{2}(\s*)到(\s*)\d{4}-\d{2}-\d{2}`) //时间范围
)

Functions

func AbsInt

func AbsInt(n int) int

计算绝对值

func AbsInt64

func AbsInt64(n int64) int64

计算绝对值

func CielInt

func CielInt(a, b uint) int

func CielInt64

func CielInt64(a, b uint) int64

func CielUint

func CielUint(a, b uint) uint

func CielUint64

func CielUint64(a, b uint) uint64

func Printf

func Printf(title string, value interface{})

func Println

func Println(content string)

func RandFloat64

func RandFloat64() float64

func RandInt

func RandInt(min int, max int) int

func RandString

func RandString(len int) string

func StrDeleteSpace

func StrDeleteSpace(str string) string

Types

type Crontab

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

Crontab crontab manager

func NewCrontab

func NewCrontab(secondsFieldLevel uint) *Crontab

NewCrontab new crontab secondsFieldLevel: 0 without,1 required,2 optional

func (*Crontab) AddByFunc

func (c *Crontab) AddByFunc(id string, spec string, f func()) error

AddByFunc add function as crontab task

func (*Crontab) AddByID

func (c *Crontab) AddByID(id string, spec string, cmd cron.Job) error

AddByID add one crontab task id is unique spec is the crontab expression

func (*Crontab) DelByID

func (c *Crontab) DelByID(id string)

DelByID remove one crontab task

func (*Crontab) IDs

func (c *Crontab) IDs() []string

IDs ...

func (*Crontab) IsExists

func (c *Crontab) IsExists(jid string) bool

IsExists check the crontab task whether existed with job id

func (*Crontab) Start

func (c *Crontab) Start()

Start start the crontab engine

func (*Crontab) Stop

func (c *Crontab) Stop()

Stop stop the crontab engine

type RandomAllocate

type RandomAllocate struct {
	AmountTotal        decimal.Decimal   //总金额
	MaxOffsetPercent   decimal.Decimal   //最大偏差比例
	CountTotal         uint              //要分配的次数
	ResultArrayAmount  []decimal.Decimal //返回金额结果
	ResultArrayPercent []decimal.Decimal //返回比例结果
	// contains filtered or unexported fields
}

按一定偏差分配总金额

var m = randomAllocate{
	AmountTotal:      decimal.NewFromFloat(1243.0),
	CountTotal:       42,
	MaxOffsetPercent: decimal.NewFromFloat(0.3),
}

a, p := m.run()

totalAmount := decimal.NewFromInt(0) totalPercent := decimal.NewFromInt(0)

for i, v := range a {
	//GU.Printf("\n分配金额"+v.String(), "  比例"+p[i].String())
	fmt.Println(v.String())
	totalAmount = totalAmount.Add(v)
	totalPercent = totalPercent.Add(p[i])
}

GU.Printf("合计金额 ", totalAmount.String()) GU.Printf("合计比例 ", totalPercent.String())

Directories

Path Synopsis
windows
复制自 https://dev.to/ik5/quick-and-dirty-audio-playing-in-golang-3n7c 功能上微调 只适用于 windows
复制自 https://dev.to/ik5/quick-and-dirty-audio-playing-in-golang-3n7c 功能上微调 只适用于 windows

Jump to

Keyboard shortcuts

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