utils

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGjsonNotFound  = errors.New("specified path does not exist")
	ErrGjsonWrongType = errors.New("wrong type")
)
View Source
var (
	HttpClientSkipTlsVerify *http.Client
	HttpClient              *http.Client
)
View Source
var (
	Json = jsoniter.ConfigCompatibleWithStandardLibrary

	DNSServers = []string{"1.1.1.1:53", "223.5.5.5:53"}
)

Functions

func BinaryToIPString

func BinaryToIPString(b []byte) string

func Compare

func Compare[T constraints.Ordered](x, y T) int

Compare returns

-1 if x is less than y,
 0 if x equals y,
+1 if x is greater than y.

For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

func GetIPFromHeader

func GetIPFromHeader(headerValue string) (string, error)

func GjsonGet

func GjsonGet(json []byte, path string) (gjson.Result, error)

func GjsonParseStringMap

func GjsonParseStringMap(jsonObject string) (map[string]string, error)

func IPDesensitize

func IPDesensitize(ipAddr string) string

func IPStringToBinary

func IPStringToBinary(ip string) ([]byte, error)

func IfOr

func IfOr[T any](a bool, x, y T) T

func IfOrFn

func IfOrFn[T any](a bool, x, y func() T) T

func IsFileExists

func IsFileExists(path string) bool

func Itoa

func Itoa[T constraints.Integer](i T) string

func SplitIPAddr

func SplitIPAddr(v4v6Bundle string) (string, string, string)

SplitIPAddr 传入/分割的v4v6混合地址,返回v4和v6地址与有效地址

func Uint64SubInt64

func Uint64SubInt64(a uint64, b int64) uint64

Types

type RequestWrapper

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

func NewRequestWrapper

func NewRequestWrapper(req *http.Request, writer http.ResponseWriter) (*RequestWrapper, error)

func (*RequestWrapper) Close

func (rw *RequestWrapper) Close() error

func (*RequestWrapper) Read

func (rw *RequestWrapper) Read(p []byte) (int, error)

func (*RequestWrapper) Write

func (rw *RequestWrapper) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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