tools

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CrtFile = []byte(`-----BEGIN CERTIFICATE-----
MIICKzCCAdGgAwIBAgIEZCFPpzAKBggqhkjOPQQDAjB5MQswCQYDVQQGEwJDTjER
MA8GA1UECBMIU2hhbmdoYWkxETAPBgNVBAcTCFNoYW5naGFpMREwDwYDVQQKEwhH
b1NwaWRlcjEWMBQGA1UECxMNR29TcGlkZXJQcm94eTEZMBcGA1UEAxMQR29zcGlk
ZXIgUm9vdCBDQTAgFw0yMzAzMTkxNjAwMDBaGA8zMDIzMDMxOTE2MDAwMFoweTEL
MAkGA1UEBhMCQ04xETAPBgNVBAgTCFNoYW5naGFpMREwDwYDVQQHEwhTaGFuZ2hh
aTERMA8GA1UEChMIR29TcGlkZXIxFjAUBgNVBAsTDUdvU3BpZGVyUHJveHkxGTAX
BgNVBAMTEEdvc3BpZGVyIFJvb3QgQ0EwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC
AASvquXLARToWOkMCtyujW+yu9Amq69hYuO0wsEMfDy35LRGcKDKXBYQAlzI4oK/
QG/jHTe/aq1sS4ee5tHtJsAdo0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/
BAgwBgEB/wIBATAdBgNVHQ4EFgQUFgJ50m8ArIS37WgP6lL7NqmsPMcwCgYIKoZI
zj0EAwIDSAAwRQIgWzRUfg2baj/hFyCJJIbnrwk9H4XfzVEJqXJHMb0dbD4CIQC6
JA5hlVq6PW49+/R90EZLn51NhSuRHgW9bmosKUMkZw==
-----END CERTIFICATE-----
`)
View Source
var JsonConfig = jsoniter.Config{
	EscapeHTML:    true,
	CaseSensitive: true,
}.Froze()
View Source
var KeyFile = []byte(`-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIEIygwBaoy/fcxW08s9EJMAR2sXaFVNZ2uLrJO53zegvoAoGCCqGSM49
AwEHoUQDQgAEr6rlywEU6FjpDArcro1vsrvQJquvYWLjtMLBDHw8t+S0RnCgylwW
EAJcyOKCv0Bv4x03v2qtbEuHnubR7SbAHQ==
-----END EC PRIVATE KEY-----
`)
View Source
var Rand = rand.New(rand.NewSource(time.Now().UnixMilli()))

随机函数

Functions

func AesDecode

func AesDecode(val string, key []byte) ([]byte, error)

ase解密

func AesEncode

func AesEncode(val []byte, key []byte) (string, error)

aes加密

func Any2json

func Any2json(data any, path ...string) gjson.Result

转成json

func Any2struct

func Any2struct(data any, stru any) error

转成struct

func Base64Decode

func Base64Decode(val string) ([]byte, error)

base64解密

func Base64Encode

func Base64Encode[T string | []byte](val T) string

base64 加密

func BytesToString

func BytesToString(b []byte) string

字节串转字符串

func Charset

func Charset(content []byte, content_type string) ([]byte, string, error)

网页解码,并返回 编码

func CopySlices

func CopySlices[T any](value []T) []T

func CopySlicess

func CopySlicess[T any](value [][]T) [][]T

func CopyWitchContext

func CopyWitchContext(ctx context.Context, writer io.Writer, reader io.Reader) (err error)

func Decode

func Decode[T string | []byte](txt T, code string) T

转码

func DecodeRead

func DecodeRead(txt io.Reader, code string) io.Reader

转码

func DelSliceIndex

func DelSliceIndex[T any](val []T, indexs ...int) []T

func FreePort

func FreePort() (int, error)

func GetCertData

func GetCertData(cert *x509.Certificate) []byte

func GetCertKey

func GetCertKey() (*ecdsa.PrivateKey, error)

func GetCertKeyData

func GetCertKeyData(key *ecdsa.PrivateKey) ([]byte, error)

func GetCertWithCN

func GetCertWithCN(rootCert *x509.Certificate, key *ecdsa.PrivateKey, commonName string) (*x509.Certificate, error)

func GetCertWithCert

func GetCertWithCert(rootCert *x509.Certificate, key *ecdsa.PrivateKey, preCert *x509.Certificate) (*x509.Certificate, error)

func GetContentTypeWithBytes

func GetContentTypeWithBytes(content []byte) string

func GetDefaultDir

func GetDefaultDir() (string, error)

默认目录

func GetHost

func GetHost(addrTypes ...int) net.IP

func GetHosts

func GetHosts(addrTypes ...int) []net.IP

func GetProxyCertWithCert

func GetProxyCertWithCert(preCert *x509.Certificate) (tlsCert tls.Certificate, err error)

func GetProxyCertWithName

func GetProxyCertWithName(serverName string) (tlsCert tls.Certificate, err error)

func GetRootCert

func GetRootCert(key *ecdsa.PrivateKey) (*x509.Certificate, error)

func GetServerName

func GetServerName(addr string) string

func GetTime

func GetTime(txt string, desc ...bool) string

文本解析时间

func GetTlsCert

func GetTlsCert(cert *x509.Certificate, key *ecdsa.PrivateKey) (tls.Certificate, error)

func GetTrack

func GetTrack(point0, point1 [2]float64, point_nums float64) [][2]float64

:param point0: 起点 :param point1: 终点 :param control_point: 控制点 :param point_nums: 生成曲线坐标点的数量.数量越多图越凹凸不平,越少越平滑

func Hex

func Hex(val any) string

func HmacSha1

func HmacSha1[T string | []byte](val, key T) []byte

HmacSha1 加密

func ImgDiffer

func ImgDiffer(c, c2 []byte) (float64, error)

func LoadCertData

func LoadCertData(data []byte) (*x509.Certificate, error)

func LoadCertKeyData

func LoadCertKeyData(data []byte) (*ecdsa.PrivateKey, error)

func Md5

func Md5[T string | []byte](val T) [16]byte

md5 加密

func Merge

func Merge(c1 any, c2 any)

合并两个结构体 *ci c2

func MkDir

func MkDir(path string) error

创建目录

func NaoId

func NaoId(l ...int) string

naoid 生成

func NaoIdWithStr

func NaoIdWithStr(val string, l ...int) string

naoid 生成

func ParseHost

func ParseHost(host string) (net.IP, int)

func ParseIp

func ParseIp(ip net.IP) int

func PathEscape

func PathEscape(txt string) string

路径转义

func PathExist

func PathExist(path string) bool

路径是否存在

func PathJoin

func PathJoin(elem ...string) string

拼接路径

func PathUnescape

func PathUnescape(txt string) (string, error)

路径解析

func QueryEscape

func QueryEscape(txt string) string

参数转义

func QueryUnescape

func QueryUnescape(txt string) (string, error)

参数解析

func RanFloat64

func RanFloat64(val, val2 int64) float64

func RanInt

func RanInt(val, val2 int) int

func RanInt64

func RanInt64(val, val2 int64) int64

func SetUnExportedField

func SetUnExportedField[T any](source T, fieldName string, newFieldVal any) T

func Sha1

func Sha1[T string | []byte](val T) []byte

Sha1 加密

func Signal

func Signal(preCtx context.Context, fun func())

func SplitHostPort

func SplitHostPort(address string) (string, int, error)

func StringToBytes

func StringToBytes(s string) []byte

字符串转字节串

func UrlJoin

func UrlJoin(base, href string) (string, error)

拼接url

func Uuid

func Uuid() uuid.UUID

func WrapError

func WrapError(err error, val ...any) error

func ZipDecode

func ZipDecode(ctx context.Context, r *bytes.Buffer, encoding string) (*bytes.Buffer, error)

压缩解码

Types

type BonId

type BonId struct {
	Timestamp int64
	Count     int64
	String    string
}

func BonIdFromString

func BonIdFromString(val string) (BonId, error)

func NewBonId

func NewBonId() BonId

Jump to

Keyboard shortcuts

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