gathertool

package module
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT Imports: 70 Imported by: 9

README

gathertool

gathertool是golang脚本化开发库,目的是提高对应场景程序开发的效率; 轻量级爬虫库,接口测试&压力测试库,DB操作库。 请使用最新版本!!!

使用场景

  1. 爬虫脚本开发
  2. 接口测试&压力测试脚本开发
  3. http/s代理服务器, socket5代理服务器
  4. mysql相关操作方法
  5. redis相关操作方法
  6. mongo相关操作方法
  7. 数据提取&清洗相关操作
  8. Websocket相关操作方法
  9. TCP客户端
  10. UDP客户端
  11. SSH客户端
  12. 加密解密脚本开发
  13. ip扫描,端口扫描脚本开发

文档:

https://pkg.go.dev 点击开始 http://mange.work/doc?id=1 点击开始

开始使用

go get github.com/mangenotwork/gathertool

简单的get请求

import gt "github.com/mangenotwork/gathertool"

func main(){
    ctx, err := gt.Get("https://www.baidu.com")
    if err != nil {
        log.Println(err)
    }
    log.Println(ctx.RespBodyString)
}

含请求事件请求

import gt "github.com/mangenotwork/gathertool"

func main(){

    gt.NewGet(`http://192.168.0.1`).SetStartFunc(func(ctx *gt.Context){
            log.Println("请求前: 添加代理等等操作")
            ctx.Client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
        }
    ).SetSucceedFunc(func(ctx *gt.Context){
            log.Println("请求成功: 处理数据或存储等等")
            log.Println(ctx.RespBodyString())
        }
    ).SetFailedFunc(func(ctx *gt.Context){
            log.Println("请求失败: 记录失败等等")
            log.Println(ctx.Err)
        }
    ).SetRetryFunc(func(ctx *gt.Context){
             log.Println("请求重试: 更换代理或添加等待时间等等")
             ctx.Client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
        }
    ).SetEndFunc(func(ctx *gt.Context){
             log.Println("请求结束: 记录结束,处理数据等等")
             log.Println(ctx)
        }
    ).Do()
    
}

事件方法复用

func main(){
    gt.NewGet(`http://192.168.0.1`).SetSucceedFunc(succeed).SetFailedFunc(failed).SetRetryFunc(retry).Do()
    gt.NewGet(`http://www.baidu.com`).SetSucceedFunc(baiduSucceed).SetFailedFunc(failed).SetRetryFunc(retry).Do()
}
// 请求成功: 处理数据或存储等等
func succeed(ctx *gt.Context){
    log.Println(ctx.RespBodyString())
}
// 请求失败: 记录失败等等
func failed(ctx *gt.Context){
    log.Println(ctx.Err)
}
// 请求重试: 更换代理或添加等待时间等等
func retry(ctx *gt.Context){
    ctx.Client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
}
// 百度请求成功后
func baiduSucceed(ctx *gt.Context){
    log.Println(ctx.RespBodyString())
}

post请求

    // FormData
    postData := gt.FormData{
        "aa":"aa",	
    }
    
    // header
    header := gt.NewHeader(map[string]string{
        "Accept":"*/*",
        "X-MicrosoftAjax":"Delta=true",
        "Accept-Encoding":"gzip, deflate",
        "XMLHttpRequest":"XMLHttpRequest",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
    })
    
    // cookie
    cookie := gt.Cookie{
        "aa":"a"
    }
    
    // 随机休眠 2~6秒
    sleep := gt.SetSleep(2,6)
    c := gt.NewPostForm(caseUrl, postData, header, cookie, sleep)
    c.Do()
    html := c.RespBodyString()
    log.Print(html)

数据存储到mysql

var (
    host   = "192.168.0.100"
    port      = 3306
    user      = "root"
    password  = "root123"
    dbName  = "dbName"
    db,_ = gt.NewMysql(host, port, user, password, dbName)
)

//.... 执行抓取
data1 := "data1"
data2 := "data2"

inputdata := map[string]interface{} {
    "data1" : data1,
    "data2" : data2,
}

tableName := "data"
db.Spider2022DB.InsertAt(tableName, inputdata)

HTML数据提取

func main(){
	date := "2022-07-05"
	caseUrl := "***"
	ctx, _ := gt.Get(fmt.Sprintf(caseUrl, date))
    datas, _ := gt.GetPointHTML(ctx.Html, "div", "id", "domestic")
	Data(datas, date, "内期表", "备注:内期表=国内期货主力合约表")
	datas, _ = gt.GetPointHTML(ctx.Html, "div", "id", "overseas")
	Data(datas, date, "外期表", "备注:外期表=国外期货主力合约表")
}

func Data(datas []string, date, typeName, note string) {
	for _, data := range datas {
		table, _ := gt.GetPointHTML(data, "table", "id", "fdata")
		if len(table) > 0 {
			trList := gt.RegHtmlTr(table[0])
			jys := ""
			for _, tr := range trList {
				td := gt.RegHtmlTd(tr)
				log.Println("td = ", td, len(td))
				if len(td) == 1 {
					jys = gt.RegHtmlTdTxt(td[0])[0]
					continue
				}
				name := gt.RegHtmlTdTxt(td[0])[0]
				if strings.Index(name, "商品名称") != -1 {
					continue
				}
				zlhy := gt.RegHtmlTdTxt(td[1])[0]
				jsj := gt.RegHtmlTdTxt(td[2])[0]
				zd := gt.RegDelHtml(gt.RegHtmlTdTxt(td[3])[0])
				cjj := gt.RegHtmlTdTxt(td[4])[0]
				ccl := gt.RegHtmlTdTxt(td[5])[0]
				dw := gt.RegHtmlTdTxt(td[6])[0]
				log.Println("日期 = ", date)
				log.Println("机构 = ", jys)
				log.Println("商品名称 = ", name)
				log.Println("主力合约 = ", zlhy)
				log.Println("结算价 = ", jsj)
				log.Println("涨跌 = ", zd)
				log.Println("成交量 = ", cjj)
				log.Println("持仓量 = ", ccl)
				log.Println("单位 = ", dw)
			}
		}
	}
}

更多方法见 文档

实例

TODO List

  • 文件相关处理
  • 三方队列(redis, mysql, nsq)
  • ES
  • 高并发下载
  • Rabbit, RC4, RIPEMD-160 加密解密
  • excel 相关操作
  • pdf 相关操作
  • 暴力登录,暴力破解等
  • 文件相关操作
  • ES相关操作

JetBrains 开源证书支持

gathertool 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 free JetBrains Open Source license(s) 正版免费授权,在此表达我的谢意。

Documentation

Index

Constants

View Source
const (
	CBC = "CBC"
	ECB = "ECB"
	CFB = "CFB"
	CTR = "CTR"
)
View Source
const (
	POST    = "POST"
	GET     = "GET"
	HEAD    = "HEAD"
	PUT     = "PUT"
	DELETE  = "DELETE"
	PATCH   = "PATCH"
	OPTIONS = "OPTIONS"
	ANY     = ""
)
View Source
const (
	UTF8    = Charset("UTF-8")
	GB18030 = Charset("GB18030")
	GBK     = Charset("GBK")
	GB2312  = Charset("GB2312")
)
View Source
const (
	KiB = 1024
	MiB = KiB * 1024
	GiB = MiB * 1024
	TiB = GiB * 1024
)

字节换算

View Source
const TimeTemplate = "2006-01-02 15:04:05"

Variables

View Source
var (
	SHOW_TABLES     = "SHOW TABLES"
	TABLE_NAME_NULL = fmt.Errorf("table name is null.")
	TABLE_IS_NULL   = fmt.Errorf("table is null.")
)
View Source
var (
	ChineseNumber   = []string{"一", "二", "三", "四", "五", "六", "七", "八", "九", "零"}
	ChineseMoney    = []string{"壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}
	ChineseMoneyAll = []string{"壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "佰", "仟", "万", "亿", "元", "角", "分", "零", "整", "正", "貳", "陸", "億", "萬", "圓"}
)
View Source
var (
	UrlBad = errors.New("url is bad.")  // 错误的url
	UrlNil = errors.New("url is null.") // 空的url

)
View Source
var AgentType = map[UserAgentType][]int{
	PCAgent:           listPCAgent,
	WindowsAgent:      listWindowsAgent,
	LinuxAgent:        listLinuxAgent,
	MacAgent:          listMacAgent,
	AndroidAgent:      listAndroidAgent,
	IosAgent:          listIosAgent,
	PhoneAgent:        listPhoneAgent,
	WindowsPhoneAgent: listWindowsPhoneAgent,
	UCAgent:           listUCAgent,
}
View Source
var ContentType map[string]string = map[string]string{}/* 315 elements not displayed */

ContentType 数据类型

View Source
var CookiePool *cookiePool

CookiePool Cookie池

View Source
var LevelMap = map[Level]string{
	1: "Info  ",
	2: "Debug ",
	3: "Warn  ",
	4: "Error ",
}
View Source
var LogClose bool = false

LogClose 是否关闭日志

View Source
var MysqlDB = &Mysql{}
View Source
var StatusCodeMap map[int]string = map[int]string{
	200: "success",
	201: "success",
	202: "success",
	203: "success",
	204: "fail",
	300: "success",
	301: "success",
	302: "success",
	400: "fail",
	401: "retry",
	402: "retry",
	403: "retry",
	404: "fail",
	405: "retry",
	406: "retry",
	407: "retry",
	408: "retry",
	412: "success",
	500: "fail",
	501: "fail",
	502: "retry",
	503: "retry",
	504: "retry",
}

StatusCodeMap 状态码处理映射 success 该状态码对应执行成功函数 fail 该状态码对应执行失败函数 retry 该状态码对应需要重试前执行的函数

View Source
var UserAgentMap map[int]string = map[int]string{
	1:  "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0",
	2:  "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36",
	3:  "Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)",
	4:  "Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.62",
	5:  "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
	6:  "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0",
	7:  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36",
	8:  "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
	9:  "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 Version/11.52",
	10: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36",
	11: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0",
	12: "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166  Safari/535.19",
	13: "Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
	14: "Mozilla/5.0 (Linux; U; Android 2.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
	15: "Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0",
	16: "Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0",
	17: "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19",
	18: "Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19",
	19: "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
	20: "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
	21: "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
	22: "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
	23: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/27.0.1453.10 Mobile/10B350 Safari/8536.25",
	24: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)",
	25: "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)",
	26: "User-Agent, UCWEB7.0.2.37/28/999",
	27: "User-Agent, NOKIA5700/ UCWEB7.0.2.37/28/999",
	28: "User-Agent, Openwave/ UCWEB7.0.2.37/28/999",
	29: "User-Agent, Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
	30: "Mozilla/5.0 (Windows; U; Windows NT 6.1; ) AppleWebKit/534.12 (KHTML, like Gecko) Maxthon/3.0 Safari/534.12",
	31: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)",
	32: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)",
	33: "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0",
	34: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)",
	35: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1 QQBrowser/6.9.11079.201",
}

Functions

func AbPathByCaller added in v0.3.5

func AbPathByCaller() string

AbPathByCaller 获取当前执行文件绝对路径(go run)

func AccountRational added in v0.3.4

func AccountRational(str string) bool

AccountRational 帐号合理性

func Any2Arr added in v0.1.17

func Any2Arr(data interface{}) []interface{}

Any2Arr interface{} -> []interface{}

func Any2Float64 added in v0.0.10

func Any2Float64(data interface{}) float64

Any2Float64 interface{} -> float64

func Any2Int added in v0.0.10

func Any2Int(data interface{}) int

Any2Int interface{} -> int

func Any2Json added in v0.2.1

func Any2Json(data interface{}) (string, error)

Any2Json interface{} -> json string

func Any2Map added in v0.0.10

func Any2Map(data interface{}) map[string]interface{}

Any2Map interface{} -> map[string]interface{}

func Any2String added in v0.0.10

func Any2String(data interface{}) string

Any2String interface{} -> string

func Any2Strings added in v0.0.10

func Any2Strings(data interface{}) []string

Any2Strings interface{} -> []string

func Any2int64 added in v0.0.10

func Any2int64(data interface{}) int64

Any2int64 interface{} -> int64

func BIG5To added in v0.2.8

func BIG5To(dstCharset string, src string) (dst string, err error)

BIG5To

func Base64Decode added in v0.1.4

func Base64Decode(str string) (string, error)

Base64Decode base64 解码

func Base64Encode added in v0.1.4

func Base64Encode(str string) string

Base64Encode base64 编码

func Base64UrlDecode added in v0.1.4

func Base64UrlDecode(str string) (string, error)

Base64UrlDecode base64 url 解码

func Base64UrlEncode added in v0.1.4

func Base64UrlEncode(str string) string

Base64UrlEncode base64 url 编码

func BeginDayUnix added in v0.1.2

func BeginDayUnix() int64

BeginDayUnix 获取当天 0点

func Bit2Byte added in v0.2.8

func Bit2Byte(b []uint8) []byte

Bit2Byte []uint8 -> []byte

func Bool2Byte added in v0.2.8

func Bool2Byte(b bool) []byte

Bool2Byte bool -> []byte

func Byte2Bit added in v0.2.8

func Byte2Bit(b []byte) []uint8

Byte2Bit []byte -> []uint8 (bit)

func Byte2Bool added in v0.2.8

func Byte2Bool(b []byte) bool

Byte2Bool []byte -> bool

func Byte2Float32 added in v0.2.8

func Byte2Float32(b []byte) float32

Byte2Float32 []byte -> float32

func Byte2Float64 added in v0.2.8

func Byte2Float64(b []byte) float64

Byte2Float64 []byte -> float64

func Byte2Int added in v0.2.8

func Byte2Int(b []byte) int

Byte2Int []byte -> int

func Byte2Int64 added in v0.2.8

func Byte2Int64(b []byte) int64

Byte2Int64 []byte -> int64

func Byte2Str added in v0.1.4

func Byte2Str(b []byte) string

Byte2Str []byte -> string

func ByteToBinaryString added in v0.1.4

func ByteToBinaryString(data byte) (str string)

ByteToBinaryString 字节 -> 二进制字符串

func ByteToGBK added in v0.3.5

func ByteToGBK(strBuf []byte) []byte

ByteToGBK byte -> gbk byte

func ByteToUTF8 added in v0.3.5

func ByteToUTF8(strBuf []byte) []byte

ByteToUTF8 byte -> utf8 byte

func CPUMax added in v0.1.11

func CPUMax()

CPUMax 多核执行

func Chdir added in v0.2.8

func Chdir(dir string) error

Chdir

func CleaningStr added in v0.0.11

func CleaningStr(str string) string

CleaningStr 清理字符串前后空白 和回车 换行符号

func CloseLog added in v0.3.6

func CloseLog()

CloseLog 关闭日志

func ConvertByte2String added in v0.1.4

func ConvertByte2String(byte []byte, charset Charset) string

ConvertByte2String 编码转换

func ConvertGBK2Str added in v0.3.5

func ConvertGBK2Str(gbkStr string) string

ConvertGBK2Str 将GBK编码的字符串转换为utf-8编码

func ConvertStr2GBK added in v0.3.5

func ConvertStr2GBK(str string) string

ConvertStr2GBK 将utf-8编码的字符串转换为GBK编码

func CopySlice added in v0.2.1

func CopySlice(s []interface{}) []interface{}

CopySlice Copy slice

func CopySliceInt added in v0.2.1

func CopySliceInt(s []int) []int

CopySliceInt

func CopySliceInt64 added in v0.2.1

func CopySliceInt64(s []int64) []int64

CopySliceInt64

func CopySliceStr added in v0.2.1

func CopySliceStr(s []string) []string

CopySliceStr

func DayAgo added in v0.2.1

func DayAgo(i int) int64

DayAgo 获取多少天前的时间戳

func Daydiff added in v0.1.4

func Daydiff(beginDay string, endDay string) int

Daydiff 两个时间字符串的日期差

func Debug added in v0.2.8

func Debug(args ...interface{})

Debug 日志-调试

func DebugTimes added in v0.3.7

func DebugTimes(times int, args ...interface{})

DebugTimes 日志-调试, 指定日志代码位置的定位调用层级

func Debugf added in v0.2.8

func Debugf(format string, args ...interface{})

Debugf 日志-调试

func DebugfTimes added in v0.3.7

func DebugfTimes(format string, times int, args ...interface{})

DebugfTimes 日志-调试, 指定日志代码位置的定位调用层级

func DecodeByte added in v0.2.8

func DecodeByte(b []byte) (interface{}, error)

DecodeByte decode byte

func DeepCopy added in v0.2.9

func DeepCopy(dst, src interface{}) error

func EncodeByte added in v0.2.8

func EncodeByte(v interface{}) []byte

EncodeByte encode byte

func EndDayUnix added in v0.1.2

func EndDayUnix() int64

EndDayUnix 获取当天 24点

func Error added in v0.2.8

func Error(args ...interface{})

Error 日志-错误

func ErrorTimes added in v0.3.7

func ErrorTimes(times int, args ...interface{})

ErrorTimes 日志-错误, 指定日志代码位置的定位调用层级

func Errorf added in v0.2.8

func Errorf(format string, args ...interface{})

Errorf 日志-错误

func ErrorfTimes added in v0.3.7

func ErrorfTimes(format string, times int, args ...interface{})

ErrorfTimes 日志-错误, 指定日志代码位置的定位调用层级

func Exists added in v0.2.8

func Exists(path string) bool

Exists

func FileMd5 added in v0.1.4

func FileMd5(path string) (string, error)

FileMd5 file md5 文件md5

func FileMd5sum added in v0.1.9

func FileMd5sum(fileName string) string

FileMd5sum 文件 Md5

func FileSizeFormat added in v0.1.1

func FileSizeFormat(fileSize int64) (size string)

FileSizeFormat 字节的单位转换 保留两位小数

func Float322Byte added in v0.2.8

func Float322Byte(f float32) []byte

Float322Byte float32 -> []byte

func Float322Uint32 added in v0.2.8

func Float322Uint32(f float32) uint32

Float322Uint32 float32 -> uint32

func Float642Byte added in v0.2.8

func Float642Byte(f float64) []byte

Float642Byte float64 -> []byte

func Float642Uint64 added in v0.2.8

func Float642Uint64(f float64) uint64

Float642Uint64 float64 -> uint64

func GB18030To added in v0.2.8

func GB18030To(dstCharset string, src string) (dst string, err error)

GB18030To

func GB2312To added in v0.2.8

func GB2312To(dstCharset string, src string) (dst string, err error)

GB2312To

func GDKTo added in v0.2.8

func GDKTo(dstCharset string, src string) (dst string, err error)

GDKTo

func GetAgent added in v0.0.4

func GetAgent(agentType UserAgentType) string

GetAgent 随机获取那种类型的 user-agent

func GetNowPath added in v0.1.5

func GetNowPath() string

GetNowPath 获取当前运行路径

func GetPointClassHTML added in v0.3.7

func GetPointClassHTML(htmlStr, label, val string) ([]string, error)

GetPointClassHTML 获取指定标签class属性的html

func GetPointHTML added in v0.3.7

func GetPointHTML(htmlStr, label, attr, val string) ([]string, error)

GetPointHTML 获取指定位置的HTML, 用标签, 标签属性, 属性值来定位

func GetPointIDHTML added in v0.3.7

func GetPointIDHTML(htmlStr, label, val string) ([]string, error)

GetPointIDHTML 获取指定标签id属性的html

func GetWD added in v0.3.5

func GetWD() string

GetWD 获取当前工作目录

func GzipCompress added in v0.3.5

func GzipCompress(src []byte) []byte

GzipCompress

func GzipDecompress added in v0.3.5

func GzipDecompress(src []byte) []byte

GzipDecompress

func HZGB2312To added in v0.2.8

func HZGB2312To(dstCharset string, src string) (dst string, err error)

HZGB2312To

func Hex2Int added in v0.2.4

func Hex2Int(s string) int

Hex2Int hex -> int

func Hex2Int64 added in v0.2.4

func Hex2Int64(s string) int64

Hex2Int64 hex -> int

func HmacMD5 added in v0.1.18

func HmacMD5(str, key string) string

HmacMD5

func HmacSHA1 added in v0.1.18

func HmacSHA1(str, key string) string

HmacSHA1

func HmacSHA256 added in v0.1.18

func HmacSHA256(str, key string) string

HmacSHA256

func HmacSHA512 added in v0.1.18

func HmacSHA512(str, key string) string

HmacSHA512

func HourAgo added in v0.2.1

func HourAgo(i int) int64

HourAgo 获取多少小时前的时间戳

func HumanFriendlyTraffic added in v0.2.4

func HumanFriendlyTraffic(bytes uint64) string

HumanFriendlyTraffic

func IF added in v0.1.12

func IF(condition bool, a, b interface{}) interface{}

IF 三元表达式 use: IF(a>b, a, b).(int)

func Info added in v0.2.8

func Info(args ...interface{})

Info 日志-信息

func InfoTimes added in v0.2.8

func InfoTimes(times int, args ...interface{})

InfoTimes 日志-信息, 指定日志代码位置的定位调用层级

func Infof added in v0.2.8

func Infof(format string, args ...interface{})

Infof 日志-信息

func InfofTimes added in v0.3.1

func InfofTimes(format string, times int, args ...interface{})

InfofTimes 日志-信息, 指定日志代码位置的定位调用层级

func Int2Byte added in v0.2.8

func Int2Byte(i int) []byte

Int2Byte int -> []byte

func Int2Hex added in v0.2.4

func Int2Hex(i int64) string

Int2Hex int -> hex

func Int642Byte added in v0.2.8

func Int642Byte(i int64) []byte

Int642Byte int64 -> []byte

func Int642Hex added in v0.2.4

func Int642Hex(i int64) string

Int642Hex int64 -> hex

func IsAllCapital added in v0.2.4

func IsAllCapital(str string) bool

IsAllCapital 验证是否全大写

func IsAllLower added in v0.2.4

func IsAllLower(str string) bool

IsAllLower 验证是否全小写

func IsBase64 added in v0.3.4

func IsBase64(str string) bool

IsBase64 是否是base64

func IsChinese added in v0.2.4

func IsChinese(str string) bool

IsChinese 验证是否含有汉字

func IsChineseAll added in v0.2.4

func IsChineseAll(str string) bool

IsChineseAll 验证是否是全汉字

func IsChineseMoney added in v0.2.4

func IsChineseMoney(str string) bool

IsChineseMoney 验证是否是中文钱大写

func IsChineseN added in v0.2.4

func IsChineseN(str string, number int) bool

IsChineseN 验证是否含有number个汉字

func IsChineseNumber added in v0.2.4

func IsChineseNumber(str string) bool

IsChineseNumber 验证是否全是汉字数字

func IsContainStr added in v0.1.4

func IsContainStr(items []string, item string) bool

IsContainStr 字符串是否等于items中的某个元素

func IsDNSName added in v0.3.4

func IsDNSName(str string) bool

IsDNSName 是否是dns 名称

func IsDir added in v0.2.8

func IsDir(path string) bool

IsDir

func IsDomain added in v0.2.4

func IsDomain(str string) bool

IsDomain 验证域名

func IsElementStr added in v0.1.9

func IsElementStr(listData []string, element string) bool

IsElementStr 判断字符串是否与数组里的某个字符串相同

func IsEngAll added in v0.2.4

func IsEngAll(str string) bool

IsEngAll 验证是否是全英文

func IsEngLen added in v0.2.4

func IsEngLen(str string, l int) bool

IsEngLen 验证是否含不超过len个英文字符

func IsEngNumber added in v0.2.4

func IsEngNumber(str string) bool

IsEngNumber 验证是否是英文和数字

func IsFile added in v0.2.8

func IsFile(path string) bool

IsFile

func IsFloat added in v0.2.4

func IsFloat(str string) bool

IsFloat 验证是否是标准正负小数(123. 不是小数)

func IsFloat2Len added in v0.2.4

func IsFloat2Len(str string, l int) bool

IsFloat2Len 验证是否含有带不超过len个小数的小数

func IsFullWidth added in v0.3.4

func IsFullWidth(str string) bool

IsFullWidth 是否是全角字符

func IsHalfWidth added in v0.3.4

func IsHalfWidth(str string) bool

IsHalfWidth 是否是半角字符

func IsHaveCapital added in v0.2.4

func IsHaveCapital(str string) bool

IsHaveCapital 验证是否有大写

func IsHaveKey added in v0.3.8

func IsHaveKey(data map[string]interface{}, key string) bool

IsHaveKey map[string]interface{} 是否存在 输入的key

func IsHaveLower added in v0.2.4

func IsHaveLower(str string) bool

IsHaveLower 验证是否有小写

func IsIP added in v0.2.4

func IsIP(str string) bool

IsIP IP地址:((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))

func IsIPv4 added in v0.3.4

func IsIPv4(str string) bool

IsIPv4 是否是ipv4

func IsInSlice added in v0.2.1

func IsInSlice(s []interface{}, v interface{}) bool

IsInSlice

func IsJson added in v0.3.8

func IsJson(str string) bool

IsJson 是否是json格式

func IsLandline added in v0.2.4

func IsLandline(str string) bool

IsLandline 验证电话号码("XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX):

func IsLatitude added in v0.3.4

func IsLatitude(str string) bool

IsLatitude 是否是纬度

func IsLeastCapital added in v0.2.4

func IsLeastCapital(str string, n int) bool

IsLeastCapital 验证不低于n个大写字母

func IsLeastLower added in v0.2.4

func IsLeastLower(str string, n int) bool

IsLeastLower 验证不低于n个小写字母

func IsLeastNumber added in v0.2.4

func IsLeastNumber(str string, n int) bool

IsLeastNumber 验证不低于n个数字

func IsLeastSpecial added in v0.2.4

func IsLeastSpecial(str string, n int) bool

IsLeastSpecial 验证不低于n特殊字符

func IsLongitude added in v0.3.4

func IsLongitude(str string) bool

IsLongitude 是否是经度

func IsNumber added in v0.2.4

func IsNumber(str string) bool

IsNumber 验证是否含有number

func IsNumber2Heard added in v0.2.4

func IsNumber2Heard(str string, n int) bool

IsNumber2Heard 验证是否含有n开头的number

func IsNumber2Len added in v0.2.4

func IsNumber2Len(str string, l int) bool

IsNumber2Len 验证是否含有连续长度不超过长度l的number

func IsPhone added in v0.2.4

func IsPhone(str string) bool

IsPhone 验证手机号码

func IsRGB added in v0.3.4

func IsRGB(str string) bool

IsRGB 是否是 rgb

func IsURL added in v0.2.4

func IsURL(str string) bool

IsURL 验证URL

func IsUUID3 added in v0.3.4

func IsUUID3(str string) bool

IsUUID3 是否是uuid

func IsUUID4 added in v0.3.4

func IsUUID4(str string) bool

IsUUID4 是否是uuid

func IsUUID5 added in v0.3.4

func IsUUID5(str string) bool

IsUUID5 是否是uuid

func IsUnixPath added in v0.3.4

func IsUnixPath(str string) bool

IsUnixPath 是否是unix路径

func IsUtf8 added in v0.3.5

func IsUtf8(buf []byte) bool

IsUtf8

func IsWindowsPath added in v0.3.4

func IsWindowsPath(str string) bool

IsWindowsPath 是否是windos路径

func IsXMLFile added in v0.3.4

func IsXMLFile(str string) bool

IsXMLFile 是否三xml文件

func Json2Map added in v0.1.3

func Json2Map(str string) (map[string]interface{}, error)

Json2Map json -> map

func JsonFind added in v0.3.8

func JsonFind(jsonStr, find string) (interface{}, error)

==================================== json find JsonFind 按路径寻找指定json值 用法参考 ./_examples/json/main.go @find : 寻找路径,与目录的url类似, 下面是一个例子: json: {a:[{b:1},{b:2}]} find=/a/[0] => {b:1} find=a/[0]/b => 1

func JsonFind2Arr added in v0.3.8

func JsonFind2Arr(jsonStr, find string) ([]interface{}, error)

JsonFind2Arr 寻找json,输出 []interface{}

func JsonFind2Json added in v0.3.8

func JsonFind2Json(jsonStr, find string) (string, error)

JsonFind2Json 寻找json,输出 json格式字符串

func JsonFind2Map added in v0.3.8

func JsonFind2Map(jsonStr, find string) (map[string]interface{}, error)

JsonFind2Map 寻找json,输出 map[string]interface{}

func JwtDecrypt added in v0.2.7

func JwtDecrypt(tokenString, secret string) (data map[string]interface{}, err error)

JwtDecrypt

func JwtEncrypt added in v0.2.7

func JwtEncrypt(data map[string]interface{}, secret, method string) (string, error)

JwtEncrypt

func JwtEncrypt256 added in v0.2.7

func JwtEncrypt256(data map[string]interface{}, secret string) (string, error)

JwtEncrypt256

func JwtEncrypt384 added in v0.2.7

func JwtEncrypt384(data map[string]interface{}, secret string) (string, error)

JwtEncrypt384

func JwtEncrypt512 added in v0.2.7

func JwtEncrypt512(data map[string]interface{}, secret string) (string, error)

JwtEncrypt512

func MD5 added in v0.0.10

func MD5(str string) string

MD5

func Map2Json added in v0.2.1

func Map2Json(m interface{}) (string, error)

Map2Json map -> json

func Map2Slice added in v0.2.8

func Map2Slice(data interface{}) []interface{}

Map2Slice Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"]

func MapCopy added in v0.2.8

func MapCopy(data map[string]interface{}) (copy map[string]interface{})

func MapMergeCopy added in v0.2.8

func MapMergeCopy(src ...map[string]interface{}) (copy map[string]interface{})

func MapStr2Any added in v0.2.4

func MapStr2Any(m map[string]string) map[string]interface{}

MapStr2Any map[string]string -> map[string]interface{}

func MinuteAgo added in v0.2.1

func MinuteAgo(i int) int64

MinuteAgo 获取多少分钟前的时间戳

func MongoConn added in v0.1.4

func MongoConn()

MongoConn mongoDB客户端连接

func MongoConn1 added in v0.1.4

func MongoConn1()

MongoConn1 mongoDB客户端连接

func NewCookiePool added in v0.2.4

func NewCookiePool() *cookiePool

NewCookiePool 实例化cookie池

func NewGDMap added in v0.2.4

func NewGDMap() *gDMap

NewGDMap ues: NewGDMap().Add(k,v)

func NewMysqlDB added in v0.0.11

func NewMysqlDB(host string, port int, user, password, database string) (err error)

NewMysqlDB 给mysql对象进行连接

func OSLine added in v0.2.1

func OSLine() string

OSLine 系统对应换行符

func P2E added in v0.2.1

func P2E()

P2E panic -> error

func PBKDF2 added in v0.1.18

func PBKDF2(str, salt []byte, iterations, keySize int) []byte

PBKDF2

func PanicToError added in v0.1.3

func PanicToError(fn func()) (err error)

PanicToError panic -> error

func PathExists added in v0.1.4

func PathExists(path string)

PathExists 目录不存在则创建

func Ping added in v0.1.4

func Ping(ip string)

Ping ping IP

func Pwd added in v0.2.8

func Pwd() string

Pwd

func ReadCsvFile added in v0.1.4

func ReadCsvFile(filename string) [][]string

ReadCsvFile csv file -> [][]string 行列

func RedisDELKeys added in v0.1.2

func RedisDELKeys(rds *Rds, keys string, jobNumber int)

RedisDELKeys Del key 使用常见: 并发删除大量key

func RegBase64 added in v0.3.4

func RegBase64(str string, property ...string) []string

RegBase64 提取base64字符串

func RegDNSName added in v0.3.4

func RegDNSName(str string, property ...string) []string

RegDNSName 提取dns

func RegDelHtml added in v0.2.4

func RegDelHtml(str string) string

RegDelHtml 删除所有标签

func RegDelHtmlA added in v0.2.7

func RegDelHtmlA(str string) string

func RegDelHtmlButton added in v0.2.7

func RegDelHtmlButton(str string, property ...string) string

func RegDelHtmlCanvas added in v0.2.7

func RegDelHtmlCanvas(str string, property ...string) string

func RegDelHtmlCode added in v0.2.7

func RegDelHtmlCode(str string, property ...string) string

func RegDelHtmlH added in v0.2.7

func RegDelHtmlH(str, typeH string, property ...string) string

func RegDelHtmlHref added in v0.2.7

func RegDelHtmlHref(str string, property ...string) string

func RegDelHtmlImg added in v0.2.7

func RegDelHtmlImg(str string, property ...string) string

func RegDelHtmlInput added in v0.2.7

func RegDelHtmlInput(str string, property ...string) string

func RegDelHtmlLi added in v0.2.7

func RegDelHtmlLi(str string, property ...string) string

func RegDelHtmlMeta added in v0.2.7

func RegDelHtmlMeta(str string, property ...string) string

func RegDelHtmlP added in v0.2.7

func RegDelHtmlP(str string, property ...string) string

func RegDelHtmlSelect added in v0.2.7

func RegDelHtmlSelect(str string, property ...string) string

func RegDelHtmlSpan added in v0.2.7

func RegDelHtmlSpan(str string, property ...string) string

func RegDelHtmlSrc added in v0.2.7

func RegDelHtmlSrc(str string, property ...string) string

func RegDelHtmlTable added in v0.2.7

func RegDelHtmlTable(str string, property ...string) string

func RegDelHtmlTbody added in v0.2.7

func RegDelHtmlTbody(str string, property ...string) string

func RegDelHtmlTd added in v0.2.7

func RegDelHtmlTd(str string, property ...string) string

func RegDelHtmlTitle added in v0.2.7

func RegDelHtmlTitle(str string) string

func RegDelHtmlTr added in v0.2.7

func RegDelHtmlTr(str string) string

func RegDelHtmlUl added in v0.2.7

func RegDelHtmlUl(str string, property ...string) string

func RegDelHtmlVideo added in v0.2.7

func RegDelHtmlVideo(str string, property ...string) string

func RegDelNumber added in v0.2.4

func RegDelNumber(str string) string

RegDelNumber 删除所有数字

func RegEmail added in v0.2.4

func RegEmail(str string, property ...string) []string

RegEmail 提取邮件

func RegEmail2 added in v0.3.4

func RegEmail2(str string, property ...string) []string

RegEmail2 提取邮件

func RegFindAll added in v0.1.1

func RegFindAll(regStr, rest string) [][]string

func RegFindAllTxt added in v0.3.7

func RegFindAllTxt(regStr, rest string) (dataList []string)

func RegFloat added in v0.3.4

func RegFloat(str string, property ...string) []string

RegFloat 提取浮点型

func RegFullURL added in v0.3.4

func RegFullURL(str string, property ...string) []string

RegFullURL 提取url

func RegFullWidth added in v0.3.4

func RegFullWidth(str string, property ...string) []string

RegFullWidth 提取全角字符

func RegGUID added in v0.2.4

func RegGUID(str string, property ...string) []string

RegGUID 提取guid

func RegHalfWidth added in v0.3.4

func RegHalfWidth(str string, property ...string) []string

RegHalfWidth 提取半角字符

func RegHtmlA added in v0.1.1

func RegHtmlA(str string, property ...string) []string

func RegHtmlATxt added in v0.1.4

func RegHtmlATxt(str string, property ...string) []string

func RegHtmlButton added in v0.2.1

func RegHtmlButton(str string, property ...string) []string

func RegHtmlButtonTxt added in v0.2.1

func RegHtmlButtonTxt(str string, property ...string) []string

func RegHtmlCanvas added in v0.2.1

func RegHtmlCanvas(str string, property ...string) []string

func RegHtmlCode added in v0.2.1

func RegHtmlCode(str string, property ...string) []string

func RegHtmlCodeTxt added in v0.2.1

func RegHtmlCodeTxt(str string, property ...string) []string

func RegHtmlDiv added in v0.3.7

func RegHtmlDiv(str string, property ...string) []string

func RegHtmlDivTxt added in v0.3.7

func RegHtmlDivTxt(str string, property ...string) []string

func RegHtmlH added in v0.1.4

func RegHtmlH(str, typeH string, property ...string) []string

func RegHtmlHTxt added in v0.1.4

func RegHtmlHTxt(str, typeH string, property ...string) []string

func RegHtmlHref added in v0.1.4

func RegHtmlHref(str string, property ...string) []string

func RegHtmlHrefTxt added in v0.1.4

func RegHtmlHrefTxt(str string, property ...string) []string

func RegHtmlImg added in v0.2.1

func RegHtmlImg(str string, property ...string) []string

func RegHtmlInput added in v0.1.1

func RegHtmlInput(str string, property ...string) []string

func RegHtmlInputTxt added in v0.1.4

func RegHtmlInputTxt(str string, property ...string) []string

func RegHtmlLi added in v0.2.1

func RegHtmlLi(str string, property ...string) []string

func RegHtmlLiTxt added in v0.2.1

func RegHtmlLiTxt(str string, property ...string) []string

func RegHtmlMeta added in v0.2.1

func RegHtmlMeta(str string, property ...string) []string

func RegHtmlP added in v0.1.1

func RegHtmlP(str string, property ...string) []string

func RegHtmlPTxt added in v0.1.4

func RegHtmlPTxt(str string, property ...string) []string

func RegHtmlSelect added in v0.2.1

func RegHtmlSelect(str string, property ...string) []string

func RegHtmlSelectTxt added in v0.2.1

func RegHtmlSelectTxt(str string, property ...string) []string

func RegHtmlSpan added in v0.1.1

func RegHtmlSpan(str string, property ...string) []string

func RegHtmlSpanTxt added in v0.1.4

func RegHtmlSpanTxt(str string, property ...string) []string

func RegHtmlSrc added in v0.1.4

func RegHtmlSrc(str string, property ...string) []string

func RegHtmlSrcTxt added in v0.1.4

func RegHtmlSrcTxt(str string, property ...string) []string

func RegHtmlTable added in v0.2.1

func RegHtmlTable(str string, property ...string) []string

func RegHtmlTableOlny added in v0.3.5

func RegHtmlTableOlny(str string, property ...string) []string

func RegHtmlTableTxt added in v0.2.1

func RegHtmlTableTxt(str string, property ...string) []string

func RegHtmlTbody added in v0.1.9

func RegHtmlTbody(str string, property ...string) []string

func RegHtmlTd added in v0.1.1

func RegHtmlTd(str string, property ...string) []string

func RegHtmlTdTxt added in v0.1.4

func RegHtmlTdTxt(str string, property ...string) []string

func RegHtmlTitle added in v0.1.1

func RegHtmlTitle(str string, property ...string) []string

func RegHtmlTitleTxt added in v0.1.4

func RegHtmlTitleTxt(str string, property ...string) []string

func RegHtmlTr added in v0.1.1

func RegHtmlTr(str string, property ...string) []string

func RegHtmlTrTxt added in v0.1.4

func RegHtmlTrTxt(str string, property ...string) []string

func RegHtmlUl added in v0.2.1

func RegHtmlUl(str string, property ...string) []string

func RegHtmlUlTxt added in v0.2.1

func RegHtmlUlTxt(str string, property ...string) []string

func RegHtmlVideo added in v0.2.1

func RegHtmlVideo(str string, property ...string) []string

func RegIP added in v0.2.4

func RegIP(str string, property ...string) []string

RegIP 提取ip

func RegIPv4 added in v0.2.4

func RegIPv4(str string, property ...string) []string

RegIPv4 提取ipv4

func RegIPv6 added in v0.2.4

func RegIPv6(str string, property ...string) []string

RegIPv6 提取ipv6

func RegInt added in v0.3.4

func RegInt(str string, property ...string) []string

RegInt 提取整形

func RegLatitude added in v0.3.4

func RegLatitude(str string, property ...string) []string

RegLatitude 提取纬度

func RegLink(str string, property ...string) []string

RegLink 提取链接

func RegLongitude added in v0.3.4

func RegLongitude(str string, property ...string) []string

RegLongitude 提取经度

func RegMACAddress added in v0.2.4

func RegMACAddress(str string, property ...string) []string

RegMACAddress 提取MACAddress

func RegMD5Hex added in v0.2.4

func RegMD5Hex(str string, property ...string) []string

RegMD5Hex 提取md5

func RegRGBColor added in v0.3.4

func RegRGBColor(str string, property ...string) []string

RegRGBColor 提取RGB值

func RegSHA1Hex added in v0.2.4

func RegSHA1Hex(str string, property ...string) []string

RegSHA1Hex 提取sha1

func RegSHA256Hex added in v0.2.4

func RegSHA256Hex(str string, property ...string) []string

RegSHA256Hex 提取sha256

func RegTime added in v0.2.4

func RegTime(str string, property ...string) []string

RegTime 提取时间

func RegURLIP added in v0.3.4

func RegURLIP(str string, property ...string) []string

RegURLIP 提取 url ip

func RegURLPath added in v0.3.4

func RegURLPath(str string, property ...string) []string

RegURLPath 提取url path

func RegURLPort added in v0.3.4

func RegURLPort(str string, property ...string) []string

RegURLPort 提取url port

func RegURLSchema added in v0.3.4

func RegURLSchema(str string, property ...string) []string

RegURLSchema 提取url schema

func RegURLSubdomain added in v0.3.4

func RegURLSubdomain(str string, property ...string) []string

RegURLSubdomain 提取 url sub domain

func RegURLUsername added in v0.3.4

func RegURLUsername(str string, property ...string) []string

RegURLUsername 提取url username

func RegUUID added in v0.3.4

func RegUUID(str string, property ...string) []string

RegUUID 提取uuid

func RegUUID3 added in v0.3.4

func RegUUID3(str string, property ...string) []string

RegUUID3 提取uuid

func RegUUID4 added in v0.3.4

func RegUUID4(str string, property ...string) []string

RegUUID4 提取uuid

func RegUUID5 added in v0.3.4

func RegUUID5(str string, property ...string) []string

RegUUID5 提取uuid

func RegUnixPath added in v0.3.4

func RegUnixPath(str string, property ...string) []string

RegUnixPath 提取 unix路径

func RegWinPath added in v0.3.4

func RegWinPath(str string, property ...string) []string

RegWinPath 提取 windows路径

func ReplaceAllToOne added in v0.2.1

func ReplaceAllToOne(str string, from []string, to string) string

ReplaceAllToOne 批量统一替换字符串

func SSHClient added in v0.1.1

func SSHClient(user string, pass string, addr string) (*ssh.Client, error)

SSHClient 连接ssh addr : 主机地址, 如: 127.0.0.1:22 user : 用户 pass : 密码 返回 ssh连接

func SearchBytesIndex added in v0.1.18

func SearchBytesIndex(bSrc []byte, b byte) int

SearchBytesIndex []byte 字节切片 循环查找

func SearchDomain added in v0.1.4

func SearchDomain(ip string)

SearchDomain 搜索host

func SearchPort added in v0.1.4

func SearchPort(ipStr string, vs ...interface{})

SearchPort 扫描ip的端口

func SetAgent added in v0.1.9

func SetAgent(agentType UserAgentType, agent string)

func SetLogFile added in v0.2.8

func SetLogFile(name string)

SetLogFile 设置日志输出到的指定文件

func SetStatusCodeFailEvent added in v0.1.5

func SetStatusCodeFailEvent(code int)

将指定状态码设置为执行失败事件

func SetStatusCodeRetryEvent added in v0.1.5

func SetStatusCodeRetryEvent(code int)

将指定状态码设置为执行重试事件

func SetStatusCodeSuccessEvent added in v0.1.5

func SetStatusCodeSuccessEvent(code int)

将指定状态码设置为执行成功事件

func SimpleServer added in v0.3.6

func SimpleServer(addr string, g *grpc.Server)

SimpleServer 启动一个简单的grpc服务

func Slice2Map added in v0.2.8

func Slice2Map(slice interface{}) map[string]interface{}

Slice2Map ["K1", "v1", "K2", "v2"] => {"K1": "v1", "K2": "v2"} ["K1", "v1", "K2"] => nil

func SliceCopy added in v0.2.8

func SliceCopy(data []interface{}) []interface{}

func SliceTool added in v0.2.1

func SliceTool() *sliceTool

use : SliceTool().CopyInt64(a)

func SockerProxy added in v0.3.5

func SockerProxy(addr string)

SockerProxy 启动一个socket5代理

func StartJob added in v0.0.7

func StartJob(jobNumber int, queue TodoQueue, f func(task *Task))

StartJob 开始运行并发

func StartJobGet added in v0.0.7

func StartJobGet(jobNumber int, queue TodoQueue, vs ...interface{})

StartJobGet 并发执行Get,直到队列任务为空 jobNumber 并发数, queue 全局队列,

func StartJobPost added in v0.0.7

func StartJobPost(jobNumber int, queue TodoQueue, vs ...interface{})

StartJobPost 开始运行并发Post

func Str2Byte added in v0.2.8

func Str2Byte(s string) []byte

Str2Bytes string -> []byte

func Str2Float32 added in v0.2.9

func Str2Float32(str string) float32

Str2Float32 string -> float32

func Str2Float64 added in v0.1.1

func Str2Float64(str string) float64

Str2Float64 string -> float64

func Str2Int added in v0.2.9

func Str2Int(str string) int

Str2Int string -> int

func Str2Int32 added in v0.2.9

func Str2Int32(str string) int32

Str2Int string -> int32

func Str2Int64 added in v0.1.1

func Str2Int64(str string) int64

Str2Int64 string -> int64

func StrDeleteSpace added in v0.0.11

func StrDeleteSpace(str string) string

StrDeleteSpace 删除字符串前后的空格

func StrDuplicates added in v0.2.4

func StrDuplicates(a []string) []string

StrDuplicates 数组,切片去重和去空串

func StrToSize added in v0.2.8

func StrToSize(sizeStr string) int64

StrToSize

func StringValue added in v0.0.9

func StringValue(i interface{}) string

StringValue 任何类型返回值字符串形式

func StringValueMysql added in v0.1.12

func StringValueMysql(i interface{}) string

StringValueMysql 用于mysql字符拼接使用

func Struct2Map added in v0.1.3

func Struct2Map(obj interface{}) map[string]interface{}

Struct2Map struct -> map[string]interface{}

func Struct2MapV2 added in v0.3.7

func Struct2MapV2(obj interface{}, hasValue bool) (map[string]interface{}, error)

Struct2Map Struct -> map hasValue=true表示字段值不管是否存在都转换成map hasValue=false表示字段为空或者不为0则转换成map

func Struct2MapV3 added in v0.3.7

func Struct2MapV3(obj interface{}) map[string]interface{}

Struct2Map2 struct -> map

func TickerRun added in v0.1.4

func TickerRun(t time.Duration, runFirst bool, f func())

TickerRun 间隔运行 t: 间隔时间, runFirst: 间隔前或者后执行 f: 运行的方法

func Timestamp added in v0.1.4

func Timestamp() string

Timestamp 获取时间戳

func Timestamp2Date added in v0.3.7

func Timestamp2Date(timestamp int64) string

func ToBIG5 added in v0.2.8

func ToBIG5(srcCharset string, src string) (dst string, err error)

ToBIG5

func ToGB18030 added in v0.2.8

func ToGB18030(srcCharset string, src string) (dst string, err error)

ToGB18030

func ToGB2312 added in v0.2.8

func ToGB2312(srcCharset string, src string) (dst string, err error)

ToGB2312

func ToGDK added in v0.2.8

func ToGDK(srcCharset string, src string) (dst string, err error)

ToGDK

func ToHZGB2312 added in v0.2.8

func ToHZGB2312(srcCharset string, src string) (dst string, err error)

ToHZGB2312

func ToUTF16 added in v0.2.8

func ToUTF16(srcCharset string, src string) (dst string, err error)

ToUTF16

func ToUTF8 added in v0.2.8

func ToUTF8(srcCharset string, src string) (dst string, err error)

ToUTF8

func UTF16To added in v0.2.8

func UTF16To(dstCharset string, src string) (dst string, err error)

UTF16To

func UTF8To added in v0.2.8

func UTF8To(dstCharset string, src string) (dst string, err error)

UTF8To

func Uint82Str added in v0.1.1

func Uint82Str(bs []uint8) string

Uint82Str []uint8 -> string

func UnescapeUnicode added in v0.1.4

func UnescapeUnicode(raw []byte) ([]byte, error)

UnescapeUnicode Unicode 转码

func UnicodeDec added in v0.2.4

func UnicodeDec(raw string) string

UnicodeDec

func UnicodeDecByte added in v0.2.4

func UnicodeDecByte(raw []byte) []byte

UnicodeDecByte

func Warn added in v0.2.8

func Warn(args ...interface{})

Warn 日志-警告

func WarnTimes added in v0.3.7

func WarnTimes(times int, args ...interface{})

WarnTimes 日志-警告, 指定日志代码位置的定位调用层级

func Warnf added in v0.2.8

func Warnf(format string, args ...interface{})

Warnf 日志-警告

func WarnfTimes added in v0.3.7

func WarnfTimes(format string, times int, args ...interface{})

WarnfTimes 日志-警告, 指定日志代码位置的定位调用层级

Types

type AES added in v0.1.18

type AES interface {
	Encrypt(str, key []byte) ([]byte, error)
	Decrypt(str, key []byte) ([]byte, error)
}

AES AES interface

func NewAES added in v0.1.18

func NewAES(typeName string, arg ...[]byte) AES

NewAES : use NewAES(AES_CBC)

type Bar added in v0.2.9

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

Bar 终端显示的进度条

func (*Bar) Finish added in v0.2.9

func (bar *Bar) Finish()

func (*Bar) NewOption added in v0.2.9

func (bar *Bar) NewOption(start, total int64)

func (*Bar) NewOptionWithGraph added in v0.2.9

func (bar *Bar) NewOptionWithGraph(start, total int64, graph string)

func (*Bar) Play added in v0.2.9

func (bar *Bar) Play(cur int64)

type Charset added in v0.1.4

type Charset string

============================================ 转码 Charset 字符集类型

type Context added in v0.0.7

type Context struct {
	// Token
	Token string

	// http client
	Client *http.Client

	// http Request
	Req *http.Request

	// http Response
	Resp *http.Response

	// Error
	Err error

	// Ctx context.Context
	Ctx context.Context

	// 最大允许重试次数
	MaxTimes RetryTimes

	// 请求成功了需要处理的事件
	SucceedFunc SucceedFunc

	// 请求失败了需要处理的事件
	FailedFunc FailedFunc

	// 重试请求处理的事件,可以是更换代理,设置等待时间
	RetryFunc RetryFunc

	// 请求开始前处理的事件
	StartFunc StartFunc

	// 请求完成后处理的事件
	EndFunc EndFunc

	// 本次请求的任务
	// 用于有步骤的请求和并发执行请求
	Task *Task

	// 请求返回的结果
	RespBody []byte

	// job编号
	// 在执行多并发执行抓取任务,每个并发都有一个编号
	// 这个编号是递增分配的
	JobNumber int

	// 请求的响应时间 单位ms
	Ms time.Duration

	// 是否显示日志, 默认是显示的
	IsLog IsLog

	// 输出字符串
	Text string

	// 输出Json
	Json string

	// 输出xml
	Xml string

	// 输出HTML
	Html string

	// 请求上下文参数
	Param map[string]interface{}
	// contains filtered or unexported fields
}

Context 请求上下文

func Delete added in v0.1.1

func Delete(url string, vs ...interface{}) (*Context, error)

Delete 执行delete请求,请求内容在上下文 *Context 里

func Get

func Get(url string, vs ...interface{}) (*Context, error)

Get 执行get请求,请求内容在上下文 *Context 里

func NewDelete added in v0.1.9

func NewDelete(url string, vs ...interface{}) *Context

NewDelete 定义一个delete请求对象,请求需执行 XX.Do()

func NewGet added in v0.1.9

func NewGet(url string, vs ...interface{}) *Context

NewGet 定义一个get请求对象,请求需执行 XX.Do()

func NewOptions added in v0.1.9

func NewOptions(url string, vs ...interface{}) *Context

NewOptions 定义一个options请求对象,请求需执行 XX.Do()

func NewPost added in v0.1.9

func NewPost(url string, data []byte, contentType string, vs ...interface{}) *Context

NewPost 定义一个post请求对象,请求需执行 XX.Do()

func NewPostForm added in v0.2.7

func NewPostForm(u string, data map[string]string, vs ...interface{}) *Context

NewPostForm 定义一个post请求对象,请求参数为fromdata,请求需执行 XX.Do()

func NewPut added in v0.1.9

func NewPut(url string, data []byte, contentType string, vs ...interface{}) *Context

NewPut 定义一个put请求对象,请求需执行 XX.Do()

func NewRequest added in v0.1.9

func NewRequest(url, method string, data []byte, contentType string, vs ...interface{}) *Context

NewRequest 请求

func Options added in v0.1.1

func Options(url string, vs ...interface{}) (*Context, error)

Options 执行options请求,请求内容在上下文 *Context 里

func Post added in v0.0.7

func Post(url string, data []byte, contentType string, vs ...interface{}) (*Context, error)

Post 执行post请求,请求内容在上下文 *Context 里

func PostFile added in v0.2.9

func PostFile(url, paramName, filePath string, vs ...interface{}) *Context

PostFile 定义一个post上传文件的请求对象,请求需执行 XX.Do()

func PostForm added in v0.1.9

func PostForm(url string, data map[string]string, vs ...interface{}) (*Context, error)

PostForm 执行post请求,请求参数为fromdata,请求内容在上下文 *Context 里

func PostJson added in v0.0.7

func PostJson(url string, jsonStr string, vs ...interface{}) (*Context, error)

PostJson 执行post请求,请求参数为json,请求内容在上下文 *Context 里

func Put added in v0.1.1

func Put(url string, data []byte, contentType string, vs ...interface{}) (*Context, error)

Put 执行put请求,请求内容在上下文 *Context 里

func Req

func Req(request *http.Request, vs ...interface{}) *Context

Req 初始化请求

func Request added in v0.0.7

func Request(url, method string, data []byte, contentType string, vs ...interface{}) (*Context, error)

Request 请求

func Upload added in v0.1.1

func Upload(url, savePath string, vs ...interface{}) (*Context, error)

Upload 上传文件

func (*Context) AddCookie added in v0.0.10

func (c *Context) AddCookie(k, v string) *Context

AddCookie 给请求添加Cookie

func (*Context) AddHeader added in v0.0.10

func (c *Context) AddHeader(k, v string) *Context

AddHeader 给请求添加Header

func (*Context) AddParam added in v0.2.9

func (c *Context) AddParam(key string, val interface{})

AddParam 添加上下文参数

func (*Context) CheckMd5 added in v0.1.9

func (c *Context) CheckMd5() string

CheckMd5 本次请求上下文包含输出结果的md5值

func (*Context) CheckReqMd5 added in v0.1.9

func (c *Context) CheckReqMd5() string

CheckReqMd5 本次请求的md5值, url+reqBodyBytes+method

func (*Context) CloseLog added in v0.1.5

func (c *Context) CloseLog()

CloseLog 关闭日志打印

func (*Context) CloseRetry added in v0.1.6

func (c *Context) CloseRetry()

CloseRetry 关闭重试

func (*Context) CookieNext added in v0.1.1

func (c *Context) CookieNext() error

CookieNext 使用上下文cookies

func (*Context) DelParam added in v0.2.9

func (c *Context) DelParam(key string)

DelParam 删除上下文参数

func (*Context) Do added in v0.0.7

func (c *Context) Do() func()

Do 执行请求

func (*Context) GetParam added in v0.2.9

func (c *Context) GetParam(key string) interface{}

GetParam 获取上下文参数

func (*Context) GetRespHeader added in v0.2.9

func (c *Context) GetRespHeader() string

GetRespHeader 获取Response的Header

func (*Context) GetRetryTimes added in v0.3.4

func (c *Context) GetRetryTimes() int

GetRetryTimes 获取当前重试最大次数

func (*Context) OpenErr2Retry added in v0.1.6

func (c *Context) OpenErr2Retry()

OpenErr2Retry 开启请求失败都执行retry

func (*Context) RespBodyArr added in v0.1.12

func (c *Context) RespBodyArr() []interface{}

RespBodyArr 请求到的Body转换为[]interface{}类型

func (*Context) RespBodyHtml added in v0.2.8

func (c *Context) RespBodyHtml() string

RespBodyHtml 请求到的Body转换为string类型的html格式

func (*Context) RespBodyMap added in v0.1.12

func (c *Context) RespBodyMap() map[string]interface{}

RespBodyMap 请求到的Body转换为map[string]interface{}类型

func (*Context) RespBodyString added in v0.1.9

func (c *Context) RespBodyString() string

RespBodyString 请求到的Body转换为string类型

func (*Context) RespContentLength added in v0.2.9

func (c *Context) RespContentLength() int64

RespContentLength 获取Response ContentLength的值

func (*Context) SetFailedFunc added in v0.0.7

func (c *Context) SetFailedFunc(failedFunc func(c *Context)) *Context

SetFailedFunc 设置错误后执行的方法

func (*Context) SetProxy added in v0.1.9

func (c *Context) SetProxy(proxyUrl string) *Context

SetProxy 给请求设置代理

func (*Context) SetProxyFunc added in v0.1.14

func (c *Context) SetProxyFunc(f func() *http.Transport) *Context

SetProxyFunc 给请求设置代理函数 f func() *http.Transport

func (*Context) SetProxyPool added in v0.3.1

func (c *Context) SetProxyPool(pool *ProxyPool) *Context

SetProxyPool 给请求设置代理池

func (*Context) SetRetryFunc added in v0.0.7

func (c *Context) SetRetryFunc(retryFunc func(c *Context)) *Context

SetRetryFunc 重试请求前执行的方法

func (*Context) SetRetryTimes added in v0.0.7

func (c *Context) SetRetryTimes(times int) *Context

SetRetryTimes 设置重试最大次数,如果超过这个次数还没有请求成功,请求结束,返回一个错误;

func (*Context) SetSleep added in v0.3.4

func (c *Context) SetSleep(i int) *Context

SetSleep 设置请求延迟时间,单位秒

func (*Context) SetSleepRand added in v0.3.4

func (c *Context) SetSleepRand(min, max int) *Context

SetSleepRand 设置延迟随机时间,单位秒

func (*Context) SetSucceedFunc added in v0.0.7

func (c *Context) SetSucceedFunc(successFunc func(c *Context)) *Context

SetSucceedFunc 设置成功后执行的方法

func (*Context) Upload added in v0.1.1

func (c *Context) Upload(filePath string) func()

Upload 下载

type Cookie map[string]string

func NewCookie added in v0.2.7

func NewCookie(data map[string]string) Cookie

NewCookie 新建Cookie

func (Cookie) Delete added in v0.2.7

func (c Cookie) Delete(key string) Cookie

Delete Cookie Delete

func (Cookie) Set added in v0.2.7

func (c Cookie) Set(key, value string) Cookie

Set Cookie Set

type Csv added in v0.1.1

type Csv struct {
	FileName string
	W        *csv.Writer
	R        *csv.Reader
}

Csv Csv格式文件

func NewCSV added in v0.2.4

func NewCSV(fileName string) (*Csv, error)

NewCSV 新创建一个csv对象

func (*Csv) Add added in v0.1.1

func (c *Csv) Add(data []string) error

Add 写入csv

func (*Csv) Close added in v0.3.4

func (c *Csv) Close()

func (*Csv) ReadAll added in v0.1.1

func (c *Csv) ReadAll() ([][]string, error)

ReadAll 读取所有

type DES added in v0.1.18

type DES interface {
	Encrypt(str, key []byte) ([]byte, error)
	Decrypt(str, key []byte) ([]byte, error)
}

DES DES interface

func NewDES added in v0.1.18

func NewDES(typeName string, arg ...[]byte) DES

NewDES : use NewDES(DES_CBC)

type EndFunc added in v0.0.7

type EndFunc func(c *Context)

EndFunc 请求流程结束后执行的方法类型

type Err2Retry added in v0.1.8

type Err2Retry bool

设置遇到错误执行 Retry 事件

type FailedFunc added in v0.0.7

type FailedFunc func(c *Context)

FailedFunc 请求失败执行的方法类型

type FormData added in v0.2.7

type FormData map[string]string

FormData form data

type GDMapApi added in v0.2.4

type GDMapApi interface {
	Add(key string, value interface{}) *gDMap
	Get(key string) interface{}
	Del(key string) *gDMap
	Len() int
	KeyList() []string
	AddMap(data map[string]interface{}) *gDMap
	Range(f func(k string, v interface{})) *gDMap
	RangeAt(f func(id int, k string, v interface{})) *gDMap
	CheckValue(value interface{}) bool // 检查是否存在某个值
	Reverse()                          //反序
}

GDMapApi 固定顺序 Map 接口

type Header map[string]string

func NewHeader added in v0.2.4

func NewHeader(data map[string]string) Header

NewHeader 新建Header

func (Header) Delete added in v0.2.4

func (h Header) Delete(key string) Header

Delete Header Delete

func (Header) Set added in v0.2.4

func (h Header) Set(key, value string) Header

Set Header Set

type HttpPackage added in v0.3.4

type HttpPackage struct {
	Url         *url.URL
	Body        []byte
	ContentType string
	Header      map[string][]string
}

HttpPackage 代理服务抓取到的HTTP的包

func (*HttpPackage) Html added in v0.3.4

func (pack *HttpPackage) Html() string

Html 数据类型是html

func (*HttpPackage) Img2Base64 added in v0.3.4

func (pack *HttpPackage) Img2Base64() string

Img2Base64 如果数据类型是image 就转换成base64的图片输出

func (*HttpPackage) Json added in v0.3.4

func (pack *HttpPackage) Json() string

Json 数据类型是json

func (*HttpPackage) SaveImage added in v0.3.4

func (pack *HttpPackage) SaveImage(path string) error

SaveImage 如果数据类型是image 就保存图片

func (*HttpPackage) ToFile added in v0.3.5

func (pack *HttpPackage) ToFile(path string) error

ToFile 抓取到的数据类型保存到文件

func (*HttpPackage) Txt added in v0.3.5

func (pack *HttpPackage) Txt() string

Txt 数据类型是txt

type Intercept added in v0.3.4

type Intercept struct {
	Ip              string
	HttpPackageFunc func(pack *HttpPackage)
}

Intercept http/s 代理与抓包

func (*Intercept) RunHttpIntercept added in v0.3.4

func (ipt *Intercept) RunHttpIntercept()

RunHttpIntercept 启动 http/s 代理与抓包服务

func (*Intercept) RunServer added in v0.3.4

func (ipt *Intercept) RunServer()

RunServer 启动 http/s 代理与抓包服务

type IsLog added in v0.1.9

type IsLog bool

IsLog 是否开启全局日志

type Level added in v0.2.8

type Level int

Level 日志等级

type Mongo added in v0.1.4

type Mongo struct {
	User        string
	Password    string
	Host        string
	Port        string
	Conn        *mongo.Client
	Database    *mongo.Database
	Collection  *mongo.Collection
	MaxPoolSize int
	TimeOut     time.Duration
}

Mongo

func NewMongo added in v0.1.4

func NewMongo(user, password, host, port string) (*Mongo, error)

NewMongo 新建mongoDB客户端对象

func (*Mongo) GetCollection added in v0.1.4

func (m *Mongo) GetCollection(dbname, name string)

GetCollection 连接mongodb 的db的集合 dbname:DB名; name:集合名

func (*Mongo) GetConn added in v0.1.4

func (m *Mongo) GetConn() (err error)

GetConn 建立mongodb 连接

func (*Mongo) GetDB added in v0.1.4

func (m *Mongo) GetDB(dbname string)

GetDB 连接mongodb 的db dbname:DB名

func (*Mongo) Insert added in v0.1.4

func (m *Mongo) Insert(document interface{}) error

Insert 插入数据 document:可以是 Struct, 是 Slice

type Mysql added in v0.0.9

type Mysql struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

Mysql 客户端对象

func GetMysqlDBConn added in v0.1.3

func GetMysqlDBConn() (*Mysql, error)

GetMysqlDBConn 获取mysql 连接

func NewMysql added in v0.0.9

func NewMysql(host string, port int, user, password, database string) (*Mysql, error)

NewMysql 创建一个mysql对象

func (*Mysql) CloseLog added in v0.0.11

func (m *Mysql) CloseLog()

CloseLog 关闭日志

func (*Mysql) Conn added in v0.0.9

func (m *Mysql) Conn() (err error)

Conn 连接mysql

func (*Mysql) Delete added in v0.1.1

func (m *Mysql) Delete(sql string) error

Delete 执行delete sql

func (*Mysql) DeleteTable added in v0.2.9

func (m *Mysql) DeleteTable(tableName string) error

DeleteTable 删除表

func (*Mysql) Describe added in v0.0.9

func (m *Mysql) Describe(table string) (*tableDescribe, error)

Describe 获取表结构

func (*Mysql) Exec added in v0.1.1

func (m *Mysql) Exec(sql string) error

Exec 执行sql

func (*Mysql) GetFieldList added in v0.3.4

func (m *Mysql) GetFieldList(table string) (fieldList []string)

GetFieldList 获取表字段

func (*Mysql) HasTable added in v0.2.9

func (m *Mysql) HasTable(tableName string) bool

HasTable 判断表是否存

func (*Mysql) Insert added in v0.0.9

func (m *Mysql) Insert(table string, fieldData map[string]interface{}) error

Insert 新增数据

func (*Mysql) InsertAt added in v0.1.17

func (m *Mysql) InsertAt(table string, fieldData map[string]interface{}) error

InsertAt 新增数据 如果没有表则先创建表

func (*Mysql) InsertAtGd added in v0.2.7

func (m *Mysql) InsertAtGd(table string, fieldData *gDMap) error

InsertAtGd 固定顺序map写入

func (*Mysql) InsertAtJson added in v0.3.4

func (m *Mysql) InsertAtJson(table, jsonStr string) error

InsertAtJson json字符串存入数据库

func (*Mysql) IsHaveTable added in v0.1.17

func (m *Mysql) IsHaveTable(table string) bool

IsHaveTable 表是否存在

func (*Mysql) NewTable added in v0.0.9

func (m *Mysql) NewTable(table string, fields map[string]string) error

NewTable 创建表 字段顺序不固定 fields 字段:类型; name:varchar(10);

func (*Mysql) NewTableGd added in v0.2.7

func (m *Mysql) NewTableGd(table string, fields *gDMap) error

NewTableGd 创建新的固定map顺序为字段的表

func (*Mysql) Query added in v0.1.9

func (m *Mysql) Query(sql string) ([]map[string]string, error)

Query 执行selete sql

func (*Mysql) Select added in v0.0.9

func (m *Mysql) Select(sql string) ([]map[string]string, error)

Select 查询语句 返回 map

func (*Mysql) SetMaxIdleConn added in v0.1.11

func (m *Mysql) SetMaxIdleConn(number int)

SetMaxIdleConn

func (*Mysql) SetMaxOpenConn added in v0.1.11

func (m *Mysql) SetMaxOpenConn(number int)

SetMaxOpenConn

func (*Mysql) ToVarChar added in v0.1.9

func (m *Mysql) ToVarChar(data interface{}) string

ToVarChar 写入mysql 的字符类型

func (*Mysql) ToXls added in v0.3.4

func (m *Mysql) ToXls(sql, outPath string)

ToXls 数据库查询输出到excel

func (*Mysql) Update added in v0.1.1

func (m *Mysql) Update(sql string) error

Update 更新sql

type ProxyIP added in v0.3.1

type ProxyIP struct {
	IP    string
	Post  int
	User  string
	Pass  string // 密码
	IsTLS bool   // 是否是 https
}

ProxyIP 代理IP

func NewProxyIP added in v0.3.1

func NewProxyIP(ip string, port int, user, pass string, isTls bool) *ProxyIP

NewProxyIP 实例化代理IP

func (*ProxyIP) String added in v0.3.1

func (p *ProxyIP) String() string

String 代理IP输出

type ProxyPool added in v0.3.1

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

ProxyPool 代理池

func NewProxyPool added in v0.3.1

func NewProxyPool() *ProxyPool

NewProxyPool 实例化代理池

func (*ProxyPool) Add added in v0.3.1

func (p *ProxyPool) Add(proxyIP *ProxyIP)

Add 代理池添加代理

func (*ProxyPool) Del added in v0.3.1

func (p *ProxyPool) Del(n int)

Del 代理池删除代理

func (*ProxyPool) Get added in v0.3.1

func (p *ProxyPool) Get() (string, int)

Get 代理池按获取顺序获取一个代理

type ProxyUrl added in v0.1.9

type ProxyUrl string

ProxyUrl 全局代理地址,一个代理,多个代理请使用代理池ProxyPool

type Queue added in v0.0.4

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

Queue 队列

func (*Queue) Add added in v0.0.4

func (q *Queue) Add(task *Task) error

Add 向队列中添加元素

func (*Queue) Clear added in v0.0.4

func (q *Queue) Clear() bool

func (*Queue) IsEmpty added in v0.0.4

func (q *Queue) IsEmpty() bool

func (*Queue) Poll added in v0.0.4

func (q *Queue) Poll() *Task

Poll 移除队列中最前面的额元素

func (*Queue) Print added in v0.0.4

func (q *Queue) Print()

func (*Queue) Size added in v0.0.4

func (q *Queue) Size() int

type Rds added in v0.1.2

type Rds struct {
	SSHUser       string
	SSHPassword   string
	SSHAddr       string
	RedisHost     string
	RedisPost     string
	RedisPassword string

	// redis DB
	RedisDB int

	// 单个连接
	Conn redis.Conn

	//	最大闲置数,用于redis连接池
	RedisMaxIdle int

	//	最大连接数
	RedisMaxActive int

	//	单条连接Timeout
	RedisIdleTimeoutSec int

	// 连接池
	Pool *redis.Pool
}

Rds Redis客户端

func NewRedis added in v0.1.2

func NewRedis(host, port, password string, db int, vs ...interface{}) *Rds

NewRedis 新建Redis客户端对象

func NewRedisPool added in v0.1.2

func NewRedisPool(host, port, password string, db, maxIdle, maxActive, idleTimeoutSec int, vs ...interface{}) *Rds

NewRedisPool 新建Redis连接池对象

func (*Rds) GetConn added in v0.1.2

func (r *Rds) GetConn() redis.Conn

GetConn 获取redis连接

func (*Rds) RedisConn added in v0.1.2

func (r *Rds) RedisConn() (err error)

RedisConn redis连接

func (*Rds) RedisPool added in v0.1.2

func (r *Rds) RedisPool() error

RedisPool 连接池连接 返回redis连接池 *redis.Pool.Get() 获取redis连接

func (*Rds) SelectDB added in v0.1.2

func (r *Rds) SelectDB(dbNumber int) error

SelectDB 切换redis db

type ReqTimeOut added in v0.0.7

type ReqTimeOut int

type ReqTimeOutMs added in v0.0.7

type ReqTimeOutMs int

type ReqUrl added in v0.0.7

type ReqUrl struct {
	Url    string
	Method string
	Params map[string]interface{}
}

单个请求地址对象

type RetryFunc added in v0.0.7

type RetryFunc func(c *Context)

RetryFunc 重试请求前执行的方法类型,是否重试来自上次请求的状态码来确定,见StatusCodeMap;

type RetryTimes added in v0.0.4

type RetryTimes int

RetryTimes 重试次数

type SSHConnInfo added in v0.1.2

type SSHConnInfo struct {
	SSHUser     string
	SSHPassword string
	SSHAddr     string
}

SSHConnInfo ssh连接通道

func NewSSHInfo added in v0.1.2

func NewSSHInfo(addr, user, password string) *SSHConnInfo

NewSSHInfo 新建ssh连接通道

type Set added in v0.1.4

type Set map[string]struct{}

================================================ Set 集合 可以用于去重

func (Set) Add added in v0.1.4

func (s Set) Add(key string)

func (Set) Delete added in v0.1.4

func (s Set) Delete(key string)

func (Set) Has added in v0.1.4

func (s Set) Has(key string) bool

type Sleep added in v0.2.4

type Sleep time.Duration

func SetSleep added in v0.2.4

func SetSleep(min, max int) Sleep

SetSleep 设置请求随机休眠时间, 单位秒

func SetSleepMs added in v0.2.4

func SetSleepMs(min, max int) Sleep

SetSleepMs 设置请求随机休眠时间, 单位毫秒

type Stack added in v0.1.4

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

================================================ Stack 栈

func New added in v0.1.4

func New() *Stack

func (*Stack) Pop added in v0.1.4

func (s *Stack) Pop()

func (*Stack) Push added in v0.1.4

func (s *Stack) Push(data interface{})

func (*Stack) String added in v0.1.4

func (s *Stack) String() string

type StartFunc added in v0.0.7

type StartFunc func(c *Context)

StartFunc 请求开始前执行的方法类型

type StressUrl added in v0.0.7

type StressUrl struct {
	Url    string
	Method string
	Sum    int64
	Total  int
	TQueue TodoQueue

	// 接口传入的json
	JsonData string

	// 接口传入类型
	ContentType string
	// contains filtered or unexported fields
}

StressUrl 压力测试一个url

func NewTestUrl added in v0.0.7

func NewTestUrl(url, method string, sum int64, total int) *StressUrl

NewTestUrl 实例化一个新的url压测

func (*StressUrl) Run added in v0.0.7

func (s *StressUrl) Run(vs ...interface{})

Run 运行压测

func (*StressUrl) SetJson added in v0.1.1

func (s *StressUrl) SetJson(str string)

SetJson 设置json

type SucceedFunc added in v0.0.7

type SucceedFunc func(c *Context)

SucceedFunc 请求成功后执行的方法类型

type TableInfo added in v0.0.9

type TableInfo struct {
	Field   string
	Type    string
	Null    string
	Key     string
	Default interface{}
	Extra   string
}

TableInfo 表信息

type Task added in v0.0.5

type Task struct {
	Url       string
	JsonParam string
	HeaderMap *http.Header
	Data      map[string]interface{} // 上下文传递的数据
	Urls      []*ReqUrl              // 多步骤使用
	Type      string                 // "", "upload", "do"
	SavePath  string
	SaveDir   string
	FileName  string
	// contains filtered or unexported fields
}

Task 任务对象

func CrawlerTask added in v0.1.3

func CrawlerTask(url, jsonParam string, vs ...interface{}) *Task

CrawlerTask

func NewTask added in v0.3.6

func NewTask() *Task

NewTask 新建任务

func (*Task) AddData added in v0.1.14

func (task *Task) AddData(key string, value interface{}) *Task

func (*Task) GetDataStr added in v0.1.12

func (task *Task) GetDataStr(key string) string

func (*Task) SetJsonParam added in v0.3.6

func (task *Task) SetJsonParam(jsonStr string) *Task

func (*Task) SetUrl added in v0.3.6

func (task *Task) SetUrl(urlStr string) *Task

type TcpClient added in v0.2.9

type TcpClient struct {
	Connection *net.TCPConn
	HawkServer *net.TCPAddr
	StopChan   chan struct{}
	CmdChan    chan string
	Token      string
	RConn      chan struct{}
}

TcpClient Tcp客户端

func NewTcpClient added in v0.2.9

func NewTcpClient() *TcpClient

func (*TcpClient) Addr added in v0.2.9

func (c *TcpClient) Addr() string

func (*TcpClient) Close added in v0.2.9

func (c *TcpClient) Close()

func (*TcpClient) ReConn added in v0.2.9

func (c *TcpClient) ReConn()

func (*TcpClient) Read added in v0.2.9

func (c *TcpClient) Read(b []byte) (int, error)

func (*TcpClient) Run added in v0.2.9

func (c *TcpClient) Run(serverHost string, r func(c *TcpClient, data []byte), w func(c *TcpClient))

func (*TcpClient) Send added in v0.2.9

func (c *TcpClient) Send(b []byte) (int, error)

func (*TcpClient) Stop added in v0.2.9

func (c *TcpClient) Stop()

type TodoQueue added in v0.0.4

type TodoQueue interface {
	Add(task *Task) error //向队列中添加元素
	Poll() *Task          //移除队列中最前面的元素
	Clear() bool          //清空队列
	Size() int            //获取队列的元素个数
	IsEmpty() bool        //判断队列是否是空
	Print()               // 打印
}

TodoQueue 任务队列

func NewQueue added in v0.0.4

func NewQueue() TodoQueue

NewQueue 新建一个队列

func NewUploadQueue added in v0.1.1

func NewUploadQueue() TodoQueue

NewQueue 新建一个下载队列

type UdpClient added in v0.2.9

type UdpClient struct {
	SrcAddr *net.UDPAddr
	DstAddr *net.UDPAddr
	Conn    *net.UDPConn
	Token   string
}

UdpClient Udp客户端

func NewUdpClient added in v0.2.9

func NewUdpClient() *UdpClient

func (*UdpClient) Addr added in v0.2.9

func (u *UdpClient) Addr() string

func (*UdpClient) Close added in v0.2.9

func (u *UdpClient) Close()

func (*UdpClient) Read added in v0.2.9

func (u *UdpClient) Read(b []byte) (int, *net.UDPAddr, error)

func (*UdpClient) Run added in v0.2.9

func (u *UdpClient) Run(hostServer string, port int, r func(u *UdpClient, data []byte), w func(u *UdpClient))

func (*UdpClient) Send added in v0.2.9

func (u *UdpClient) Send(b []byte) (int, error)

type UploadQueue added in v0.1.1

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

下载队列

func (*UploadQueue) Add added in v0.1.1

func (q *UploadQueue) Add(task *Task) error

Add 向队列中添加元素

func (*UploadQueue) Clear added in v0.1.1

func (q *UploadQueue) Clear() bool

func (*UploadQueue) IsEmpty added in v0.1.1

func (q *UploadQueue) IsEmpty() bool

func (*UploadQueue) Poll added in v0.1.1

func (q *UploadQueue) Poll() *Task

Poll 移除队列中最前面的额元素

func (*UploadQueue) Print added in v0.1.1

func (q *UploadQueue) Print()

func (*UploadQueue) Size added in v0.1.1

func (q *UploadQueue) Size() int

type UserAgentType added in v0.0.4

type UserAgentType int
const (
	PCAgent UserAgentType = iota + 1
	WindowsAgent
	LinuxAgent
	MacAgent
	AndroidAgent
	IosAgent
	PhoneAgent
	WindowsPhoneAgent
	UCAgent
)

type WSClient added in v0.1.9

type WSClient interface {
	Send(body []byte) error
	Read(data []byte) error
	Close()
}

WSClient websocket 客户端

func WsClient added in v0.1.9

func WsClient(host, path string, isSSL bool) (WSClient, error)

WsClient websocket 客户端

Directories

Path Synopsis
_examples
baojia
url : http://www.100ppi.com/mprice/mlist-1--1.html 抓取商品报价
url : http://www.100ppi.com/mprice/mlist-1--1.html 抓取商品报价
get
qgyyzs
环球医药网 爬虫 http://data.qgyyzs.net
环球医药网 爬虫 http://data.qgyyzs.net
qihuo
url: http://futures.100ppi.com/qhb/day-2022-07-05.html 抓取期货数据
url: http://futures.100ppi.com/qhb/day-2022-07-05.html 抓取期货数据
search
1.
1.

Jump to

Keyboard shortcuts

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