utils

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 37 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AES_CBC = "cbc"
	AES_ECB = "ecb"
)
View Source
const (
	//前景色
	FBLACK   = 30
	FRED     = 31
	FGREEN   = 32
	FYELLOW  = 33
	FBLUE    = 34
	FFUCHSIA = 35
	FCYAN    = 36
	FWHITE   = 37
	//背景色
	BBLACK   = 40
	BRED     = 41
	BGREEN   = 42
	BYELLOW  = 43
	BBLUE    = 44
	BFUCHSIA = 45
	BCYAN    = 46
	BWHITE   = 47
	//显示模式
	SDEF = 0 //终端默认
	SHGH = 1 //高亮显示
	SUNL = 4 //下划线
	SLL  = 5 //闪烁
	SB   = 7 //反白显示
	SNO  = 8 //不可见
)
View Source
const (
	STR_PAD_LEFT = 1 + iota
	STR_PAD_RIGHT
)

Variables

View Source
var ErrBadStringFormat = errors.New("bad string format")

ErrBadStringFormat represents a error of input string's format is illegal .

View Source
var ErrEmptyString = errors.New("empty string")

ErrEmptyString represents a error of empty input string.

Functions

func AesKeySecureRandom added in v1.1.6

func AesKeySecureRandom(keyword []byte) (key []byte)

func ApiResult

func ApiResult(status bool, msg string, i interface{}) *map[string]interface{}

API输出

func BinaryStringToBytes

func BinaryStringToBytes(s string) (bs []byte)

BinaryStringToBytes get the binary bytes according to the input string which is in binary format.

func ByteToBinaryString

func ByteToBinaryString(b byte) string

ByteToBinaryString get the string in binary format of a byte or uint8.

func ByteToFloat32

func ByteToFloat32(bytes []byte) float32

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

func BytesToBinaryString

func BytesToBinaryString(bs []byte) string

BytesToBinaryString get the string in binary format of a []byte or []int8.

func BytesToInt

func BytesToInt(b []byte) int

字节转换成整形

func BytesToInt64 added in v1.6.3

func BytesToInt64(b []byte) (int64, error)

字节转换成整形

func Contains

func Contains(obj interface{}, target interface{}) (bool, error)

func ConvertFloat

func ConvertFloat(c interface{}) float64

转换任意数据为 float64

func CreateUUID

func CreateUUID(step bool) string

创建UUID

func EncodeMD5

func EncodeMD5(s string) string

func EncodeMD5Std

func EncodeMD5Std(s string) string

func Error

func Error(msg string, err error) error

添加新的错误信息

func Exist

func Exist(filename string) bool

func ExitApp

func ExitApp(out chan os.Signal, callback func(os.Signal))

收到退出信号时处理程序关闭

func FixByesIntLen added in v1.1.5

func FixByesIntLen(b []byte) []byte

修正bytes int 数据长度

func Float32ToByte

func Float32ToByte(float float32) []byte

func Float64ToByte

func Float64ToByte(float float64) []byte

func Floor added in v1.2.2

func Floor(num float64, precision int) float64

舍小数位

func FmtColor

func FmtColor(str string, colors ...int) string

func FormatTime

func FormatTime(format_str string, unix_timestamp int64) string

func GBK2UTF8 added in v1.4.0

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

func GenerateStruct added in v1.5.9

func GenerateStruct(key string, data M, indent string)

JSON 生成 struct 结构内容

func GetBucket

func GetBucket(bucketName string, endpoint string, accessID string, accessKey string) (*oss.Bucket, error)

Get bucket

func GetDirectoryCount

func GetDirectoryCount(dir_path string) (int, error)

func GetLocationAddress

func GetLocationAddress()

func HttpGet

func HttpGet(url_str string) (string, error)

http get 请求

func HttpGetBytes

func HttpGetBytes(urlStr string) ([]byte, error)

http get 请求

func HttpPostJsonBytes

func HttpPostJsonBytes(url_str string, post_data []byte) ([]byte, error)

http post JSON 数据,返回一个 []byte 数组

func HttpPostJsonString

func HttpPostJsonString(url_str string, post_data M) (string, error)

http post JSON 数据,返回一个 string 数据

func Hump2Under

func Hump2Under(str string) string

驼峰转下划线

func Inet_aton

func Inet_aton(ipnr string) int64

Convert net.IP to int64 , http://www.outofmemory.cn

func Inet_ntoa

func Inet_ntoa(ipnr int64) string

Convert uint to net.IP http://www.outofmemory.cn

func IntToBytes

func IntToBytes(n int, bit int) []byte

整形转换成字节

func LcFirst added in v1.5.1

func LcFirst(str string) string

首字母小写

func Map2Struct

func Map2Struct(obj interface{}, stu interface{}) error

map 转结构

func MapDump added in v1.4.0

func MapDump(m M) ([]string, []interface{})

func MapKeys

func MapKeys(m map[string]interface{}) []string

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

func PKCS7Padding added in v1.2.3

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7 处理

func PKCS7UnPadding added in v1.2.3

func PKCS7UnPadding(plantText []byte) []byte

PKCS7 反解

func PathExists

func PathExists(path string) bool

func PrintAny added in v1.0.2

func PrintAny(any interface{})

func PrintMap

func PrintMap(obj map[string]interface{}, step string)

func RandRange added in v1.4.5

func RandRange(min, max int) int

生成范围数字

func RandRange64 added in v1.4.6

func RandRange64(min, max int64) int64

生成范围数字

func RandStr

func RandStr(number int, r_table interface{}) string

生成随机字符串

func ReadDir

func ReadDir(path string) (files []string, dirs []string, err error)

func ReadDirRecursion

func ReadDirRecursion(dir_path string) ([]string, error)

func Round

func Round(d float64, position int) float64

保留小数位

func SHA1 added in v1.1.6

func SHA1(data []byte) []byte

func SHAPRNGDecode added in v1.1.6

func SHAPRNGDecode(deText []byte, kenCode []byte) ([]byte, error)

func SHAPRNGDecodeString added in v1.1.6

func SHAPRNGDecodeString(decryptStr string, kenCode string) (string, error)

func SHAPRNGEncode added in v1.1.6

func SHAPRNGEncode(plantText []byte, kenCode []byte) ([]byte, error)

func SHAPRNGEncodeString added in v1.1.6

func SHAPRNGEncodeString(encryptStr string, kenCode string) (string, error)

func SetTimeout

func SetTimeout(step time.Duration, callback func())

设置时间回调

func StrPad

func StrPad(str string, pad_str string, number int, t int) string

func StringIndexOf

func StringIndexOf(arr []string, search string) int

func Struct2Map

func Struct2Map(obj interface{}, fields []string) map[string]interface{}

结构转map

func UTF82GBK added in v1.4.0

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

func UcFirst

func UcFirst(str string) string

首字母大写

func Under2Hump

func Under2Hump(str string) string

下划线转驼峰

func WritePid

func WritePid(pidName string)

生成PID文件

func YN

func YN(condition bool, yes interface{}, no interface{}) interface{}

模拟二元操作符功能

Types

type AesEncrypt

type AesEncrypt struct {
	// contains filtered or unexported fields
}

func NewAes

func NewAes(k string) *AesEncrypt

创建加密

func (*AesEncrypt) Decrypt

func (a *AesEncrypt) Decrypt(deStr []byte) ([]byte, error)

解密方法

func (*AesEncrypt) DecryptString

func (a *AesEncrypt) DecryptString(deStr string) (string, error)

解密字符串

func (*AesEncrypt) DecryptUrl added in v1.2.6

func (a *AesEncrypt) DecryptUrl(plantText []byte) ([]byte, error)

解密BASE64URL的密码

func (*AesEncrypt) Encrypt

func (a *AesEncrypt) Encrypt(plantText []byte) ([]byte, error)

加密方法

func (*AesEncrypt) EncryptString

func (a *AesEncrypt) EncryptString(plantText string) (string, error)

加密返回字符串

func (*AesEncrypt) EncryptUrl added in v1.2.6

func (a *AesEncrypt) EncryptUrl(plantText []byte) ([]byte, error)

加密返回BASE64 URL

func (*AesEncrypt) GetKey

func (a *AesEncrypt) GetKey() []byte

得到加密KEY

func (*AesEncrypt) SetBase64 added in v1.4.1

func (a *AesEncrypt) SetBase64(chk bool)

设置是否自动base64返回

func (*AesEncrypt) SetIV

func (a *AesEncrypt) SetIV(iv []byte)

设置向量IV

func (*AesEncrypt) SetKey

func (a *AesEncrypt) SetKey(k string)

设置加密KEY

func (*AesEncrypt) SetKeyBytes added in v1.3.5

func (a *AesEncrypt) SetKeyBytes(k []byte)

func (*AesEncrypt) SetPkcs added in v1.5.8

func (a *AesEncrypt) SetPkcs(flag bool)

设置是否启动pkcs

func (*AesEncrypt) SetType

func (a *AesEncrypt) SetType(t string)

设置加密类型

type DesCipher added in v1.2.3

type DesCipher struct {
	DesType string
	// contains filtered or unexported fields
}

func NewDesCipher added in v1.2.3

func NewDesCipher(key []byte) *DesCipher

func (*DesCipher) Decrypt added in v1.2.3

func (d *DesCipher) Decrypt(data []byte) ([]byte, error)

func (*DesCipher) DecryptString added in v1.2.3

func (d *DesCipher) DecryptString(data string) (string, error)

func (*DesCipher) Encrypt added in v1.2.3

func (d *DesCipher) Encrypt(data []byte) ([]byte, error)

func (*DesCipher) EncryptString added in v1.2.3

func (d *DesCipher) EncryptString(data string) (string, error)

func (*DesCipher) SetIV added in v1.2.3

func (d *DesCipher) SetIV(iv []byte)

func (*DesCipher) SetKey added in v1.2.3

func (d *DesCipher) SetKey(key []byte)

type ExecTime

type ExecTime struct {
	// contains filtered or unexported fields
}

func NewExecTime

func NewExecTime() *ExecTime

func (*ExecTime) End

func (this *ExecTime) End(print bool) time.Duration

func (*ExecTime) Start

func (this *ExecTime) Start()

type HD

type HD map[string]interface{}

func (*HD) ToJson

func (h *HD) ToJson() string

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

http 请求客户端

func NewHttpClient

func NewHttpClient() *HttpClient

创建一个新的HTTP连接客户端

func NewTLSHttpClient

func NewTLSHttpClient(tlsCfg *tls.Config) *HttpClient

创建一个安全连接的HTTP客户端

func (*HttpClient) Clear

func (h *HttpClient) Clear()

清除HTTP当前请求的数据

func (*HttpClient) Get

func (h *HttpClient) Get(url_str string) ([]byte, error)

发起一个GET请求

func (*HttpClient) GetLastResponse

func (h *HttpClient) GetLastResponse() *HttpRequestData

得到最后一次请求的返回数据

func (*HttpClient) Post

func (h *HttpClient) Post(url_str string, data M) ([]byte, error)

发起一个POST请求

func (*HttpClient) PostJson

func (h *HttpClient) PostJson(url_str string, data M) ([]byte, error)

发起一个POST JSON请求 接收utils.M

func (*HttpClient) PostJsonBytes added in v1.6.1

func (h *HttpClient) PostJsonBytes(urlStr string, data []byte) ([]byte, error)

发起一个POST JSON请求 接收JSON 字节数组

func (*HttpClient) PostJsonString

func (h *HttpClient) PostJsonString(urlStr string, data string) ([]byte, error)

发起一个POST JSON请求 接收JSON字符串

func (*HttpClient) PostXml

func (h *HttpClient) PostXml(url_str string, data string) ([]byte, error)

发起一个POST XML请求

func (*HttpClient) Request

func (h *HttpClient) Request(method string, url_str string, content io.Reader) (*HttpRequestData, error)

发起一个http request 请求

func (*HttpClient) SetCookie

func (h *HttpClient) SetCookie(cookie *http.Cookie)

设置请求带的COOKIE信息

func (*HttpClient) SetHeader

func (h *HttpClient) SetHeader(key, val string)

设置请求头信息

func (*HttpClient) SetTimeout

func (h *HttpClient) SetTimeout(sc time.Duration)

设置请求超时时间

func (*HttpClient) SetTransport added in v1.2.1

func (h *HttpClient) SetTransport(transport *http.Transport)

设置使用HTTP代理,tls证书访问等

func (*HttpClient) Upload added in v1.6.1

func (h *HttpClient) Upload(urlStr string, fileName string, fs io.Reader, fields M) ([]byte, error)

上传文件

type HttpCookies

type HttpCookies struct {
	Cookies []*http.Cookie
}

cookie集合处理

func NewHttpCookies

func NewHttpCookies(cookies ...*http.Cookie) *HttpCookies

func (*HttpCookies) GetCookieString

func (hc *HttpCookies) GetCookieString() string

type HttpRequestData

type HttpRequestData struct {
	Status     string
	StatusCode int
	Headers    http.Header
	Content    []byte
	Cookie     *HttpCookies
}

http 请求返回数据

type JsonParse

type JsonParse struct {
	ParseObject interface{}
}

func NewJsonParse added in v1.0.8

func NewJsonParse(obj interface{}) *JsonParse

func (*JsonParse) ParseJson

func (m *JsonParse) ParseJson(data []byte) error

func (*JsonParse) ParseJsonString

func (m *JsonParse) ParseJsonString(data string) error

func (*JsonParse) ToJson

func (m *JsonParse) ToJson() []byte

func (*JsonParse) ToJsonString

func (m *JsonParse) ToJsonString() string

type M

type M map[string]interface{}

func HttpPost

func HttpPost(url_str string, post_data *url.Values) (M, error)

func HttpPostJson

func HttpPostJson(url_str string, post_data M) (M, error)

http post JSON 数据,返回一个MAP数据

func (*M) ParseJson

func (m *M) ParseJson(data []byte) error

func (*M) ParseJsonString

func (m *M) ParseJsonString(data string) error

func (*M) ToJson

func (m *M) ToJson() []byte

func (*M) ToJsonString

func (m *M) ToJsonString() string

type ResData

type ResData struct {
	Status bool        `json:"status"`
	Msg    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

func (*ResData) ParseJson

func (r *ResData) ParseJson(data []byte) error

func (*ResData) ParseJsonString

func (r *ResData) ParseJsonString(str string) error

func (*ResData) ToJson

func (r *ResData) ToJson() []byte

func (*ResData) ToJsonString

func (r *ResData) ToJsonString() string

type XMLMap

type XMLMap map[string]interface{}

func (XMLMap) MarshalXML

func (m XMLMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the map to XML, with each key in the map being a tag and it's corresponding value being it's contents.

func (*XMLMap) UnmarshalXML

func (m *XMLMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a map of string to strings, creating a key in the map for each tag and setting it's value to the tags contents.

The fact this function is on the pointer of Map is important, so that if m is nil it can be initialized, which is often the case if m is nested in another xml structurel. This is also why the first thing done on the first line is initialize it.

Directories

Path Synopsis
/腾讯云短信发送
/腾讯云短信发送
Package uuid provides implementation of Universally Unique Identifier (UUID).
Package uuid provides implementation of Universally Unique Identifier (UUID).

Jump to

Keyboard shortcuts

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