Skip to content

shzy2012/common

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Toolbox

build status codecov GitHub license

安装

使用 go get 下载安装 SDK

$ go get -u github.com/shzy2012/common

如果您使用了 glide 管理依赖,您也可以使用 glide 来安装 SDK

$ glide get github.com/shzy2012/common

Example

log

package main

import "github.com/shzy2012/common/log"

func main() {
	log.Info("测试 log")
	log.Debug("测试 log")
	log.Error("测试 log")
}


[INFO]2019/10/17 16:32:33 main.go:6: 测试 log
[DEBG]2019/10/17 16:32:33 main.go:7: 测试 log
[ERRO]2019/10/17 16:32:33 main.go:8: 测试 log

random string

package main

import (
	"github.com/shzy2012/common/log"
	"github.com/shzy2012/common/tool"
)

func main() {
	t := tool.NewTool()
	log.Info(t.GetRandomString(64))
}

[INFO]2019/10/17 16:45:34 main.go:10: 5CDIiY3fJ1X501Ri5jsbsuomCUPjjLR2tLXYzQ5p5N0kZRnRHqGhDWrC7Hnw7YMx

string builder

package main

import (
	"github.com/shzy2012/common/log"
	"github.com/shzy2012/common/tool"
)

func main() {
	origin := "apple,iphone,apple"
	result := tool.StringBuilder(origin).Replace("apple", "fruit").Replace("iphone", "phone").Build()
	log.Info(result)
}

[INFO]2019/10/17 16:43:17 main.go:11: fruit,phone,fruit

task chain

package main

import (
	"fmt"

	"github.com/shzy2012/common/tool"
)

func main() {
	tasks := tool.NewTask()

	task1 := func(data interface{}) interface{} {
		msg := fmt.Sprintf("%s\n %s", data, "exec=> i am task1")
		return msg
	}
	task2 := func(data interface{}) interface{} {
		msg := fmt.Sprintf("%s\n %s", data, "exec=> i am task2")
		return msg
	}
	task3 := func(data interface{}) interface{} {
		msg := fmt.Sprintf("%s\n %s", data, "exec=> i am task3")
		return msg
	}

	tasks.AddTasks(task1, task2, task3)
	result := tasks.Run(" run tasks")
	fmt.Println(result)
}

 run tasks
 exec=> i am task1
 exec=> i am task2
 exec=> i am task3