tools

package
v0.0.0-...-b1b21d8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: LGPL-3.0 Imports: 52 Imported by: 1

README

功能概述

  • 爬虫小零件库

生成根证书

package main
import (
	"log"
	"gitee.com/baixudong/gospider/tools"
)
func main() {
	key, err := tools.CreateCertKey()
	if err != nil {
		log.Panic(err)
	}
	crt, err := tools.CreateRootCert(key)
	if err != nil {
		log.Panic(err)
	}
	log.Print(crt)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CrtFile []byte
View Source
var KeyFile []byte
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) (gjson.Result, error)

转成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 CompressionBrDecode

func CompressionBrDecode(ctx context.Context, r *bytes.Buffer) (*bytes.Buffer, error)

压缩解码

func CompressionDecode

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

压缩解码

func CompressionDeflateDecode

func CompressionDeflateDecode(ctx context.Context, r *bytes.Buffer) (*bytes.Buffer, error)

func CompressionGzipDecode

func CompressionGzipDecode(ctx context.Context, r *bytes.Buffer) (*bytes.Buffer, error)

func CompressionZlibDecode

func CompressionZlibDecode(ctx context.Context, r *bytes.Buffer) (*bytes.Buffer, 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.ReadCloser) (err error)

func CreateCertKey

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

生成私钥

func CreateCertWithCert

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

func CreateProxyCertWithCert

func CreateProxyCertWithCert(crt *x509.Certificate, key *ecdsa.PrivateKey, preCert *x509.Certificate) (tlsCert tls.Certificate, err error)

func CreateProxyCertWithName

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

func CreateRootCert

func CreateRootCert(key *ecdsa.PrivateKey) (*x509.Certificate, 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 GetCertKeyData

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

func GetCertWithCN

func GetCertWithCN(rootCert *x509.Certificate, key *ecdsa.PrivateKey, commonName string) (*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 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 JsonMarshal

func JsonMarshal(data any) ([]byte, error)

func JsonUnMarshal

func JsonUnMarshal(data []byte, v any) 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 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

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