go_utils

package module
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 15 Imported by: 0

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

func AbsInt(n int) int

计算绝对值

func AbsInt64 added in v0.5.7

func AbsInt64(n int64) int64

计算绝对值

func CWD

func CWD() string

@title cwd @description 获取当前工作目录 @return string

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 GetFuncName

func GetFuncName() string

获取正在运行的函数名

func GormErrorFilter

func GormErrorFilter(err error) error

func IsGormNotFound

func IsGormNotFound(err error) bool

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() *Crontab

NewCrontab new crontab

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 Paging

type Paging struct {
	Page      uint   //current page number
	PageSize  uint   //list items number in per page
	TotalItem uint   //rows number in database
	TotalPage uint   //the count of all pages
	DBType    string //type of database,mysql or postgresql
}

func PagingGenerator

func PagingGenerator(page, pageSize, total uint, DBType string) (paging Paging, err error)

func (*Paging) GetQueryBegin

func (p *Paging) GetQueryBegin() (begin uint)

func (*Paging) GetQueryLimit

func (p *Paging) GetQueryLimit() (sql string)

func (*Paging) SetData

func (p *Paging) SetData() (begin uint, err error)

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
复制自 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