gutils

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 9 Imported by: 0

README

Toolset for go

Contains the following main functions:

  • aliyun: Aliyun related
  • convert: Convert data type
  • datetime: Time related
  • db: Database related
  • encrypt: Encrypt related
  • files: Files related
  • media: Media related, including QR code / play sound / TTS
  • runtime: Runtime and hardware related
  • web: HTTP request, etc
  • crontab.go: Crontab
  • math.go: Math related
  • print.go: Simplify the print statement
  • random.go: Random string / number
  • string.go: String related

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RESpace     = regexp.MustCompile(`\s+`)                                             // Empty string
	RENumber    = regexp.MustCompile(`([0-9\.]+)`)                                      // Number
	REHex       = regexp.MustCompile(`([a-fA-F0-9]+)`)                                  // Hes
	RETimeRange = regexp.MustCompile(`\d{4}-\d{2}-\d{2}(\s*) - (\s*)\d{4}-\d{2}-\d{2}`) // Date range
)

Functions

func AbsInt

func AbsInt(n int) int

Calculate absolute value

func AbsInt64

func AbsInt64(n int64) int64

Calculate absolute value

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   // Total amount
	MaxPercentOfOffset decimal.Decimal   // Max percent of offset
	CountTotal         uint              // Allocate times
	ResultArrayAmount  []decimal.Decimal // Allocated amount array
	ResultArrayPercent []decimal.Decimal // Allocated percent array
	// contains filtered or unexported fields
}

Allocate total amount according to certain deviation

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 {
	fmt.Println(v.String())
	totalAmount = totalAmount.Add(v)
	totalPercent = totalPercent.Add(p[i])
}

Directories

Path Synopsis
windows
Refer: https://dev.to/ik5/quick-and-dirty-audio-playing-in-golang-3n7c Only for Windows OS
Refer: https://dev.to/ik5/quick-and-dirty-audio-playing-in-golang-3n7c Only for Windows OS

Jump to

Keyboard shortcuts

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