utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client = &http.Client{
	Transport: &http.Transport{
		ForceAttemptHTTP2:   true,
		MaxConnsPerHost:     0,
		MaxIdleConns:        0,
		MaxIdleConnsPerHost: 999,
	},
}

Functions

func B2S

func B2S(b []byte) string

B2S converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ . from github.com/savsgio/gotils/strconv

func ChunkString

func ChunkString(s string, chunkSize int) []string

func ComputeMd5AndLength

func ComputeMd5AndLength(r io.Reader) ([]byte, int64)

func ConvertSubVersionToInt

func ConvertSubVersionToInt(str string) int32

func HTTPGetReadCloser

func HTTPGetReadCloser(url string, cookie string) (io.ReadCloser, error)

HTTPGetReadCloser 从 Http url 获取 io.ReadCloser

func HttpGetBytes

func HttpGetBytes(url, cookie string) ([]byte, error)

HttpGetBytes 带 cookie 的 GET 请求

func HttpPostBytes

func HttpPostBytes(url string, data []byte) ([]byte, error)

func HttpPostBytesWithCookie

func HttpPostBytesWithCookie(url string, data []byte, cookie string, contentType ...string) ([]byte, error)

func MultiReadSeeker

func MultiReadSeeker(r ...io.ReadSeeker) io.ReadSeeker

func NewGzipReadCloser

func NewGzipReadCloser(reader io.ReadCloser) (io.ReadCloser, error)

NewGzipReadCloser 从 io.ReadCloser 创建 gunzip io.ReadCloser

func RandomString

func RandomString(len int) string

func RandomStringRange

func RandomStringRange(length int, str string) string

func S2B

func S2B(s string) (b []byte)

S2B converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

func Select

func Select(a, b []byte) []byte

Select 如果A为nil 将会返回 B 否则返回A 对应 ?? 语法

func ToGroupCode

func ToGroupCode(groupUin int64) int64

func ToGroupUin

func ToGroupUin(groupCode int64) int64

func XmlEscape

func XmlEscape(s string) string

XmlEscape xml escape string

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache - simple implementation of cache More information: https://en.wikipedia.org/wiki/Time_to_live

func NewCache

func NewCache[T any](interval time.Duration) *Cache[T]

NewCache - initialization of new cache. For avoid mistake - minimal time to live is 1 minute. For simplification, - key is string and cache haven`t stop method

func (*Cache[T]) Add

func (cache *Cache[T]) Add(key string, value T, ttl time.Duration)

Add - add key/value in cache

func (*Cache[_]) Count

func (cache *Cache[_]) Count() int

Count - return amount element of TTL map.

func (*Cache[T]) Get

func (cache *Cache[T]) Get(key string) (value T, _ bool)

Get - return value from cache

func (*Cache[T]) GetAndUpdate

func (cache *Cache[T]) GetAndUpdate(key string, ttl time.Duration) (_ T, _ bool)

func (*Cache[_]) GetKeys

func (cache *Cache[_]) GetKeys() []string

GetKeys - return all keys of cache map

type ICMPPingResult

type ICMPPingResult struct {
	PacketsSent int
	PacketsLoss int
	AvgTimeMill int64
}

func RunTCPPingLoop

func RunTCPPingLoop(ipport string, count int) (r ICMPPingResult)

RunTCPPingLoop 使用 tcp 进行 ping

type UploadWaiter

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

UploadWaiter 用于控制并发上传,当有一个文件多次上传时, 等待第一个上传,后续的上传并发进行(可以秒传).

func NewUploadWaiter

func NewUploadWaiter() *UploadWaiter

NewUploadWaiter return a new UploadWaiter.

func (*UploadWaiter) Done

func (s *UploadWaiter) Done(key string)

Done 当前上传任务已完成。

func (*UploadWaiter) Wait

func (s *UploadWaiter) Wait(key string)

Wait 如果不是第一个上传则等待。

Jump to

Keyboard shortcuts

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