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 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 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 ReadDir(path string, callback func(fileinfo fs.FileInfo)) error
- func ReadFileToString(path string) (string, error)
- func ReplaceAllString(originalstr, oldstr, newstr string) string
- func StartBrowserByUrl(url string) error
- func StrToInt(intstr string, prune []string) int64
- type HttpRequest
- 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
- 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 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 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 ¶
func ReadFileToString ¶ added in v1.0.2
ReadFileString 读取文件内容
func ReplaceAllString ¶ added in v1.0.3
func StartBrowserByUrl ¶ added in v1.0.2
StartBrowserByUrl 打开系统默认浏览器
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
}
func NewHttpRequest ¶ added in v1.0.4
func NewHttpRequest(url string) *HttpRequest
NewHttpRequest 构建http请求,默认为GET方法的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()
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"