util

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2023 License: AGPL-3.0 Imports: 32 Imported by: 0

README

util

介绍

HLTY util

软件架构
util工具库
安装教程
go get gitee.com/lyhuilin/util
更新教程
go get -u gitee.com/lyhuilin/util
使用说明
package main

import (
	"gitee.com/lyhuilin/util"
	//"gitee.com/lyhuilin/util/constvar"
)
func main(){
	……
}
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64StdEncodingDecode

func Base64StdEncodingDecode(input string) ([]byte, error)

func Base64StdEncodingEncodeToString

func Base64StdEncodingEncodeToString(input []byte) string

func BetweenStr

func BetweenStr(str, start, end string) string

取字符串中间,如果未找到返回空字符串

func CheckPingBaseURL

func CheckPingBaseURL(baseURL string) (retBool bool)

自检openAPI服务是否正常运行

func ClearUrl

func ClearUrl(text string) string

清除文本中 url

func CreateUUID

func CreateUUID() (string, error)

生成随机UUID(RFC 4122) create a random UUID with from RFC 4122 adapted from http://github.com/nu7hatch/gouuid

func CrosscheckKey

func CrosscheckKey(key string, maxKey int) (retBool bool)

检查 key 是否存在 true 真 存在,false 不存在/或key为空,不存在存储

func CrosscheckKeyWithBase

func CrosscheckKeyWithBase(keyBase, key string, maxKey int) (retBool bool)

func EncryptHmacSha256

func EncryptHmacSha256(data string, secret string) string

func EncryptHmacmd5

func EncryptHmacmd5(src, key string) (cryptext string)

https://www.jianshu.com/p/02da10ca45d1 hmac-md5加密

func EncryptMd5

func EncryptMd5(source string) (cryptext string)

hash plaintext with md5

func EncryptMd5Byte

func EncryptMd5Byte(source []byte) (cryptext string)

hash plaintext with md5

func EncryptSha1

func EncryptSha1(plaintext string) (cryptext string)

hash plaintext with SHA-1

func FileExist

func FileExist(path string) bool

func GB18030String

func GB18030String(str string) string

func Gb18030ToUtf8

func Gb18030ToUtf8(s []byte) ([]byte, error)

func Gb18030ToUtf8String

func Gb18030ToUtf8String(s string) string

func GetAbsPath

func GetAbsPath(tmpName, defaultName string) string

获取绝对路径 tmpName:绝对/相对路径,defaultName:默认路径

func GetBetweenStr

func GetBetweenStr(str, start, end string) string

取字符串中间 如果未找到,原样返回。

func GetRedirectUrl

func GetRedirectUrl(str string, isClear bool) (string, error)

可还原的链接: 淘宝 https://s.click.taobao.com/rioMXxu 二合一链接 苏宁 https://sugs.suning.com/HpGbzgk6 https://sugs.suning.com/HpCPkl3B 唯品会 https://t.vip.com/MhW6RosYXqA

func GetRedirectUrlJD

func GetRedirectUrlJD(str string, isClear bool) (retText string, err error)

可还原的链接: https://u.jd.com/K7oUzZ

func GetRedirectUrlWithTCN

func GetRedirectUrlWithTCN(str string, isClear bool) (retText string, err error)

还原新浪短链接 urlOrg, err := util.GetRedirectUrlEx("http://t.cn/A6c2Ka9G", false) fmt.Println(err, urlOrg) urlOrg, err = util.GetRedirectUrlEx(urlOrg, false) fmt.Println(err, urlOrg)

func GetRel

func GetRel(basepath, targpath string) string

https://www.cnblogs.com/malukang/p/12907945.html GetRel(uploadDir,uploadFilePath) 获取相对路径

func GetSafeHtml

func GetSafeHtml(text string) (string, error)

获取 text 的 安全html格式内容(转义html)

func GetTextCleaner

func GetTextCleaner(textStr string) (retText, retHash string)

func GetUrlToByte

func GetUrlToByte(url string) (retByte []byte, err error)

func GetUrlToByteEx

func GetUrlToByteEx(url string, timeOut time.Duration) (retByte []byte, err error)

func GetUrlToString

func GetUrlToString(url string) (retText string, err error)

func GetUrlToStringEx

func GetUrlToStringEx(url string, timeOut time.Duration) (retText string, err error)

func GetUrlWithCookieToString

func GetUrlWithCookieToString(url, cookie, host, referer, userAgent string) (retText string, err error)

func GetUrlWithCookieToStringAndSaveFile

func GetUrlWithCookieToStringAndSaveFile(url, cookie, host, referer, userAgent, filePath string) (retText string, err error)

func Getwd

func Getwd() string

获取程序运行目录相当于linux的pwd

func Gzip

func Gzip(data []byte)

func IsExist

func IsExist(f string) bool

判断文件/目录是否存在 IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.

func IsExists

func IsExists(path string) (bool, error)

判断文件夹是否存在

func IsFile

func IsFile(f string) bool

区分目录和文件 IsFile checks whether the path is a file, it returns false when it's a directory or does not exist.

func IsFileExist

func IsFileExist(path string) (bool, error)

FileExist 判断文件是否存在

func JsonDecode

func JsonDecode(data string, inter interface{}) error

func JsonDecodeByte

func JsonDecodeByte(bytes []byte) map[string]interface{}

func JsonDecodeString

func JsonDecodeString(String string) map[string]interface{}

func JsonEncode

func JsonEncode(data interface{}) string

func JsonEncodeMapToByte

func JsonEncodeMapToByte(stringMap map[string]interface{}) []byte

func KeyworldListParse

func KeyworldListParse(keyworldListStr string) []string

解析 k|k1 到数组

func KeyworldListParseToArrMap

func KeyworldListParseToArrMap(keyworldText string) []map[string]string

解析 k>>kc|k1>>kc1 到 arr map

func KeyworldListParseToMap

func KeyworldListParseToMap(keyworldText string) map[string]string

解析 k>>kc|k1>>kc1 到 map

func LeftStr

func LeftStr(str, posStr string, isContainsPosStr bool) string

取字符串左侧

func MD5Hash

func MD5Hash(text string) string

*

  • @note
  • 获取md5 hash串
  • @param string text 源串 *
  • @return string

func Marshal

func Marshal(obj interface{}) string

func MarshalEx

func MarshalEx(obj interface{}, isEscapeHTML bool) string

json编码后,是否对HTML内容进行转义处理。

func MkDir

func MkDir(path string) error

func MsgSignatureCheck

func MsgSignatureCheck(msgmsgSignature string, maxKey int) (retBool bool)

检查 msgmsgSignature 是否已记录 true 真 存在,false 不存在,不存在存储

func MsgSignatureCheckEx

func MsgSignatureCheckEx(msgmsgSignature, msgText string, maxKey int) (retBool bool)

检查 msgmsgSignature 是否已记录 true 真 存在,false 不存在,不存在存储

func MsgTextCleanerCheck

func MsgTextCleanerCheck(msgText string, maxKey int) (retBool bool)

func MsgTextToHtml

func MsgTextToHtml(msg string) (retText string, err error)

func OpenURL

func OpenURL(url string) error

open opens the specified URL in the default browser of the user.

func PostToServer

func PostToServer(serverApiUrl, serverToken string, postData interface{}) (ret []byte, err error)

func PostToServerEx

func PostToServerEx(serverApiUrl, serverToken string, postData interface{}) (ret string, err error)

func RandTimeMinute

func RandTimeMinute(n int64) time.Duration

休眠随机时间(分钟)2_n*2

func RandTimeSecond

func RandTimeSecond(n int64) time.Duration

休眠随机时间(秒) 2_n*2

func ReadFile

func ReadFile(path string) (retByte []byte, err error)

ReadFile 读取文件 读取失败返回 nil

func RemoveFile

func RemoveFile(filePath string) error

func RemoveRep

func RemoveRep(slc []string) []string

元素去重

func RemoveRepByLoop

func RemoveRepByLoop(slc []string) []string

元素去重

func RemoveRepByMap

func RemoveRepByMap(slc []string) []string

通过map主键唯一的特性过滤重复元素

func RightStr

func RightStr(str, posStr string, isContainsPosStr bool) string

取字符串右侧

func RuneIndex

func RuneIndex(p []byte, n int) (int, bool)

RuneIndex 返回 p 中第 n 个字符的位置索引,可以通过索引位置截取 []byte 如果 n 超过 p 中字符的数量,则第二个参数返回 false 错误的或短的编码被当做宽度为一个字节的单一字符。

func RuneIndexInString

func RuneIndexInString(s string, n int) (int, bool)

RuneIndexInString 返回 s 中第 n 个字符的位置索引,可以通过索引位置截取字符串 如果 n 超过 s 中字符的数量,则第二个参数返回 false 错误的或短的编码被当做宽度为一个字节的单一字符。

func RuneSub

func RuneSub(p []byte, start, length int) []byte

RuneSub 提供符文数量截取字节数组的方法,针对多字节字符安全高效的截取 如果 start 是非负数,返回的字符串将从 string 的 start 位置开始,从 0 开始计算。例如,在字符串 “abcdef” 中,在位置 0 的字符是 “a”,位置 2 的字符串是 “c” 等等。 如果 start 是负数,返回的字符串将从 string 结尾处向前数第 start 个字符开始。 如果 string 的长度小于 start,将返回空字符串。

如果提供了正数的 length,返回的字符串将从 start 处开始最多包括 length 个字符(取决于 string 的长度)。 如果提供了负数的 length,那么 string 末尾处的 length 个字符将会被省略(若 start 是负数则从字符串尾部算起)。如果 start 不在这段文本中,那么将返回空字符串。 如果提供了值为 0 的 length,返回的子字符串将从 start 位置开始直到字符串结尾。

func RuneSubString

func RuneSubString(s string, start, length int) string

RuneSubString 提供符文数量截取字符串的方法,针对多字节字符安全高效的截取 如果 start 是非负数,返回的字符串将从 string 的 start 位置开始,从 0 开始计算。例如,在字符串 “abcdef” 中,在位置 0 的字符是 “a”,位置 2 的字符串是 “c” 等等。 如果 start 是负数,返回的字符串将从 string 结尾处向前数第 start 个字符开始。 如果 string 的长度小于 start,将返回空字符串。

如果提供了正数的 length,返回的字符串将从 start 处开始最多包括 length 个字符(取决于 string 的长度)。 如果提供了负数的 length,那么 string 末尾处的 length 个字符将会被省略(若 start 是负数则从字符串尾部算起)。如果 start 不在这段文本中,那么将返回空字符串。 如果提供了值为 0 的 length,返回的子字符串将从 start 位置开始直到字符串结尾。

func SleepRandTimeMinute

func SleepRandTimeMinute(n int64)

休眠随机时间(分钟)2_n*2

func SleepRandTimeSecond

func SleepRandTimeSecond(n int64)

休眠随机时间(秒) 2_n*2

func StructToMap

func StructToMap(data interface{}) map[string]interface{}

func SubStrDecodeRuneInString

func SubStrDecodeRuneInString(s string, length int) string

截取字符串

func SubStrRange

func SubStrRange(s string, length int) string

func SubStrRuneN

func SubStrRuneN(textStr string, n int) (retText string)

截图字符串前N个字符内容

func TbkPidParse

func TbkPidParse(pid string) (siteID, adzoneID string)

func TimeStampNow

func TimeStampNow() int64

13位时间戳 UnixMilli

func TimeStampNowEx

func TimeStampNowEx(isSecond bool) int64

fmt.Println(time.Now().Unix()) fmt.Println(time.Now().UnixNano() / 1e6) 13位时间戳 UnixMilli isSecond=true 返回10位时间戳。isSecond=false 返回13位时间戳

func TinyURLAPI

func TinyURLAPI(langURL, apiBaseURL string, timeDuration time.Duration, isJson bool) (retText string, err error)

长链接转短链接 http://127.0.0.1:8089/tinyURL?url=http://www.lyhuilin.com {"code":0,"message":"OK","data":{"url":"http://www.lyhuilin.com","short_url":"https://u.nav.xin/4i"}}

func TrimEmoji

func TrimEmoji(s string) string

清除emoji表情

func TrimHtml

func TrimHtml(src string) string

去除html标签

func UnGzip

func UnGzip(byte []byte) []byte

func UnicodeEmojiCode

func UnicodeEmojiCode(s string) string

表情转换

func UnicodeEmojiDecode

func UnicodeEmojiDecode(s string) string

表情解码

func UrlMapToTGHTML

func UrlMapToTGHTML(urlMap map[string]string) (ret string, err error)

hanMap := make(map[string]string, 0) hanMap["汉//\\字"] = "http://han.com" hanMap["汉.df||字2"] = "http://han2.com" ret, err := util.UrlMapToTGHTML(hanMap)

if err != nil {
	fmt.Println("出错了", err)
} else {

	fmt.Println("ret", ret)
}

urlMap[title]url,转义,输出为TG支持的HTML格式文案

func UrlPatchHttp

func UrlPatchHttp(url string) (ret string)

补全网址协议头

func UrlRegMatchReplace

func UrlRegMatchReplace(str string) (ret string)

func UrlRegMatchReplaceToMarkdown

func UrlRegMatchReplaceToMarkdown(str string) (ret string)

func UrlRegMatchReplaceToTGHTML

func UrlRegMatchReplaceToTGHTML(str string) (ret string, err error)

识别文案中链接,并转义,输出为TG支持的HTML格式文案

func UrlTextToMap

func UrlTextToMap(urlText string) (ret map[string]string, err error)

消息中链接识别

func Utf8ToGb18030

func Utf8ToGb18030(s []byte) ([]byte, error)

func Utf8ToGb18030String

func Utf8ToGb18030String(s string) string

func VerifyEmailFormat

func VerifyEmailFormat(email string) bool

email verify

func VerifyMobileFormat

func VerifyMobileFormat(mobileNum string) bool

mobile verify

func VerifyNameFormat

func VerifyNameFormat(name string) bool

username verify

func WriteFile

func WriteFile(filePath string, fileBody []byte) error

Types

type BCounter

type BCounter struct {
	// contains filtered or unexported fields
}
var Counter *BCounter

计数器

func (*BCounter) Get

func (c *BCounter) Get() int64

func (*BCounter) Inc

func (c *BCounter) Inc()

func (*BCounter) IsNice

func (c *BCounter) IsNice() bool

func (*BCounter) IsNiceWithNum

func (c *BCounter) IsNiceWithNum(num int64) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL