common

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

  • Package common @Author: zhizhuo @IDE:GoLand @File: common.go @Date: 2025/2/20 下午3:37*
  • Package common @Author: zhizhuo @IDE:GoLand @File: yaml.go @Date: 2025/4/2 下午2:02*

Index

Constants

View Source
const (
	HttpType = "http"
	TcpType  = "tcp"
	UdpType  = "udp"
)

Variables

This section is empty.

Functions

func Base64Encode

func Base64Encode(braw []byte) []byte

Base64Encode base64 encode

func DealMultipart

func DealMultipart(contentType string, ruleBody string) (result string, err error)

DealMultipart 把规则中以 \n 分行的 multipart 正文转换为 RFC 7578 要求的 \r\n 格式。 每个分段以第一个空行分隔头部与内容,内容中的空行原样保留。

func FromHex

func FromHex(data string) string

FromHex 将十六进制字符串转换为普通字符串

func GetRandomIP

func GetRandomIP() string

GetRandomIP 获取随机ip地址

func IsYamlFile

func IsYamlFile(filename string) bool

IsYamlFile 判断文件是否为YAML格式

func Mmh3Hash32

func Mmh3Hash32(raw []byte) int32

Mmh3Hash32 计算 mmh3 hash

func ParseTarget

func ParseTarget(target, path string) string

ParseTarget 处理请求url地址

目标的路径是规则路径的前缀(http://a/app/ 加 /admin 得到 http://a/app/admin)。 目标的查询串只属于目标页面本身:规则路径为空或 "/" 时保留,其余路径不携带; 片段不会发往服务端,始终丢弃。

func ParseUrl

func ParseUrl(u *url.URL) *proto.UrlType

func RandFromChoices

func RandFromChoices(n int, choices string) string

RandFromChoices 从 choices 中随机取 n 个字节组成字符串;n<=0 或 choices 为空时返回空串。

使用 math/rand/v2 的全局生成器:并发安全、无需每次创建随机源。按纳秒时间 重新播种的旧实现在同一纳秒内的并发调用会得到相同结果,且每次分配约 5 KiB。

func RandLetters

func RandLetters(n int) string

RandLetters 随机小写字母

func RandomString

func RandomString(n int) string

RandomString 生成由大小写字母与数字组成的随机字符串。

func RandomUA

func RandomUA() string

RandomUA 返回一个高度真实的随机 User-Agent 保证平台-浏览器-版本号的搭配逻辑正确(如 Safari 只出现在 Apple 平台)

func RemoveTrailingSlash

func RemoveTrailingSlash(url string) string

RemoveTrailingSlash 删除URL中的最后一个/

func ReverseString

func ReverseString(s string) string

func Str2UTF8

func Str2UTF8(str string) string

Str2UTF8 字符串转 utf 8

func Url2UrlType

func Url2UrlType(u *url.URL) *proto.UrlType

func UrlTypeToString

func UrlTypeToString(u *proto.UrlType) string

func ValidUTF8Truncated added in v1.3.0

func ValidUTF8Truncated(data []byte) bool

ValidUTF8Truncated 与 utf8.Valid 的区别在于:容忍末尾一个被截断的不完整多字节序列。

响应正文受读取上限约束,截断位置可能恰好落在多字节字符中间。这种正文仍然是 UTF-8, 不能因为最后半个字符就判为非 UTF-8、再把整页按 GB18030 重新解码(会让中文内容整体错位)。 只放宽末尾最多 utf8.UTFMax-1 个字节,其余部分必须是合法 UTF-8。

func ValidUTF8TruncatedString added in v1.3.0

func ValidUTF8TruncatedString(s string) bool

ValidUTF8TruncatedString 是 ValidUTF8Truncated 的字符串版本。

Types

This section is empty.

Jump to

Keyboard shortcuts

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