toolkit

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 6 Imported by: 3

README

开发常用函数工具箱(Develop a common function toolkit)

安装(Install)

go get github.com/wumoxi/toolkit

生成指定范围内的随机数

Call

r := toolbox.Random(100000, 999999)

Result

// This is a random value
722479

生成指定范围内的有序整型切片

Call

s := toolbox.GenerateSectionIntSliceOfOrderly(1, 20, 3)

Result

[1 4 7 10 13 16 19]

生成指定范围内的无序整型切片

Call

s := toolbox.GenerateSectionIntSliceOfDisorderly(1, 20)

Result

// It could be something like this
[4 18 16 7 8 4 19 1 16 9 13 9 1 4 16 15 13 8 14]

使用可变参数连接字符串切片

Call

s := toolbox.JoinItemOfStringSlice("", "中", "华", "人", "民", "共", "和", "国")

Result

中华人民共和国

生成指定范围内的斐波那契数列

Call

s := toolbox.FibSliceOfInt(100)

Result

[1 1 2 3 5 8 13 21 34 55 89]

计算正整数阶乘

Call

s := toolbox.Factorial(10)

Result

362880

生成指定范围内的正整数阶乘切片

Call

s := toolbox.FactorialSliceOfUint64(10)

Result

[1 1 2 6 24 120 720 5040 40320 362880]

计算函数运行时间

可以使用 toolkit.FunctionStart()duration := toolkit.FunctionEnd() 函数对待检测运行时间的函数进行包裹,FunctionEnd() 返回一个 Duration 值。

Call

func main() {
	toolkit.FunctionStart()
	sum(100000000)
	duration := toolkit.FunctionEnd()
	fmt.Println(duration)
}

func sum(number int64) (sum int64) {
	var i int64
	for i = 0; i < number; i++ {
		sum += i
	}
	return sum
}

Result

// 具体的运行时间根据执行环境而定
// The specific runtime depends on the execution environment
102.202207ms

发送邮件

Call

mailer := toolkit.NewEmail(&toolkit.MailerParams{
    ServerHost:   "smtp.qq.com",
    ServerPort:   465,
    FromEmail:    "shaohua@foxmail.com",
    FromPassword: "mmooqssdsuwjskssddthpubddf",
    FromName:     "武沫汐",
    Toers:        []string{"warner@126.com", "warner@139.com", "contact.warner@gmail.com"},
    CCers:        []string{"warner@163.com"},
})

send, err := mailer.Send("Golang邮件发送", `中华人民共和国 - Golang邮件发送`, "text/plain")
if err != nil && !send {
    t.Fatal(err)
} else {
    t.Log("发送成功")
}

Result

发送成功

Documentation

Index

Constants

View Source
const (
	Underline = "_" // 下划线
)

Variables

This section is empty.

Functions

func AllowCapitalGenerateSlice

func AllowCapitalGenerateSlice(str string) (words []string)

AllowCapitalGenerateSlice 将传递参数 str 通过单词首字母大写,进行分割返回全小写单词切片

func BigCamelCase2SmallCamelCase

func BigCamelCase2SmallCamelCase(str string) string

BigCamelCase2SmallCamelCase 使用大驼峰转小驼峰

func CamelCase2Underline

func CamelCase2Underline(str string) string

CamelCase2Underline 使用驼峰转下划线生成标记

func ConvertToBigCamelCase

func ConvertToBigCamelCase(str string) string

ConvertToBigCamelCase 转换为大驼峰命令法

func ConvertToSmallCamelCase

func ConvertToSmallCamelCase(str string) string

ConvertToSmallCamelCase 转换为小驼峰命令法

func Factorial

func Factorial(n uint64) (result uint64)

计算正整数阶乘

func FactorialSliceOfUint64

func FactorialSliceOfUint64(max uint64) (factorial []uint64)

生成指定范围内的正整数阶乘切片

func Fib

func Fib(n int) (res int)

生成斐波那契数

func FibSliceOfInt

func FibSliceOfInt(max int) (slice []int)

生成指定范围内的斐波那契数列

func FunctionEnd

func FunctionEnd() (duration time.Duration)

获取记录的运行时间

func FunctionStart

func FunctionStart()

开始记录运行时间

func GenerateSectionIntSliceOfDisorderly

func GenerateSectionIntSliceOfDisorderly(min, max int) []int

生成指定范围内的无序整型切片

func GenerateSectionIntSliceOfOrderly

func GenerateSectionIntSliceOfOrderly(min, max int, step int) []int

生成指定范围内的有序整型切片

func GetWordsFormString

func GetWordsFormString(str string) (words []string)

GetWordsFormString 获取 str 中的单词

func JoinItemOfStringSlice

func JoinItemOfStringSlice(delimit string, slice ...string) (joined string)

使用指定的定界符连接字符串切片值

func Random

func Random(min, max int) int

生成指定范围的随机数

func SmallCamelCase2BigCamelCase

func SmallCamelCase2BigCamelCase(str string) string

SmallCamelCase2BigCamelCase 使用小驼峰转大驼峰

func Underline2BigCamelCase

func Underline2BigCamelCase(str string) string

Underline2BigCamelCase 下划线转换为大驼峰

func Underline2SmallCamelCase

func Underline2SmallCamelCase(str string) string

Underline2SmallCamelCase 下划线转换为小驼峰

Types

type Mailer

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

邮件结构体

func NewEmail

func NewEmail(params *MailerParams) *Mailer

获取一个邮件指针实例

func (*Mailer) Send

func (m *Mailer) Send(subject, body, contentType string) (bool, error)

发送邮件

type MailerParams

type MailerParams struct {
	ServerHost   string   // ServerHost 邮箱服务器地址,如腾讯邮箱为 smtp.qq.com
	ServerPort   int      // ServerPort 邮箱服务器端口,如腾讯邮箱为 465
	FromName     string   // 发件人名称
	FromEmail    string   // 发件人邮箱地址
	FromPassword string   // 发件人邮箱密码
	Toers        []string // 接收者邮件地址,可以添加多个
	CCers        []string // 抄送者邮件地址,可以添加多个
}

发送邮件配置参数

Jump to

Keyboard shortcuts

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