Compare commits

..

5 Commits

Author SHA1 Message Date
97f027badd save code 2023-07-27 18:21:51 +08:00
55e14d3fd5 update go mod 2023-07-27 17:58:40 +08:00
428dc77280 update 2023-02-11 20:09:03 +08:00
6446cd58f1 解决cookie设置失败问题 2023-01-24 18:50:43 +08:00
4c99d24de6 保存无头浏览器处理的代码 2023-01-24 17:14:44 +08:00
25 changed files with 2598 additions and 51 deletions

1
.gitignore vendored
View File

@ -19,4 +19,5 @@
.idea
.vscode
mail_test.go
test.png

78
array.go Normal file
View File

@ -0,0 +1,78 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-03-30 14:35
package util
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
type array struct {
}
// In 判断指定数据是否在目标数据集中, 不存在返回 -1 , 存在时返回数据对应的索引
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:38 2023/3/30
func (a *array) In(search interface{}, source interface{}) int {
if nil == source {
return -1
}
sourceType := reflect.TypeOf(source).Kind()
if sourceType != reflect.Array && sourceType != reflect.Slice {
return -1
}
byteData, _ := json.Marshal(source)
var (
formatSourceData []interface{}
)
_ = JSON.UnmarshalWithNumber(byteData, &formatSourceData)
if nil == search {
for idx, item := range formatSourceData {
if item == nil {
return idx
}
}
return -1
}
searchType := reflect.TypeOf(search).Kind()
for idx, item := range formatSourceData {
itemKind := reflect.TypeOf(item).Kind()
if searchType != itemKind {
// 类型不同, 检测是否为数字
if strings.Contains(searchType.String(), "int") || strings.Contains(searchType.String(), "float") {
// 查询的是数字
if _, ok := item.(json.Number); ok {
if fmt.Sprintf("%v", search) == fmt.Sprintf("%v", item) {
return idx
}
}
}
continue
}
if fmt.Sprintf("%v", search) == fmt.Sprintf("%v", item) {
return idx
}
}
return -1
}
// InAny In 函数的简化写法
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:25 2023/3/30
func (a *array) InAny(search interface{}, source ...interface{}) int {
return a.In(search, source)
}

21
array_test.go Normal file
View File

@ -0,0 +1,21 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-03-30 14:43
package util
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_array_In(t *testing.T) {
//assert.Equal(t, -1, Array.In(1234, []string{"1234", "123", "1"}))
assert.Equal(t, 0, Array.In(1234, []interface{}{1234, "123", "1"}))
//assert.Equal(t, -1, Array.In(nil, []interface{}{1234, "123", "1"}))
//assert.Equal(t, 3, Array.In(nil, []interface{}{1234, "123", "1", nil}))
}

33
browser.go Normal file
View File

@ -0,0 +1,33 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-04-09 19:02
package util
import (
"fmt"
"os/exec"
"runtime"
)
type browser struct {
commandTable map[string]string
}
// Open 使用系统默认浏览器打开链接
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:05 2023/4/9
func (b *browser) Open(link string) error {
run, ok := b.commandTable[runtime.GOOS]
if !ok {
return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
}
cmd := exec.Command(run, link)
return cmd.Start()
}

View File

@ -21,9 +21,6 @@ type calculate struct {
//
// Date : 15:50 2022/7/17
func (c *calculate) GetTotalPage(total int64, pageSize int64) int64 {
if pageSize <= 0 {
return 1
}
totalPage := total / pageSize
if total%pageSize > 0 {
totalPage++

123
chrome.go Normal file
View File

@ -0,0 +1,123 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-01-24 15:36
package util
import (
"fmt"
"github.com/tebeka/selenium"
"github.com/tebeka/selenium/chrome"
"os"
)
// NewChrome ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:38 2023/1/24
//
// chromedriver下载地址 : http://chromedriver.storage.googleapis.com/index.html
func NewChrome(seleniumPath string, port int, debug bool, options []selenium.ServiceOption) (*Chrome, error) {
instance := &Chrome{
seleniumPath: seleniumPath,
port: port,
debug: debug,
}
// 设置debug模式
selenium.SetDebug(instance.debug)
var (
err error
)
// 获取实例
if instance.serviceInstance, err = selenium.NewChromeDriverService(seleniumPath, port, options...); nil != err {
return nil, err
}
return instance, nil
}
// Chrome 无头模式chrome浏览器, 用于爬虫或截图
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:36 2023/1/24
type Chrome struct {
seleniumPath string // chrome 路径
port int // 端口
debug bool // 开启debug模式
serviceInstance *selenium.Service // 浏览器实例
}
// Render 无头模式渲染页面
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:14 2023/1/24
func (c *Chrome) Render(cookieList []*selenium.Cookie) {
//链接本地的浏览器 chrome
caps := selenium.Capabilities{
//"browserName": "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
"browserName": "Google Chrome",
}
//禁止图片加载,加快渲染速度
imagCaps := map[string]interface{}{
"profile.managed_default_content_settings.images": 2,
}
chromeCaps := chrome.Capabilities{
Prefs: imagCaps,
Path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
Args: []string{
//静默执行请求
"--headless", // 设置Chrome无头模式在linux下运行需要设置这个参数否则会报错
"--no-sandbox",
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", // 模拟user-agent防反爬
},
}
//以上是设置浏览器参数
caps.AddChrome(chromeCaps)
url := "https://zhangdeman.cn/archives/bbd86236.html"
w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", c.port))
if err != nil {
fmt.Println("connect to the webDriver failed", err.Error())
return
}
_ = w_b1.Get(url)
fmt.Println(w_b1.DoubleClick())
for _, itemCookie := range cookieList {
err = w_b1.AddCookie(itemCookie)
if nil != err {
fmt.Println(err)
}
}
allCookie, _ := w_b1.GetCookies()
fmt.Println(allCookie)
err = w_b1.Get(url)
imgByteData, _ := w_b1.Screenshot()
_ = os.WriteFile("test.png", imgByteData, 0777)
//获取网页源码
pageSource, err := w_b1.PageSource()
if err != nil {
fmt.Println("get page failed", err.Error())
return
}
fmt.Print(pageSource)
}
// Close 关闭浏览器
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:52 2023/1/24
func (c *Chrome) Close() error {
return c.serviceInstance.Stop()
}

21
chrome_test.go Normal file
View File

@ -0,0 +1,21 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-01-24 16:16
package util
import (
"testing"
"github.com/tebeka/selenium"
)
func TestNewChrome(t *testing.T) {
cookieList := make([]*selenium.Cookie, 0)
instance, _ := NewChrome("/Users/zhangdeman/Downloads/chromedriver", 9515, false, nil)
instance.Render(cookieList)
}

4
cli.go
View File

@ -23,9 +23,7 @@ type cli struct {
func (c *cli) ParseCLIParameter(parameterNameList []string) map[string]string {
cliParameterTable := make(map[string]*string)
for _, parameterName := range parameterNameList {
var val string
flag.StringVar(&val, parameterName, "", parameterName)
cliParameterTable[parameterName] = &val
cliParameterTable[parameterName] = flag.String(parameterName, "", parameterName)
}
// 这里有一个非常中的操作,转换,必须调用该方法
flag.Parse()

View File

@ -1,26 +0,0 @@
// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-07-31 14:52
package define
import "io/fs"
// FileInfo 文件信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:53 2023/7/31
type FileInfo struct {
IsDir bool `json:"is_dir"` // 是否目录
Name string `json:"name"` // 文件名
AbsolutePath string `json:"absolute_path"` // 绝对路径
Format string `json:"format"` // 文件格式
Size int64 `json:"size"` // 文件大小
ModifyTime int64 `json:"modify_time"` // 修改时间, 秒级时间戳
Mode fs.FileMode `json:"mode"` // 文件权限
FileList []*FileInfo `json:"file_list"` // 递归读取, 且当前文件为目录
}

181
file.go Normal file
View File

@ -0,0 +1,181 @@
// Package util...
//
// Description : 文件相关工具
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-04-26 6:00 下午
package util
import (
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/go-ini/ini"
"github.com/pkg/errors"
yml "gopkg.in/yaml.v3"
)
// file 文件相关操作
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:08 2022/5/14
type file struct {
}
// GetProjectPath 获取项目路径(可执行文件所在目录)
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:32 下午 2021/4/26
func (f *file) GetProjectPath() (string, error) {
rootPath, err := os.Getwd()
if nil != err {
return "", err
}
pathArr := strings.Split(rootPath, "/")
if len(pathArr) > 0 {
if pathArr[len(pathArr)-1] == "test" {
rootPath = strings.Join(pathArr[0:len(pathArr)-1], "/")
}
}
return rootPath, nil
}
// ReadYmlContent 读取yml配置问价,并解析到指定的结构体中
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:35 下午 2021/4/26
func (f *file) ReadYmlContent(filePath string, result interface{}) error {
if nil == result {
return errors.New("接收读取结果的数据指针为NIL")
}
var (
fileContent []byte
err error
)
if fileContent, err = f.ReadFileContent(filePath); nil != err {
return err
}
return yml.Unmarshal(fileContent, result)
}
// ReadJSONContent 读取JSON内容,并解析到指定的结构体中
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:23 2022/6/9
func (f *file) ReadJSONContent(filePath string, result interface{}) error {
if nil == result {
return errors.New("接收读取结果的数据指针为NIL")
}
var (
fileContent []byte
err error
)
if fileContent, err = f.ReadFileContent(filePath); nil != err {
return err
}
return JSON.UnmarshalWithNumber(fileContent, result)
}
// ReadIniContent 读取并解析ini文件
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:21 2022/7/2
func (f *file) ReadIniContent(filePath string, result interface{}) error {
if nil == result {
return errors.New("接收读取结果的数据指针为NIL")
}
return ini.MapTo(result, filePath)
}
// ReadAnyFileContent 读取任意类型的文件并解析
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:11 2022/7/2
func (f *file) ReadAnyFileContent(filePath string, receiver interface{}) error {
fileInfoArr := strings.Split(filePath, ".")
if len(fileInfoArr) < 2 {
return errors.New("未知的文件类型")
}
var (
parseFunc func(filePath string, receiver interface{}) error
)
fileExt := strings.ToLower(fileInfoArr[len(fileInfoArr)-1])
switch fileExt {
case "json":
parseFunc = f.ReadJSONContent
case "yml":
fallthrough
case "yaml":
parseFunc = f.ReadYmlContent
case "ini":
parseFunc = f.ReadIniContent
default:
return errors.New(fileExt + " 暂不支持当前格式的文件解析")
}
return parseFunc(filePath, receiver)
}
// ReadFileContent 读取文件内容
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:37 下午 2021/4/26
func (f *file) ReadFileContent(filePath string) ([]byte, error) {
if exist, isFile := f.IsFileExist(filePath); !exist || !isFile {
//文件不存在或者是一个目录
return nil, errors.New(filePath + " 文件不存在或者是一个目录!")
}
//打开文件
var (
fileHandler *os.File
err error
)
if fileHandler, err = os.Open(filePath); nil != err {
return nil, err
}
return ioutil.ReadAll(fileHandler)
}
// IsFileExist 判断文件是否存在
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:37 下午 2021/4/26
func (f *file) IsFileExist(filePath string) (bool, bool) {
fileStat, err := os.Stat(filePath)
return nil == err || os.IsExist(err), (nil == err || os.IsExist(err)) && !fileStat.IsDir()
}
// GetFileMIMEType 获取本地文件的MIME类型
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:15 2023/2/7
func (f *file) GetFileMIMEType(filePath string) (string, error) {
var (
err error
fileHandler *os.File
)
if fileHandler, err = os.Open(filePath); nil != err {
return "", err
}
// 只需要前 512 个字节就可以了
buffer := make([]byte, 512)
if _, err = fileHandler.Read(buffer); nil != err {
return "", err
}
contentType := http.DetectContentType(buffer)
return contentType, nil
}

137
filter.go Normal file
View File

@ -0,0 +1,137 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-04 11:45
package util
import (
"fmt"
"github.com/Jeffail/gabs"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
)
// MapRule 映射规则
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:21 2022/7/4
type MapRule struct {
SourcePath string `json:"source_path"` // 原路径
MapPath string `json:"map_path"` // 映射路径
Required bool `json:"required"` // 必须存在
DataType string `json:"data_type"` // 数据类型
DefaultValue string `json:"default_value"` // 默认值, 以字符串传入, 会转换成 DataType
}
// NewFilter 过滤器实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:54 2022/7/4
func NewFilter(sourceData string, filterRuleList []MapRule) *filter {
return &filter{
sourceData: sourceData,
filterRuleList: filterRuleList,
jsonObj: &gabs.Container{},
}
}
// filter 数据过滤
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:58 2022/7/4
type filter struct {
sourceData string
filterRuleList []MapRule
jsonObj *gabs.Container // 生成的json对象实例
}
// Deal ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:59 2022/7/4
func (f *filter) Deal() ([]byte, error) {
for _, rule := range f.filterRuleList {
sourceResult := gjson.Get(f.sourceData, rule.SourcePath)
sourceVal := sourceResult.String()
if !sourceResult.Exists() {
// 不存在, 使用默认值
sourceVal = rule.DefaultValue
}
formatVal, err := f.getValue(rule.DataType, sourceVal)
if nil != err {
return nil, fmt.Errorf("%s = %v can not convert to %s : %s", rule.SourcePath, sourceResult.Value(), rule.DataType, err.Error())
}
if _, err := f.jsonObj.SetP(formatVal, rule.MapPath); nil != err {
return nil, fmt.Errorf("%s set val = %v fail : %s", rule.MapPath, formatVal, err.Error())
}
}
return f.jsonObj.EncodeJSON(), nil
}
// getValue 获取值
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:25 2022/7/4
func (f *filter) getValue(dataType string, defaultValue string) (interface{}, error) {
switch dataType {
case "int8":
fallthrough
case "int16":
fallthrough
case "int32":
fallthrough
case "int64":
fallthrough
case "int":
var (
err error
val int64
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "uint8":
fallthrough
case "uint16":
fallthrough
case "uint32":
fallthrough
case "uint64":
fallthrough
case "uint":
var (
err error
val uint64
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "bool":
var (
err error
val bool
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "float32":
fallthrough
case "float64":
var (
err error
val float64
)
err = ConvertAssign(&val, defaultValue)
return val, err
case "string":
return defaultValue, nil
default:
return nil, errors.New(dataType + " is not support!")
}
}

57
filter_test.go Normal file
View File

@ -0,0 +1,57 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-04 12:44
package util
import (
"fmt"
"testing"
)
func Test_filter_Deal(t *testing.T) {
sourceData := `{
"name":"zhangsan",
"age":"18",
"extension":{
"sex":"man",
"height":"180"
}
}`
ruleList := []MapRule{
{
SourcePath: "name",
MapPath: "user_name",
Required: true,
DataType: "string",
DefaultValue: "lalala",
},
{
SourcePath: "age",
MapPath: "user_age",
Required: true,
DataType: "int",
DefaultValue: "280",
},
{
SourcePath: "extension.height",
MapPath: "user_height",
Required: true,
DataType: "int",
DefaultValue: "359",
},
{
SourcePath: "extension.sex",
MapPath: "user_sex",
Required: true,
DataType: "string",
DefaultValue: "lalala",
},
}
instance := NewFilter(sourceData, ruleList)
result, err := instance.Deal()
fmt.Println(string(result), err)
}

25
go.mod
View File

@ -1,20 +1,27 @@
module git.zhangdeman.cn/zhangdeman/util
go 1.21
go 1.20
require (
github.com/Jeffail/gabs v1.4.0
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-ini/ini v1.67.0
github.com/mitchellh/go-homedir v1.1.0
github.com/mozillazg/go-pinyin v0.20.0
github.com/mssola/user_agent v0.6.0
github.com/pkg/errors v0.9.1
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.8.2
github.com/tebeka/selenium v0.9.9
github.com/tidwall/gjson v1.14.4
gopkg.in/yaml.v3 v3.0.1
)
require (
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b // indirect
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71 // indirect
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d // indirect
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/go-ini/ini v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
)

151
go.sum
View File

@ -1,23 +1,154 @@
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b h1:C7KftnLh7dOqzNRs5dn/9yqMDvuqMn5RCglvV6bY758=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71 h1:nvVSH+Ju8EmoPiPHTae5lxHo4kDjROYChs19Yayz+NY=
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d h1:TV0BCQQewBEtLsv3i9gXkxLFd5A5bWBTiNd3D/I5o4Q=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d/go.mod h1:w7kG4zyTJ1uPFaTWhze+OQuaUBINT2XnDxpyiM6ctc0=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000 h1:ulssHpUMNoxws/fdJD+bhw8tuMPXp+jB54WwLdJNTsU=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000/go.mod h1:rt9wlUf/Y6lpZBXb0KK8n0JxEbI1J5JB73XgQmGHJqw=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.41.0/go.mod h1:OauMR7DV8fzvZIl2qg6rkaIhD/vmgk4iwEw/h6ercmg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e h1:4ZrkT/RzpnROylmoQL57iVUL57wGKTR5O6KpVnbm2tA=
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-github/v27 v27.0.4/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/mssola/user_agent v0.6.0 h1:uwPR4rtWlCHRFyyP9u2KOV0u8iQXmS7Z7feTrstQwk4=
github.com/mssola/user_agent v0.6.0/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tebeka/selenium v0.9.9 h1:cNziB+etNgyH/7KlNI7RMC1ua5aH1+5wUlFQyzeMh+w=
github.com/tebeka/selenium v0.9.9/go.mod h1:5Fr8+pUvU6B1OiPfkdCKdXZyr5znvVkxuPd0NOdZCQc=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190624190245-7f2218787638/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190626174449-989357319d63/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

48
init.go
View File

@ -10,23 +10,71 @@ package util
var (
// Cli ...
Cli *cli
// File ...
File *file
// Hash ...
Hash *hash
// IP ...
IP *ip
// JSON ...
JSON *ownJSON
// String ...
String *stringOperate
// Struct ...
Struct *ownStruct
// Time ...
Time *ownTime
// URL ...
URL *ownURL
// Map ...
Map *ownMap
// Calculate ...
Calculate *calculate
// Project ...
Project *project
// 数组操作
Array *array
// JWT ...
JWT *ownJwt
// UserAgent ...
UserAgent *userAgent
// Console 控制台输出数据
Console *console
// Browser 浏览器操作实例
Browser *browser
// StringConvert 字符串转为任意类型
StringConvert *stringConvert
// PinYin 汉字转拼音
PinYin *pinYin
)
func init() {
Cli = &cli{}
File = &file{}
Hash = &hash{}
IP = &ip{}
JSON = &ownJSON{}
String = &stringOperate{}
Struct = &ownStruct{}
Time = &ownTime{}
URL = &ownURL{}
Map = &ownMap{}
Calculate = &calculate{}
Project = &project{}
Array = &array{}
JWT = &ownJwt{}
UserAgent = &userAgent{
list: defaultUserAgentList,
}
Console = &console{}
Browser = &browser{
commandTable: map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
},
}
// StringConvert
StringConvert = &stringConvert{}
PinYin = &pinYin{}
}

59
ip.go Normal file
View File

@ -0,0 +1,59 @@
// Package util...
//
// Description : util...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-03-09 5:56 下午
package util
import (
"net"
"net/http"
)
// ip ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:47 2022/5/14
type ip struct {
}
// GetHostIP 获取本机IP地址
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:58 下午 2021/3/9
func (i *ip) GetHostIP() string {
hostIP := "127.0.0.1"
addrs, _ := net.InterfaceAddrs()
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
hostIP = ipnet.IP.String()
break
}
}
}
return hostIP
}
// GetRemoteIP 获取远端IP
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:35 下午 2021/11/22
func (i *ip) GetRemoteIP(req *http.Request) string {
// Try via request
remoteIP, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
return "::1"
}
userIP := net.ParseIP(remoteIP)
if userIP == nil {
return "::1"
}
return userIP.String()
}

128
json.go Normal file
View File

@ -0,0 +1,128 @@
// Package util...
//
// Description : json 工具函数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-09-14 8:38 下午
package util
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"reflect"
)
// ownJSON ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:01 2022/5/14
type ownJSON struct {
}
// UnmarshalWithNumber 解析json
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:39 下午 2021/9/14
func (oj *ownJSON) UnmarshalWithNumber(byteData []byte, receiver interface{}) error {
decoder := json.NewDecoder(bytes.NewReader(byteData))
decoder.UseNumber()
return decoder.Decode(receiver)
}
// UnmarshalWithNumberForIOReader ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 8:43 下午 2021/9/14
func (oj *ownJSON) UnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver interface{}) error {
decoder := json.NewDecoder(ioReader)
decoder.UseNumber()
return decoder.Decode(receiver)
}
// UnmarshalWithNumberForString 字符串转结构体
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:50 2023/7/22
func (oj *ownJSON) UnmarshalWithNumberForString(input string, receiver interface{}) error {
return oj.UnmarshalWithNumber([]byte(input), receiver)
}
// MarshalForByte 序列化并返回字节数组
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:56 2023/7/22
func (oj *ownJSON) MarshalForByte(input interface{}) []byte {
byteData, _ := json.Marshal(input)
return byteData
}
// MarshalForString 序列化并返回字符串
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:56 2023/7/22
func (oj *ownJSON) MarshalForString(input interface{}) string {
byteData := oj.MarshalForByte(input)
return string(byteData)
}
// ConsoleOutput ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:45 下午 2021/11/5
func (oj *ownJSON) ConsoleOutput(data interface{}) {
var out bytes.Buffer
switch reflect.TypeOf(data).Kind() {
case reflect.Slice:
fallthrough
case reflect.Array:
fallthrough
case reflect.Map:
fallthrough
case reflect.Ptr:
byteData, _ := json.Marshal(data)
_ = json.Indent(&out, []byte(string(byteData)+"\n"), "", "\t")
_, _ = out.WriteTo(os.Stdout)
return
case reflect.Int:
fallthrough
case reflect.Int8:
fallthrough
case reflect.Int16:
fallthrough
case reflect.Int32:
fallthrough
case reflect.Int64:
fallthrough
case reflect.Uint:
fallthrough
case reflect.Uint8:
fallthrough
case reflect.Uint16:
fallthrough
case reflect.Uint32:
fallthrough
case reflect.Uint64:
fallthrough
case reflect.Float32:
fallthrough
case reflect.Float64:
fallthrough
case reflect.String:
_ = json.Indent(&out, []byte(fmt.Sprintf("%v\n", data)), "", "\t")
_, _ = out.WriteTo(os.Stdout)
return
default:
fmt.Println("")
}
}

66
jwt.go Normal file
View File

@ -0,0 +1,66 @@
// Package util ...
//
// Description : go-jwt具体实现
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-02-11 20:09
package util
import (
"errors"
"github.com/dgrijalva/jwt-go"
)
type ownJwt struct {
}
type MyClaims struct {
jwt.StandardClaims
}
// Generate 生成 token
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:13 2023/2/11
func (j *ownJwt) Generate(signMethod jwt.SigningMethod, secret string, claims jwt.Claims) (string, error) {
if nil == signMethod {
signMethod = jwt.SigningMethodHS256
}
var (
token *jwt.Token
)
if nil == claims {
token = jwt.New(signMethod)
} else {
token = jwt.NewWithClaims(signMethod, claims)
}
return token.SignedString([]byte(secret))
}
// Validate 验证token
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:13 2023/2/11
func (j *ownJwt) Validate(inputToken string, secret string, claims jwt.Claims) (jwt.Claims, error) {
var (
token *jwt.Token
err error
)
if token, err = jwt.ParseWithClaims(inputToken, claims, func(tokenInfo *jwt.Token) (interface{}, error) {
return []byte(secret), nil
}); nil != err {
return nil, errors.New("token parse fail : " + err.Error())
}
if !token.Valid {
return nil, errors.New("token is valid : " + err.Error())
}
return token.Claims, nil
}

229
map.go Normal file
View File

@ -0,0 +1,229 @@
// Package util ...
//
// Description : 从map中读取数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-11-16 4:28 下午
package util
import (
"github.com/pkg/errors"
)
// ownMap ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:53 2022/5/14
type ownMap struct {
}
// Exist 检测一个key在map中是否存在
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:52 下午 2021/11/16
func (om *ownMap) Exist(source map[interface{}]interface{}, key interface{}) bool {
if nil == source {
return false
}
if _, exist := source[key]; !exist {
return false
}
return true
}
// GetInt 获取int值
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:30 下午 2021/11/16
func (om *ownMap) GetInt(source map[interface{}]interface{}, key interface{}, defaultVal int) int {
var result int
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetInt8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:59 下午 2021/11/16
func (om *ownMap) GetInt8(source map[interface{}]interface{}, key interface{}, defaultVal int8) int8 {
var result int8
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetInt16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:59 下午 2021/11/16
func (om *ownMap) GetInt16(source map[interface{}]interface{}, key interface{}, defaultVal int16) int16 {
var result int16
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetInt32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:00 下午 2021/11/16
func (om *ownMap) GetInt32(source map[interface{}]interface{}, key interface{}, defaultVal int32) int32 {
var result int32
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetInt64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:00 下午 2021/11/16
func (om *ownMap) GetInt64(source map[interface{}]interface{}, key interface{}, defaultVal int64) int64 {
var result int64
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetUint ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:01 下午 2021/11/16
func (om *ownMap) GetUint(source map[interface{}]interface{}, key interface{}, defaultVal uint) uint {
var result uint
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetUint8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:01 下午 2021/11/16
func (om *ownMap) GetUint8(source map[interface{}]interface{}, key interface{}, defaultVal uint8) uint8 {
var result uint8
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetUint16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:02 下午 2021/11/16
func (om *ownMap) GetUint16(source map[interface{}]interface{}, key interface{}, defaultVal uint16) uint16 {
var result uint16
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetUint32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:02 下午 2021/11/16
func (om *ownMap) GetUint32(source map[interface{}]interface{}, key interface{}, defaultVal uint32) uint32 {
var result uint32
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetUint64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:03 下午 2021/11/16
func (om *ownMap) GetUint64(source map[interface{}]interface{}, key interface{}, defaultVal uint64) uint64 {
var result uint64
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetFloat32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:03 下午 2021/11/16
func (om *ownMap) GetFloat32(source map[interface{}]interface{}, key interface{}, defaultVal float32) float32 {
var result float32
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetFloat64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:04 下午 2021/11/16
func (om *ownMap) GetFloat64(source map[interface{}]interface{}, key interface{}, defaultVal float64) float64 {
var result float64
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetString ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:07 下午 2021/11/16
func (om *ownMap) GetString(source map[interface{}]interface{}, key interface{}, defaultVal string) string {
var result string
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
return defaultVal
}
return result
}
// GetDataWithReceiver 使用制定的数据指针接受结果
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:54 下午 2021/11/16
func (om *ownMap) GetDataWithReceiver(source map[interface{}]interface{}, key interface{}, receiver interface{}) error {
if !om.Exist(source, key) {
return errors.New("key is not found")
}
return ConvertAssign(receiver, source[key])
}
// ToStruct map转结构体
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:48 2023/7/22
func (om *ownMap) ToStruct(source map[string]interface{}, receiver interface{}) error {
if nil == source {
return nil
}
byteData := JSON.MarshalForByte(source)
return JSON.UnmarshalWithNumber(byteData, receiver)
}

203
string.go Normal file
View File

@ -0,0 +1,203 @@
// Package util...
//
// Description : 字符串相关的工具
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-03-09 6:00 下午
package util
import (
"crypto/md5"
"encoding/hex"
"math/rand"
"strings"
"time"
"github.com/axgle/mahonia"
)
var (
// LETTER_LIST 字母列表
LETTER_LIST = []string{
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
}
)
// stringOperate ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:09 2022/5/14
type stringOperate struct {
}
// GenRandom 获取随机长度的字符串
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 6:01 下午 2021/3/9
func (s *stringOperate) GenRandom(source string, length uint) string {
if length == 0 {
return ""
}
if len(source) == 0 {
//字符串为空,默认字符源为如下(去除易混淆的i/l):
source = "0123456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKMNOPQRSTUVWXYZ"
}
strByte := []byte(source)
var genStrByte = make([]byte, 0)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < int(length); i++ {
genStrByte = append(genStrByte, strByte[r.Intn(len(strByte))])
}
return string(genStrByte)
}
// Md5 对字符串进行md5加密
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 6:01 下午 2021/3/9
func (s *stringOperate) Md5(str string) string {
h := md5.New()
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
// Md5FromByte 从字节数组计算签名
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022/10/21 14:12:16
func (s *stringOperate) Md5FromByte(data []byte) string {
h := md5.New()
_, _ = h.Write(data)
return hex.EncodeToString(h.Sum(nil))
}
// GenRandomMd5 生成随机md5
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:11 2022/7/12
func (s *stringOperate) GenRandomMd5() string {
return s.Md5(s.GenRandom("", 16))
}
// SnakeCaseToCamel 蛇形字符串转换为驼峰
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:58 下午 2021/10/25
func (s *stringOperate) SnakeCaseToCamel(str string) string {
if len(str) == 0 {
return ""
}
builder := strings.Builder{}
index := 0
if str[0] >= 'a' && str[0] <= 'z' {
builder.WriteByte(str[0] - ('a' - 'A'))
index = 1
}
for i := index; i < len(str); i++ {
if str[i] == '_' && i+1 < len(str) {
if str[i+1] >= 'a' && str[i+1] <= 'z' {
builder.WriteByte(str[i+1] - ('a' - 'A'))
i++
continue
}
}
// 将ID转为大写
if str[i] == 'd' && i-1 >= 0 && (str[i-1] == 'i' || str[i-1] == 'I') && (i+1 == len(str) || i+1 < len(str) && str[i+1] == '_') {
builder.WriteByte('d' - ('a' - 'A'))
continue
}
builder.WriteByte(str[i])
}
return builder.String()
}
// Convert 字符串编码转换
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:38 2022/7/9
func (s *stringOperate) Convert(str string, sourceCode string, targetCode string) string {
sourceCoder := mahonia.NewDecoder(sourceCode)
sourceResult := sourceCoder.ConvertString(str)
targetCoder := mahonia.NewDecoder(targetCode)
_, cdata, _ := targetCoder.Translate([]byte(sourceResult), true)
return string(cdata)
}
// RemoveDuplicates 对列表数据去重
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:12 2022/7/23
func (s *stringOperate) RemoveDuplicates(sourceList []string) []string {
result := make([]string, 0)
hasDeal := make(map[string]bool)
if len(sourceList) == 0 {
return result
}
for _, val := range sourceList {
if _, exist := hasDeal[val]; exist {
continue
}
result = append(result, val)
hasDeal[val] = true
}
return result
}
// Map2Query map参数转换为url query
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:51 2022/10/10
func (s *stringOperate) Map2Query(data map[string]string) string {
list := make([]string, 0)
for k, v := range data {
list = append(list, k+"="+v)
}
return strings.Join(list, "&")
}
// ClearChar 清理指定字符
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:53 2023/1/13
func (s *stringOperate) ClearChar(src string, charList ...string) string {
if len(charList) == 0 {
return src
}
for _, item := range charList {
src = strings.ReplaceAll(src, item, "")
}
return src
}
// ReplaceChineseChar 替换常见的中文符号
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:59 2023/4/4
func (s *stringOperate) ReplaceChineseChar(str string) string {
charTable := map[string]string{
"": "(",
"": ")",
"": ":",
"": ",",
"。": ".",
"【": "]",
"】": "]",
}
for k, v := range charTable {
str = strings.ReplaceAll(str, k, v)
}
return str
}

653
string_convert.go Normal file
View File

@ -0,0 +1,653 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-05-04 18:25
package util
import (
"strings"
"github.com/pkg/errors"
)
type stringConvert struct {
}
// ToFloat32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:26 2023/5/4
func (sc *stringConvert) ToFloat32(str string) (float32, error) {
var (
err error
res float32
)
err = ConvertAssign(&res, str)
return res, err
}
// ToFloat64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:26 2023/5/4
func (sc *stringConvert) ToFloat64(str string) (float64, error) {
var (
err error
res float64
)
err = ConvertAssign(&res, str)
return res, err
}
// ToDouble 转double
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:33 2023/5/4
func (sc *stringConvert) ToDouble(str string) (float64, error) {
return sc.ToFloat64(str)
}
// ToNumber 转数字, 使用最高精度的float64
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:33 2023/5/4
func (sc *stringConvert) ToNumber(str string) (float64, error) {
return sc.ToFloat64(str)
}
// ToInt8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToInt8(str string) (int8, error) {
var (
err error
res int8
)
err = ConvertAssign(&res, str)
return res, err
}
// ToInt16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToInt16(str string) (int16, error) {
var (
err error
res int16
)
err = ConvertAssign(&res, str)
return res, err
}
// ToInt32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToInt32(str string) (int32, error) {
var (
err error
res int32
)
err = ConvertAssign(&res, str)
return res, err
}
// ToInt64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToInt64(str string) (int64, error) {
var (
err error
res int64
)
err = ConvertAssign(&res, str)
return res, err
}
// ToInt ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:47 2023/5/5
func (sc *stringConvert) ToInt(str string) (int, error) {
var (
err error
res int
)
err = ConvertAssign(&res, str)
return res, err
}
// ToUint8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:30 2023/5/4
func (sc *stringConvert) ToUint8(str string) (uint8, error) {
var (
err error
res uint8
)
err = ConvertAssign(&res, str)
return res, err
}
// ToUint16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToUint16(str string) (uint16, error) {
var (
err error
res uint16
)
err = ConvertAssign(&res, str)
return res, err
}
// ToUint32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToUint32(str string) (uint32, error) {
var (
err error
res uint32
)
err = ConvertAssign(&res, str)
return res, err
}
// ToUint64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToUint64(str string) (uint64, error) {
var (
err error
res uint64
)
err = ConvertAssign(&res, str)
return res, err
}
// ToUint ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (sc *stringConvert) ToUint(str string) (uint, error) {
var (
err error
res uint
)
err = ConvertAssign(&res, str)
return res, err
}
// ToBool ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:34 2023/5/4
func (sc *stringConvert) ToBool(str string) (bool, error) {
var (
err error
res bool
)
err = ConvertAssign(&res, str)
return res, err
}
// ToObject ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:35 2023/5/4
func (sc *stringConvert) ToObject(str string) (map[string]interface{}, error) {
var (
err error
result map[string]interface{}
)
if err = JSON.UnmarshalWithNumber([]byte(str), &result); nil != err {
return nil, err
}
return result, nil
}
// ToStruct ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:38 2023/5/4
func (sc *stringConvert) ToStruct(str string, receiver interface{}) error {
if nil == receiver {
return errors.New("receiver is nil")
}
return JSON.UnmarshalWithNumber([]byte(str), receiver)
}
// ToInt8Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:55 2023/5/4
func (sc *stringConvert) ToInt8Slice(str string, splitChar ...string) ([]int8, error) {
var (
err error
res []int8
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]int8, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToInt8(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToInt16Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:01 2023/5/4
func (sc *stringConvert) ToInt16Slice(str string, splitChar ...string) ([]int16, error) {
var (
err error
res []int16
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]int16, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToInt16(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToInt32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:03 2023/5/4
func (sc *stringConvert) ToInt32Slice(str string, splitChar ...string) ([]int32, error) {
var (
err error
res []int32
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]int32, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToInt32(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToInt64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:04 2023/5/4
func (sc *stringConvert) ToInt64Slice(str string, splitChar ...string) ([]int64, error) {
var (
err error
res []int64
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]int64, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToInt64(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToIntSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:04 2023/5/4
func (sc *stringConvert) ToIntSlice(str string, splitChar ...string) ([]int, error) {
var (
err error
res []int
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]int, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToInt(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToUint8Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:50 2023/5/5
func (sc *stringConvert) ToUint8Slice(str string, splitChar ...string) ([]uint8, error) {
var (
err error
res []uint8
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]uint8, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToUint8(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToUint16Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:52 2023/5/5
func (sc *stringConvert) ToUint16Slice(str string, splitChar ...string) ([]uint16, error) {
var (
err error
res []uint16
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]uint16, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToUint16(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToUint32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:53 2023/5/5
func (sc *stringConvert) ToUint32Slice(str string, splitChar ...string) ([]uint32, error) {
var (
err error
res []uint32
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]uint32, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToUint32(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToUint64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:54 2023/5/5
func (sc *stringConvert) ToUint64Slice(str string, splitChar ...string) ([]uint64, error) {
var (
err error
res []uint64
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]uint64, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToUint64(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToUintSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:54 2023/5/5
func (sc *stringConvert) ToUintSlice(str string, splitChar ...string) ([]uint, error) {
var (
err error
res []uint
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]uint, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToUint(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToBoolSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:55 2023/5/5
func (sc *stringConvert) ToBoolSlice(str string, splitChar ...string) ([]bool, error) {
var (
err error
res []bool
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]bool, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToBool(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToFloat32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:56 2023/5/5
func (sc *stringConvert) ToFloat32Slice(str string, splitChar ...string) ([]float32, error) {
var (
err error
res []float32
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]float32, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToFloat32(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToFloat64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:56 2023/5/5
func (sc *stringConvert) ToFloat64Slice(str string, splitChar ...string) ([]float64, error) {
var (
err error
res []float64
)
isSplit := len(splitChar) > 0
if !isSplit {
if err = JSON.UnmarshalWithNumber([]byte(str), &res); nil != err {
return nil, err
}
return res, nil
}
res = make([]float64, 0)
arr := strings.Split(str, splitChar[0])
for _, item := range arr {
if itemVal, err := sc.ToFloat64(item); nil != err {
return nil, err
} else {
res = append(res, itemVal)
}
}
return res, nil
}
// ToDoubleSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:57 2023/5/5
func (sc *stringConvert) ToDoubleSlice(str string, splitChar ...string) ([]float64, error) {
return sc.ToFloat64Slice(str, splitChar...)
}
// ToNumberSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:57 2023/5/5
func (sc *stringConvert) ToNumberSlice(str string, splitChar ...string) ([]float64, error) {
return sc.ToFloat64Slice(str, splitChar...)
}

38
struct.go Normal file
View File

@ -0,0 +1,38 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-03-14 11:11 下午
package util
import "encoding/json"
// ownStruct ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:19 2022/5/14
type ownStruct struct {
}
// ToMap 结构体转为map
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:12 下午 2021/3/14
func (os *ownStruct) ToMap(data interface{}) (map[string]interface{}, error) {
var (
byteData []byte
err error
result map[string]interface{}
)
if byteData, err = json.Marshal(data); nil != err {
return nil, err
}
if err = json.Unmarshal(byteData, &result); nil != err {
return nil, err
}
return result, nil
}

91
time.go Normal file
View File

@ -0,0 +1,91 @@
// Package util ...
//
// Description : 时间相关操作
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-10-07 1:33 上午
package util
import (
"fmt"
"time"
)
// ownTime ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:24 2022/5/14
type ownTime struct {
format string
}
// GetCurrentFormatTime 获取当前时间的格式化时间(秒)
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 1:34 上午 2021/10/7
func (ot *ownTime) GetCurrentFormatTime(layout ...string) string {
if len(layout) == 0 {
layout = []string{"2006-01-02 15:04:05"}
}
return time.Now().In(time.Local).Format(layout[0])
}
// FormatUnixNano 格式化纳秒时间戳
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:54 2022/7/14
func (ot *ownTime) FormatUnixNano(timestamp int64, layout ...string) string {
if len(layout) == 0 {
layout = []string{"2006-01-02 15:04:05.000"}
}
nano := timestamp % 1e6
milli := timestamp / 1e6
return ot.FormatUnixMilli(milli, layout...) + fmt.Sprintf(" %v", nano)
}
// FormatUnixMilli 格式化毫秒时间戳
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:55 2022/7/14
func (ot *ownTime) FormatUnixMilli(timestamp int64, layout ...string) string {
if len(layout) == 0 {
layout = []string{"2006-01-02 15:04:05.000"}
}
return time.UnixMilli(timestamp).In(time.Local).Format(layout[0])
}
// FormatUnixSec ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:06 2022/7/14
func (ot *ownTime) FormatUnixSec(timestamp int64, layout ...string) string {
if len(layout) == 0 {
layout = []string{"2006-01-02 15:04:05"}
}
return time.Unix(timestamp, 0).In(time.Local).Format(layout[0])
}
// ParseISO8601Time 解析 2006-01-02T15:04:05+08:00 格式时间 -> 2006-01-02 15:04:05
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:48 2022/7/14
func (ot *ownTime) ParseISO8601Time(parseTime string) string {
var (
timeLayout = "2006-01-02T15:04:05+08:00"
formatTime time.Time
err error
)
if formatTime, err = time.Parse(timeLayout, parseTime); nil != err {
return ""
}
return formatTime.In(time.Local).Format("2006-01-02 15:04:05")
}

97
url.go Normal file
View File

@ -0,0 +1,97 @@
// Package util...
//
// Description : util...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-11-04 2:38 下午
package util
import (
"net/url"
"strings"
)
// URLParseResult url解析
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:51 下午 2021/11/4
type URLParseResult struct {
Scheme string `json:"scheme"`
Domain string `json:"domain"`
URI string `json:"uri"`
Parameter map[string]string `json:"parameter"`
}
// ownURL ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:38 2022/5/14
type ownURL struct {
}
// Encode ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:39 下午 2021/11/4
func (ou *ownURL) Encode(inputURL string) string {
return url.QueryEscape(inputURL)
}
// Decode ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:39 下午 2021/11/4
func (ou *ownURL) Decode(inputURL string) (string, error) {
return url.QueryUnescape(inputURL)
}
// Parse url解析
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:39 下午 2021/11/4
func (ou *ownURL) Parse(inputURL string) (*URLParseResult, error) {
var (
parseResult *url.URL
err error
)
if parseResult, err = url.Parse(inputURL); nil != err {
return nil, err
}
detail := &URLParseResult{
Scheme: parseResult.Scheme,
Domain: parseResult.Host,
URI: parseResult.Path,
Parameter: make(map[string]string),
}
for k, v := range parseResult.Query() {
if len(v) > 1 {
detail.Parameter[k] = "[" + strings.Join(v, ",") + "]"
} else {
detail.Parameter[k] = v[0]
}
}
return detail, nil
}
// BuildQueryURL 构建GET链接
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:43 下午 2021/11/4
func (ou *ownURL) BuildQueryURL(apiURL string, parameter map[string]string) string {
u := url.Values{}
for k, v := range parameter {
u.Set(k, v)
}
apiURL = strings.Trim(apiURL, "?")
if strings.Contains(apiURL, "?") {
return apiURL + "&" + u.Encode()
}
return apiURL + "?" + u.Encode()
}

176
user_agent.go Normal file
View File

@ -0,0 +1,176 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-03-31 18:51
package util
import (
"math/rand"
"time"
"github.com/mssola/user_agent"
)
var defaultUserAgentList = []string{
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
"Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
"Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.3 Mobile/14E277 Safari/603.1.30",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1",
"(KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
"Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11",
"(KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6",
"(KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6",
"(KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1",
"(KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5",
"(KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5",
"Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5",
"(KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3",
"(KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24",
"(KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24",
"(KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24",
}
type userAgent struct {
list []string
}
// Set 设置ua池
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:55 2023/3/31
func (ua *userAgent) Set(agentList []string) {
if len(agentList) == 0 {
return
}
ua.list = agentList
}
// GetRandomUA 随机获取UA
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:56 2023/3/31
func (ua *userAgent) GetRandomUA() string {
rand.Seed(time.Now().UnixNano())
idx := rand.Intn(len(ua.list))
return ua.list[idx]
}
// Parse 解析UA
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:31 2023/4/20
func (ua *userAgent) Parse(inputUA string) *UAInfo {
uaInstance := user_agent.New(inputUA)
uaInfo := &UAInfo{
Mozilla: uaInstance.Mozilla(),
Platform: uaInstance.Platform(),
OS: uaInstance.OS(),
Localization: uaInstance.Localization(),
Model: uaInstance.Model(),
Browser: &BrowserInfo{
Engine: "",
EngineVersion: "",
Name: "",
Version: "",
},
OSInfo: &OSInfo{
FullName: uaInstance.OSInfo().FullName,
Name: uaInstance.OSInfo().Name,
Version: uaInstance.OSInfo().Version,
},
Bot: false,
Mobile: false,
Undecided: false,
}
uaInfo.Browser.Engine, uaInfo.Browser.EngineVersion = uaInstance.Engine()
uaInfo.Browser.Name, uaInfo.Browser.Version = uaInstance.Browser()
return uaInfo
}
// UAInfo ua解析结果
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:34 2023/4/20
type UAInfo struct {
Mozilla string `json:"mozilla"`
Platform string `json:"platform"`
OS string `json:"os"`
OSInfo *OSInfo `json:"os_info"`
Localization string `json:"localization"`
Model string `json:"model"`
Browser *BrowserInfo `json:"browser"`
Bot bool `json:"bot"`
Mobile bool `json:"mobile"`
Undecided bool `json:"undecided"`
}
// BrowserInfo 浏览器信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:34 2023/4/20
type BrowserInfo struct {
Engine string `json:"engine"` // 浏览器引擎
EngineVersion string `json:"engine_version"` // 浏览器引擎版本
Name string `json:"name"` // 浏览器名称
Version string `json:"version"` // 浏览器版本
}
// OSInfo 系统信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:34 2023/4/20
type OSInfo struct {
FullName string `json:"full_name"` // 操作系统全称
Name string `json:"name"` // 操作系统名称
Version string `json:"version"` // 操作系统版本
}