remove network code

This commit is contained in:
白茶清欢 2023-08-10 14:39:45 +08:00
parent 17efb38b18
commit 8425926115
6 changed files with 0 additions and 476 deletions

View File

@ -1,33 +0,0 @@
// 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()
}

20
init.go
View File

@ -14,16 +14,12 @@ var (
File *file File *file
// Hash ... // Hash ...
Hash *hash Hash *hash
// IP ...
IP *ip
// JSON ... // JSON ...
JSON *ownJSON JSON *ownJSON
// String ... // String ...
String *stringOperate String *stringOperate
// Struct ... // Struct ...
Struct *ownStruct Struct *ownStruct
// URL ...
URL *ownURL
// Map ... // Map ...
Map *ownMap Map *ownMap
// Calculate ... // Calculate ...
@ -34,12 +30,8 @@ var (
Array *array Array *array
// JWT ... // JWT ...
JWT *ownJwt JWT *ownJwt
// UserAgent ...
UserAgent *userAgent
// Console 控制台输出数据 // Console 控制台输出数据
Console *console Console *console
// Browser 浏览器操作实例
Browser *browser
// PinYin 汉字转拼音 // PinYin 汉字转拼音
PinYin *pinYin PinYin *pinYin
) )
@ -48,26 +40,14 @@ func init() {
Cli = &cli{} Cli = &cli{}
File = &file{} File = &file{}
Hash = &hash{} Hash = &hash{}
IP = &ip{}
JSON = &ownJSON{} JSON = &ownJSON{}
String = &stringOperate{} String = &stringOperate{}
Struct = &ownStruct{} Struct = &ownStruct{}
URL = &ownURL{}
Map = &ownMap{} Map = &ownMap{}
Calculate = &calculate{} Calculate = &calculate{}
Project = &project{} Project = &project{}
Array = &array{} Array = &array{}
JWT = &ownJwt{} JWT = &ownJwt{}
UserAgent = &userAgent{
list: defaultUserAgentList,
}
Console = &console{} Console = &console{}
Browser = &browser{
commandTable: map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
},
}
PinYin = &pinYin{} PinYin = &pinYin{}
} }

59
ip.go
View File

@ -1,59 +0,0 @@
// 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()
}

91
time.go
View File

@ -1,91 +0,0 @@
// 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
View File

@ -1,97 +0,0 @@
// 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()
}

View File

@ -1,176 +0,0 @@
// 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"` // 操作系统版本
}