Compare commits
3 Commits
master
...
428dc77280
Author | SHA1 | Date | |
---|---|---|---|
428dc77280 | |||
6446cd58f1 | |||
4c99d24de6 |
@ -21,9 +21,6 @@ type calculate struct {
|
|||||||
//
|
//
|
||||||
// Date : 15:50 2022/7/17
|
// Date : 15:50 2022/7/17
|
||||||
func (c *calculate) GetTotalPage(total int64, pageSize int64) int64 {
|
func (c *calculate) GetTotalPage(total int64, pageSize int64) int64 {
|
||||||
if pageSize <= 0 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
totalPage := total / pageSize
|
totalPage := total / pageSize
|
||||||
if total%pageSize > 0 {
|
if total%pageSize > 0 {
|
||||||
totalPage++
|
totalPage++
|
||||||
|
123
chrome.go
Normal file
123
chrome.go
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
// Package util ...
|
||||||
|
//
|
||||||
|
// Description : util ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2023-01-24 15:36
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/tebeka/selenium"
|
||||||
|
"github.com/tebeka/selenium/chrome"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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://detail.tmall.hk/hk/item.htm?id=605481322232&rn=bbb58fe2f3e13e03b21df9c396f23fbc&abbucket=12"
|
||||||
|
w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", c.port))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("connect to the webDriver faild", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = w_b1.Get(url)
|
||||||
|
|
||||||
|
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()
|
||||||
|
_ = ioutil.WriteFile("test.png", imgByteData, 0777)
|
||||||
|
|
||||||
|
//获取网页源码
|
||||||
|
pageSource, err := w_b1.PageSource()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("get page faild", 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()
|
||||||
|
}
|
352
chrome_test.go
Normal file
352
chrome_test.go
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
// Package util ...
|
||||||
|
//
|
||||||
|
// Description : util ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2023-01-24 16:16
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/tebeka/selenium"
|
||||||
|
)
|
||||||
|
|
||||||
|
type itemCookie struct {
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
ExpirationDate float64 `json:"expirationDate"`
|
||||||
|
HostOnly bool `json:"hostOnly"`
|
||||||
|
HTTPOnly bool `json:"httpOnly"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
SameSite string `json:"sameSite"`
|
||||||
|
Secure bool `json:"secure"`
|
||||||
|
Session bool `json:"session"`
|
||||||
|
StoreID interface{} `json:"storeId"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewChrome(t *testing.T) {
|
||||||
|
cookieJson := `[
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"csg",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"fc697e5b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"sg",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"686"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":true,
|
||||||
|
"name":"cookie17",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"UoYenbvzgsH2Rg%3D%3D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1691071546,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"isg",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"BCUlEDTRqvr1_M7BGtKJXclsNOdfYtn0p7prhScK4dxrPkWw77LpxLPcyKJIJfGs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1691071546,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"tfstk",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":null,
|
||||||
|
"secure":false,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"cxL1B7jgeKLEdyg0SOGEg-9RLpQAwNrlGV661AqpnM-PVT1cBzW7X890LZ5AO"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":true,
|
||||||
|
"name":"cookie2",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"18a65977fe14410e7165b578f17cfcc9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":"detail.tmall.hk",
|
||||||
|
"expirationDate":1678111546,
|
||||||
|
"hostOnly":true,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"pnm_cku822",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":null,
|
||||||
|
"secure":false,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"098%23E1hvIQvUvbZvjQCkvvvvvjiWRs5Z1jEjR2dvgj3mPmPZtj1bRsLWgjtPPsdwgjAevpvhvvmv9F9CvvpvvvvvvvhvC9v9vvCvpv9CvhQhRP%2BvClsWafmxdByaWGjxs4hZ%2B3%2Bua4oQD40OwkM6qwVHRfvrcKkxfwkKSeQEfw1lY2Kz8Z0vQbmxdXyaUExr1WkKHkx%2F1W3lYCI7Kvhv8vvvvU1vpvvvvvv2ohCvCVUvvvnUphvp4vvvv63vpCvhvvv2ohCvhvoIvpvUvvmvplsFoXRUvpvjmvmC9cHCtvgCvvpvvvvv"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":true,
|
||||||
|
"name":"cookie1",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"BxNXlt0D51JOFzwVkC855E5hMO%2FLJ%2BIjtQKRXjOlrHA%3D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"cancelledSubSites",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,t
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"empty"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1710079422.393609,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":true,
|
||||||
|
"name":"enc",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"6CoIBy8lnAje2hQ5K99yGofrAdPkNuvRIKCK5JA5Q1%2Boub3YNh5iNsNvpfU4Gc%2F9X98U3fXBxBLv3PYp6%2Fw9Eg%3D%3D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":2303824744,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"cna",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"Unx0GIPP62UCAdIMnVT6ZNWT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"_l_g_",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"Ug%3D%3D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"_nk_",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"zhangdeman6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"_tb_token_",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"30407d3b645b3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"dnk",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"zhangdeman6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1691071546,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"l",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":null,
|
||||||
|
"secure":false,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"fB_jjhQqT3bcatTDBOfaFurza77OSIRYYuPzaNbMi9fP_XfB5rWCW6JFWaY6C3GVF602R38_FFteBeYBc3xonxv9G-QXeLHmndLHR35.."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1707084222.393463,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"lid",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"zhangdeman6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"login",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":true,
|
||||||
|
"name":"sgcookie",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"E100RQxy9HrGQ0dqJP7D0skhsmAR0MNIWjOxfE9v%2Booy%2BVv3jquiIls3KiK%2BNCGCVLIO3oLnQg5eHL7p9OxXTQP5zZlMCUWIymMwWp1fGTUu%2F51XqdviOSUH15DdkYu26Isz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"t",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"6f803235fb4e32d8ef21df8238179fbe"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"tracknick",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"zhangdeman6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"uc1",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"existShop=false&cookie14=UoezSgPKm%2FLtYA%3D%3D&pas=0&cookie16=U%2BGCWk%2F74Mx5tgzv3dWpnhjPaQ%3D%3D&cookie15=V32FPkk%2Fw0dUvg%3D%3D&cookie21=W5iHLLyFfX5Xzx7qNYvXUg%3D%3D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"unb",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":true,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"1708690398"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain":".tmall.hk",
|
||||||
|
"expirationDate":1675605805,
|
||||||
|
"hostOnly":false,
|
||||||
|
"httpOnly":false,
|
||||||
|
"name":"xlly_s",
|
||||||
|
"path":"/",
|
||||||
|
"sameSite":"no_restriction",
|
||||||
|
"secure":true,
|
||||||
|
"session":false,
|
||||||
|
"storeId":null,
|
||||||
|
"value":"1"
|
||||||
|
}
|
||||||
|
]`
|
||||||
|
var inputCookieList []itemCookie
|
||||||
|
_ = json.Unmarshal([]byte(cookieJson), &inputCookieList)
|
||||||
|
cookieList := make([]*selenium.Cookie, 0)
|
||||||
|
for _, item := range inputCookieList {
|
||||||
|
expiry := uint(item.ExpirationDate)
|
||||||
|
if expiry == 0 {
|
||||||
|
expiry = 1690105309
|
||||||
|
}
|
||||||
|
if item.Domain == ".tmall.hk" {
|
||||||
|
item.Domain = "citizenwatchhk" + item.Domain
|
||||||
|
}
|
||||||
|
cookieList = append(cookieList, &selenium.Cookie{
|
||||||
|
Name: item.Name,
|
||||||
|
Value: item.Value,
|
||||||
|
Path: item.Path,
|
||||||
|
Domain: item.Domain,
|
||||||
|
Secure: item.Secure,
|
||||||
|
Expiry: expiry,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
instance, _ := NewChrome("/Users/zhangdeman/Downloads/chromedriver", 9515, true, nil)
|
||||||
|
instance.Render(cookieList)
|
||||||
|
}
|
4
cli.go
4
cli.go
@ -23,9 +23,7 @@ type cli struct {
|
|||||||
func (c *cli) ParseCLIParameter(parameterNameList []string) map[string]string {
|
func (c *cli) ParseCLIParameter(parameterNameList []string) map[string]string {
|
||||||
cliParameterTable := make(map[string]*string)
|
cliParameterTable := make(map[string]*string)
|
||||||
for _, parameterName := range parameterNameList {
|
for _, parameterName := range parameterNameList {
|
||||||
var val string
|
cliParameterTable[parameterName] = flag.String(parameterName, "", parameterName)
|
||||||
flag.StringVar(&val, parameterName, "", parameterName)
|
|
||||||
cliParameterTable[parameterName] = &val
|
|
||||||
}
|
}
|
||||||
// 这里有一个非常中的操作,转换,必须调用该方法
|
// 这里有一个非常中的操作,转换,必须调用该方法
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
103
console.go
103
console.go
@ -1,103 +0,0 @@
|
|||||||
// Package util ...
|
|
||||||
//
|
|
||||||
// Description : util ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2023-04-04 16:09
|
|
||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// console 终端数据输出的一些操作
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:10 2023/4/4
|
|
||||||
type console struct {
|
|
||||||
enable bool
|
|
||||||
formatJson bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable 启用
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:10 2023/4/4
|
|
||||||
func (c *console) Enable() {
|
|
||||||
c.enable = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable 禁用
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:11 2023/4/4
|
|
||||||
func (c *console) Disable() {
|
|
||||||
c.enable = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormatJson 是否格式化json
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:35 2023/4/4
|
|
||||||
func (c *console) FormatJson(format bool) {
|
|
||||||
c.formatJson = format
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output 禁用终端输出
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:13 2023/4/4
|
|
||||||
func (c *console) Output(dataList ...interface{}) {
|
|
||||||
if !c.enable {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, item := range dataList {
|
|
||||||
fmt.Println(c.getDataStr(item))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getDataStr 数据转换为字符串
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:14 2023/4/4
|
|
||||||
func (c *console) getDataStr(data interface{}) string {
|
|
||||||
if nil == data {
|
|
||||||
return "nil"
|
|
||||||
}
|
|
||||||
dataValue := reflect.ValueOf(data)
|
|
||||||
dataType := reflect.TypeOf(data).Kind()
|
|
||||||
if dataType == reflect.Ptr {
|
|
||||||
dataValue = dataValue.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
switch dataValue.Kind() {
|
|
||||||
case reflect.Map:
|
|
||||||
fallthrough
|
|
||||||
case reflect.Slice:
|
|
||||||
fallthrough
|
|
||||||
case reflect.Array:
|
|
||||||
fallthrough
|
|
||||||
case reflect.Struct:
|
|
||||||
byteData, _ := json.Marshal(data)
|
|
||||||
if !c.formatJson {
|
|
||||||
return string(byteData)
|
|
||||||
}
|
|
||||||
var out bytes.Buffer
|
|
||||||
_ = json.Indent(&out, []byte(string(byteData)+"\n"), "", "\t")
|
|
||||||
return string(out.Bytes())
|
|
||||||
case reflect.Func:
|
|
||||||
return dataValue.String()
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("%v", data)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
// Package util ...
|
|
||||||
//
|
|
||||||
// Description : util ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2023-04-04 16:21
|
|
||||||
package util
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func Test_console_Output(t *testing.T) {
|
|
||||||
Console.Enable()
|
|
||||||
var a = map[string]interface{}{
|
|
||||||
"name": "baicha",
|
|
||||||
}
|
|
||||||
type U struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
b := &U{Name: "qinghuan"}
|
|
||||||
c := U{Name: "test"}
|
|
||||||
Console.Output(a, b, c)
|
|
||||||
}
|
|
@ -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"` // 递归读取, 且当前文件为目录
|
|
||||||
}
|
|
158
file.go
Normal file
158
file.go
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
// Package util...
|
||||||
|
//
|
||||||
|
// Description : 文件相关工具
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2021-04-26 6:00 下午
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"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()
|
||||||
|
}
|
137
filter.go
Normal file
137
filter.go
Normal 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
57
filter_test.go
Normal 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)
|
||||||
|
}
|
23
go.mod
23
go.mod
@ -1,20 +1,21 @@
|
|||||||
module git.zhangdeman.cn/zhangdeman/util
|
module git.zhangdeman.cn/zhangdeman/util
|
||||||
|
|
||||||
go 1.21
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/Jeffail/gabs v1.4.0
|
||||||
github.com/mozillazg/go-pinyin v0.20.0
|
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
|
||||||
|
github.com/go-ini/ini v1.66.6
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/spaolacci/murmur3 v1.1.0
|
github.com/spaolacci/murmur3 v1.1.0
|
||||||
|
github.com/tidwall/gjson v1.14.1
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b // indirect
|
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71 // indirect
|
github.com/stretchr/testify v1.8.0 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d // indirect
|
github.com/tebeka/selenium v0.9.9 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
github.com/tidwall/pretty v1.2.0 // 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
|
|
||||||
)
|
)
|
||||||
|
146
go.sum
146
go.sum
@ -1,23 +1,137 @@
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b h1:C7KftnLh7dOqzNRs5dn/9yqMDvuqMn5RCglvV6bY758=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20230815040024-2b12dd51d19b/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71 h1:nvVSH+Ju8EmoPiPHTae5lxHo4kDjROYChs19Yayz+NY=
|
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20231224145141-489e31b07a71/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
cloud.google.com/go v0.41.0/go.mod h1:OauMR7DV8fzvZIl2qg6rkaIhD/vmgk4iwEw/h6ercmg=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d h1:TV0BCQQewBEtLsv3i9gXkxLFd5A5bWBTiNd3D/I5o4Q=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20231224125439-01f39b6ea08d/go.mod h1:w7kG4zyTJ1uPFaTWhze+OQuaUBINT2XnDxpyiM6ctc0=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000 h1:ulssHpUMNoxws/fdJD+bhw8tuMPXp+jB54WwLdJNTsU=
|
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
|
||||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20231224145327-d9aed3d80000/go.mod h1:rt9wlUf/Y6lpZBXb0KK8n0JxEbI1J5JB73XgQmGHJqw=
|
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
|
||||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
|
||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
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 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
||||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
|
||||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
|
||||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-ini/ini v1.66.6 h1:h6k2Bb0HWS/BXXHCXj4QHjxPmlIU4NK+7MuLp9SD+4k=
|
||||||
|
github.com/go-ini/ini v1.66.6/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||||
|
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/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/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 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
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/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
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.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||||
|
github.com/tidwall/gjson v1.14.1/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 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||||
|
github.com/tidwall/pretty v1.2.0/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/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/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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
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=
|
||||||
|
33
init.go
33
init.go
@ -10,23 +10,40 @@ package util
|
|||||||
var (
|
var (
|
||||||
// Cli ...
|
// Cli ...
|
||||||
Cli *cli
|
Cli *cli
|
||||||
|
// File ...
|
||||||
|
File *file
|
||||||
// Hash ...
|
// Hash ...
|
||||||
Hash *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 *calculate
|
Calculate *calculate
|
||||||
// Project ...
|
// Project ...
|
||||||
Project *project
|
Project = &project{}
|
||||||
// Console 控制台输出数据
|
|
||||||
Console *console
|
|
||||||
// PinYin 汉字转拼音
|
|
||||||
PinYin *pinYin
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Cli = &cli{}
|
Cli = &cli{}
|
||||||
|
File = &file{}
|
||||||
Hash = &hash{}
|
Hash = &hash{}
|
||||||
|
IP = &ip{}
|
||||||
|
JSON = &ownJSON{}
|
||||||
|
String = &stringOperate{}
|
||||||
|
Struct = &ownStruct{}
|
||||||
|
Time = &ownTime{}
|
||||||
|
URL = &ownURL{}
|
||||||
|
Map = &ownMap{}
|
||||||
Calculate = &calculate{}
|
Calculate = &calculate{}
|
||||||
Project = &project{}
|
|
||||||
Console = &console{}
|
|
||||||
PinYin = &pinYin{}
|
|
||||||
}
|
}
|
||||||
|
59
ip.go
Normal file
59
ip.go
Normal 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()
|
||||||
|
}
|
99
json.go
Normal file
99
json.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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("")
|
||||||
|
}
|
||||||
|
}
|
216
map.go
Normal file
216
map.go
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
// 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])
|
||||||
|
}
|
12
project.go
12
project.go
@ -12,8 +12,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type project struct {
|
type project struct {
|
||||||
@ -90,13 +88,3 @@ func (p *project) GetProjectPath() string {
|
|||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHomeDir 获取家目录
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 22:31 2023/4/18
|
|
||||||
func (p *project) GetHomeDir() string {
|
|
||||||
homePath, _ := homedir.Dir()
|
|
||||||
return homePath
|
|
||||||
}
|
|
||||||
|
174
string.go
Normal file
174
string.go
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
38
struct.go
Normal file
38
struct.go
Normal 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
|
||||||
|
}
|
79
time.go
Normal file
79
time.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// 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 {
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCurrentFormatTime 获取当前时间的格式化时间(秒)
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 1:34 上午 2021/10/7
|
||||||
|
func (ot *ownTime) GetCurrentFormatTime() string {
|
||||||
|
return time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatUnixNano 格式化纳秒时间戳
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 11:54 2022/7/14
|
||||||
|
func (ot *ownTime) FormatUnixNano(timestamp int64) string {
|
||||||
|
nano := timestamp % 1e6
|
||||||
|
milli := timestamp / 1e6
|
||||||
|
return ot.FormatUnixMilli(milli) + fmt.Sprintf(" %v", nano)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatUnixMilli 格式化毫秒时间戳
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 11:55 2022/7/14
|
||||||
|
func (ot *ownTime) FormatUnixMilli(timestamp int64) string {
|
||||||
|
time.Now().UnixMilli()
|
||||||
|
return time.UnixMilli(timestamp).Format("2006-01-02 15:04:05.000")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatUnixSec ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 12:06 2022/7/14
|
||||||
|
func (ot *ownTime) FormatUnixSec(timestamp int64) string {
|
||||||
|
return time.UnixMilli(timestamp).Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.Format("2006-01-02 15:04:05")
|
||||||
|
}
|
97
url.go
Normal file
97
url.go
Normal 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()
|
||||||
|
}
|
208
util.go
208
util.go
@ -1,208 +0,0 @@
|
|||||||
// Package util ...
|
|
||||||
//
|
|
||||||
// Description : util ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2023-06-25 17:22
|
|
||||||
package util
|
|
||||||
|
|
||||||
import "github.com/mozillazg/go-pinyin"
|
|
||||||
|
|
||||||
// PinYinArg 设置选项方法
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:33 2023/6/25
|
|
||||||
type PinYinArg func(arg *pinyin.Args)
|
|
||||||
|
|
||||||
// 拼音风格的设置
|
|
||||||
|
|
||||||
// PinYinStyleNormal ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:37 2023/6/25
|
|
||||||
func PinYinStyleNormal() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneStand 声调风格1,拼音声调在韵母第一个字母上。如: zhōng guó
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:38 2023/6/25
|
|
||||||
func PinYinStyleToneStand() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Tone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneAfterYunMu 声调风格2,即拼音声调在各个韵母之后,用数字 [1-4] 进行表示。如: zho1ng guo2
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:39 2023/6/25
|
|
||||||
func PinYinStyleToneAfterYunMu() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Tone2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneAtEnding 声调风格3,即拼音声调在各个拼音之后,用数字 [1-4] 进行表示。如: zhong1 guo2
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:40 2023/6/25
|
|
||||||
func PinYinStyleToneAtEnding() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Tone3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleShengMu 声母风格,只返回各个拼音的声母部分。如: zh g 。注意:不是所有的拼音都有声母
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:41 2023/6/25
|
|
||||||
func PinYinStyleShengMu() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Initials
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleFirstLetter 首字母风格,只返回拼音的首字母部分。如: z g
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:42 2023/6/25
|
|
||||||
func PinYinStyleFirstLetter() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.FirstLetter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleYunMu 韵母风格,只返回各个拼音的韵母部分,不带声调。如: ong uo
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:43 2023/6/25
|
|
||||||
func PinYinStyleYunMu() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.Finals
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneYunMu 韵母风格1,带声调,声调在韵母第一个字母上。如: ōng uó
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:44 2023/6/25
|
|
||||||
func PinYinStyleToneYunMu() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.FinalsTone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneYunMuAtStart 韵母风格2,带声调,声调在各个韵母之后,用数字 [1-4] 进行表示。如: o1ng uo2
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:45 2023/6/25
|
|
||||||
func PinYinStyleToneYunMuAtStart() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.FinalsTone2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleToneYunMuAtEnding 韵母风格3,带声调,声调在各个拼音之后,用数字 [1-4] 进行表示。如: ong1 uo2
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:40 2023/6/25
|
|
||||||
func PinYinStyleToneYunMuAtEnding() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Style = pinyin.FinalsTone3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼音风格设置结束
|
|
||||||
|
|
||||||
// PinYinStyleWithSeparator 设置拼音的分隔符
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:59 2023/6/25
|
|
||||||
func PinYinStyleWithSeparator(separator string) PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
if len(separator) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
arg.Separator = separator
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYinStyleWithHeteronym 开启多音字模式
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 18:03 2023/6/25
|
|
||||||
func PinYinStyleWithHeteronym() PinYinArg {
|
|
||||||
return func(arg *pinyin.Args) {
|
|
||||||
arg.Heteronym = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinYin 汉字转拼音
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:23 2023/6/25
|
|
||||||
type pinYin struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert 汉字生成拼音
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:26 2023/6/25
|
|
||||||
func (py *pinYin) Convert(text string, argFuncList ...PinYinArg) string {
|
|
||||||
arg := pinyin.NewArgs()
|
|
||||||
arg.Separator = " "
|
|
||||||
for _, argFunc := range argFuncList {
|
|
||||||
argFunc(&arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pinyin.Slug(text, arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConvertSingle 每个字一个读音, 支持多音字
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 18:02 2023/6/25
|
|
||||||
func (py *pinYin) ConvertSingle(text string, argFuncList ...PinYinArg) []string {
|
|
||||||
arg := pinyin.NewArgs()
|
|
||||||
arg.Separator = " "
|
|
||||||
for _, argFunc := range argFuncList {
|
|
||||||
argFunc(&arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pinyin.LazyPinyin(text, arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConvertWithHeteronym 多音字模式
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 18:02 2023/6/25
|
|
||||||
func (py *pinYin) ConvertWithHeteronym(text string, argFuncList ...PinYinArg) [][]string {
|
|
||||||
arg := pinyin.NewArgs()
|
|
||||||
arg.Separator = " "
|
|
||||||
for _, argFunc := range argFuncList {
|
|
||||||
argFunc(&arg)
|
|
||||||
}
|
|
||||||
return pinyin.Pinyin(text, arg)
|
|
||||||
}
|
|
Reference in New Issue
Block a user