Documentation
¶
Index ¶
- Constants
- Variables
- func Base64UrlDecode(seg string) ([]byte, error)
- func Base64UrlEncode(seg []byte) string
- func CopyDir(src string, dst string) error
- func CopyFile(src, dst string) error
- func GetBaseUrl(url string) string
- func GetDomainByUrl(url string) string
- func GetFileInfo(path string) (file fs.FileInfo, err error)
- func GetFileSha256(path string) (hash string, err error)
- func GetIndexOf[T any](val T, vals []T) int64
- func GetJwtBySecret(keyBytes []byte, bodyInfo map[string]interface{}) (string, error)
- func GetKeywordByDomain(domain string) string
- func GetMapStringValue(key string, dictMap map[string]interface{}) string
- func GetPidByPort(portNumber int) int
- func GetPriceByText(priceText string) float64
- func GetRandInt(min, max int) int
- func GetRandString(l int) string
- func GetSha256(s string) string
- func GetSha256BySecret(secret string, keyBytes []byte) []byte
- func GetUrl(url, base string) string
- func GetUrlQueryValue(key, url string) string
- func IsPathExists(path string) bool
- func JsonDecodeUseNumber(infoBytes []byte, result interface{}) error
- func KillPid(pid string) error
- func Md5(s string) string
- func Mkdir(path string) error
- func ParseJsonFile(path string, v interface{}, useNumber bool) error
- func ReadCookies(h http.Header, filter string) []*http.Cookie
- func ReadDir(path string, callback func(fileinfo fs.FileInfo)) error
- func ReadFileToString(path string) (string, error)
- func ReadSetCookies(h http.Header) []*http.Cookie
- func ReplaceAllString(originalstr, oldstr, newstr string) string
- func RunCmd(name string, arg ...string) ([]byte, error)
- func StartBrowserByUrl(url string) error
- func StrToInt(intstr string, prune []string) int64
- func UpdateJsonFile(path string, v interface{}) error
- type HttpRequest
- func (h *HttpRequest) AddRequestHeader(key string, value string) error
- func (h *HttpRequest) Do(callback func(h *HttpRequest)) error
- func (h *HttpRequest) Download(file string) error
- func (h *HttpRequest) ParseJsonResponse(model interface{}) error
- func (h *HttpRequest) SetProxy(proxyUrl string)
- func (h *HttpRequest) SetRequestHeader(key string, value string) error
- func (h *HttpRequest) SetRequestPost(data interface{}) error
- func (h *HttpRequest) SetRequestPostByString(data string) error
- func (h *HttpRequest) SetTimeout(seconds uint8)
- type JsonWebToken
- type LogLevel
- type Logger
- func (l *Logger) CloseLogFile()
- func (l *Logger) Debug(content ...interface{}) (isPrint bool)
- func (l *Logger) Debugf(format string, v ...any) (isPrint bool)
- func (l *Logger) Error(content ...interface{}) (isPrint bool)
- func (l *Logger) Errorf(format string, v ...any) (isPrint bool)
- func (l *Logger) Info(content ...interface{}) (isPrint bool)
- func (l *Logger) Infof(format string, v ...any) (isPrint bool)
- func (l *Logger) SetLogLevel(level LogLevel) *Logger
- func (l *Logger) Warn(content ...interface{}) (isPrint bool)
- func (l *Logger) Warnf(format string, v ...any) (isPrint bool)
- type Strfind
Constants ¶
const ( LOG_LEVEL_DEBUG = 0 LOG_LEVEL_INFO = 1 LOG_LEVEL_WARN = 2 LOG_LEVEL_ERROR = 3 )
Variables ¶
Functions ¶
func Base64UrlDecode ¶
Base64UrlDecode Decode JWT specific base64url encoding with padding stripped
func Base64UrlEncode ¶
Base64UrlEncode Encode JWT specific base64url encoding with padding stripped
func GetBaseUrl ¶ added in v1.0.3
GetBaseUrl. GetBaseUrl("https://www.baidu.com/hello?word=hiiii") -> "https://www.baidu.com" url must starwith http; return like: https://www.baidu.com
func GetDomainByUrl ¶ added in v1.0.3
GetDomainByUrl. 获取url网址的域名。 the arg url startwith http, //, / ; return like: "www.baidu.com", "baidu.com", ""
func GetFileInfo ¶ added in v1.0.8
GetFileInfo 获取文件信息
func GetFileSha256 ¶
GetFileSha256 get SHA256 hash of file.
func GetIndexOf ¶ added in v1.0.5
GetIndexOf 获取切片元素的位置,不存在返回-1
func GetJwtBySecret ¶
func GetKeywordByDomain ¶ added in v1.0.3
GetKeywordByDomain GetKeywordByDomain("www.baidu.com") -> baidu
func GetMapStringValue ¶ added in v1.0.3
func GetPidByPort ¶ added in v1.0.2
GetPidByPort. 查找端口所属进程的PID。 返回端口号对应的进程PID,若没有找到相关进程,返回-1
func GetPriceByText ¶ added in v1.0.5
GetPriceByText 价格字符串转数字(float64) Examples: GetPriceByText("$ 156,335,10.37") -> 15633510.37 GetPriceByText("£156,335,10.37") -> 15633510.37
func GetRandInt ¶ added in v1.0.9
GetRandInt 获取 min~max之间的随机数。包括min和max。
func GetRandString ¶
func GetSha256BySecret ¶
GetSha256BySecret get SHA256 hash by Key
func GetUrl ¶ added in v1.0.3
GetUrl. 获取Url链接全路径。常用于爬虫链接格式化。例: Get("/product?id=90", "https://www.site.com") url: startwith http, /, // ; base must startwith http
func GetUrlQueryValue ¶ added in v1.0.3
GetUrlQueryValue 提取网址的查询字符串。即问号之后的部分。
func JsonDecodeUseNumber ¶
JsonDecodeUseNumber 解析带数字的JSON
func ParseJsonFile ¶ added in v1.0.8
ParseJsonFile 解析json文件内容 json1 := map[string]interface{}{} ParseJsonFile("runtime/testjson.json", &json1, false)
func ReadCookies ¶ added in v1.0.8
readCookies parses all "Cookie" values from the header h and returns the successfully parsed Cookies.
if filter isn't empty, only cookies of that name are returned
func ReadFileToString ¶ added in v1.0.2
ReadFileString 读取文件内容
func ReadSetCookies ¶ added in v1.0.8
readSetCookies parses all "Set-Cookie" values from the header h and returns the successfully parsed Cookies.
func ReplaceAllString ¶ added in v1.0.3
func StartBrowserByUrl ¶ added in v1.0.2
StartBrowserByUrl 打开系统默认浏览器
func StrToInt ¶ added in v1.0.5
StrToInt 字符串转整数。prune参数: 去除千分位等特殊符号。 Examples: StrToInt("15,633,510", nil) -> 15633510 StrToInt("$ 156,335,10", []string{"$", ","}) != 15633510
func UpdateJsonFile ¶ added in v1.0.8
UpdateJsonFile 更新json文件内容 testJson := map[string]interface{}{"name": "Tom", "age": 19, "height": 167.5} UpdateJsonFile("runtime/testjson.json", testJson)
Types ¶
type HttpRequest ¶ added in v1.0.4
type HttpRequest struct { Client *http.Client Request *http.Request OnRequest func(r *http.Request) Response *http.Response BodyBytes []byte Url string RetryTimes uint8 // contains filtered or unexported fields }
HttpRequest TODO 把 Request 改为私有属性
func NewHttpRequest ¶ added in v1.0.4
func NewHttpRequest(url string) *HttpRequest
NewHttpRequest 构建http请求,默认为GET方法的HTTP请求。
func (*HttpRequest) AddRequestHeader ¶ added in v1.0.11
func (h *HttpRequest) AddRequestHeader(key string, value string) error
SetRequestHeader 添加HTTP请求头
func (*HttpRequest) Do ¶ added in v1.0.4
func (h *HttpRequest) Do(callback func(h *HttpRequest)) error
Do 执行之构建好的HTTP请求
func (*HttpRequest) Download ¶ added in v1.0.4
func (h *HttpRequest) Download(file string) error
Download 下载文件. example: NewHttpRequest("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png").Download("runtime/baidu.png")
func (*HttpRequest) ParseJsonResponse ¶ added in v1.0.4
func (h *HttpRequest) ParseJsonResponse(model interface{}) error
ParseJsonResponse 解码HTTP响应的json内容。 when response body is a json string param model: a struct point
func (*HttpRequest) SetProxy ¶ added in v1.0.4
func (h *HttpRequest) SetProxy(proxyUrl string)
设置HTTP代理。 例: SetProxy("http://127.0.0.1:1080")
func (*HttpRequest) SetRequestHeader ¶ added in v1.0.4
func (h *HttpRequest) SetRequestHeader(key string, value string) error
SetRequestHeader 设置HTTP请求头
func (*HttpRequest) SetRequestPost ¶ added in v1.0.4
func (h *HttpRequest) SetRequestPost(data interface{}) error
SetRequestPost 构建POST方法请求,设置POST数据内容。
func (*HttpRequest) SetRequestPostByString ¶ added in v1.0.4
func (h *HttpRequest) SetRequestPostByString(data string) error
SetRequestPostByString 构建POST方法请求,设置POST数据字符串。
func (*HttpRequest) SetTimeout ¶ added in v1.0.4
func (h *HttpRequest) SetTimeout(seconds uint8)
SetTimeout 设置请求超时时间
type JsonWebToken ¶
type JsonWebToken struct { TokenString string // contains filtered or unexported fields }
func (*JsonWebToken) Create ¶
func (j *JsonWebToken) Create(claims map[string]interface{}, expiresin time.Duration) (token string, err error)
Create JsonWebToken string Create(map[string]interface{}{"id": 123456789, "username": "Harvey"}, time.Second*time.Duration(3600))
type Logger ¶ added in v1.0.2
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) CloseLogFile ¶ added in v1.0.2
func (l *Logger) CloseLogFile()
func (*Logger) SetLogLevel ¶ added in v1.0.9
type Strfind ¶ added in v1.0.3
type Strfind struct { BodyStr string // contains filtered or unexported fields }
func NewStrfind ¶ added in v1.0.3
NewStrfind 字符串提取器。使用正则表达式从字符串中提取信息。
func (*Strfind) GetOne ¶ added in v1.0.3
GetOne 获取检索结果。例: GetOne(true) -> "begin123end", GetOne(false) -> "123"