Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ go.work.sum
.vscode/

# Generated files
data/
/data/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECT_NAME=ponghub
BINARY=bin/$(PROJECT_NAME)
SRC=cmd/$(PROJECT_NAME)/*.go

.PHONY: all build run clean
.PHONY: all build run test clean

all: build

Expand All @@ -13,5 +13,8 @@ build:
run: build
$(BINARY)

test:
go test ./...

clean:
del $(BINARY)
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,81 @@ Ensure that the environment variable is set in your GitHub repository settings u
- `{{hash_short}}` - Short hash value (6-digit hexadecimal)
- `{{hash_md5_like}}` - MD5-style long hash value (32-digit hexadecimal)

#### 🌐 Network and System Information Parameters

- `{{local_ip}}` - Gets the local IP address of the system
- `{{hostname}}` - Gets the hostname of the system
- `{{user_agent}}` - Generates a random User-Agent string for HTTP requests
- `{{http_method}}` - Generates a random HTTP method (GET, POST, PUT, DELETE, etc.)

#### 🔐 Encoding and Decoding Parameters

- `{{base64(content)}}` - Base64 encodes the provided content
- Example: `{{base64(hello world)}}` - Encodes "hello world" to Base64
- `{{url_encode(content)}}` - URL encodes the provided content
- Example: `{{url_encode(hello world)}}` - URL encodes "hello world"
- `{{json_escape(content)}}` - JSON escapes the provided content
- Example: `{{json_escape("test")}}` - Escapes quotes and special characters for JSON

#### 🔢 Mathematical Operation Parameters

- `{{add(a,b)}}` - Adds two numbers
- Example: `{{add(10,5)}}` - Returns 15
- `{{sub(a,b)}}` - Subtracts two numbers
- Example: `{{sub(10,5)}}` - Returns 5
- `{{mul(a,b)}}` - Multiplies two numbers
- Example: `{{mul(10,5)}}` - Returns 50
- `{{div(a,b)}}` - Divides two numbers
- Example: `{{div(10,5)}}` - Returns 2

#### 📝 Text Processing Parameters

- `{{upper(text)}}` - Converts text to uppercase
- Example: `{{upper(hello)}}` - Returns "HELLO"
- `{{lower(text)}}` - Converts text to lowercase
- Example: `{{lower(HELLO)}}` - Returns "hello"
- `{{reverse(text)}}` - Reverses the text
- Example: `{{reverse(hello)}}` - Returns "olleh"
- `{{substr(text,start,length)}}` - Extracts substring from text
- Example: `{{substr(hello world,0,5)}}` - Returns "hello"

#### 🎨 Color Generation Parameters

- `{{color_hex}}` - Generates a random hexadecimal color code
- Example: `#FF5733`
- `{{color_rgb}}` - Generates a random RGB color value
- Example: `rgb(255, 87, 51)`
- `{{color_hsl}}` - Generates a random HSL color value
- Example: `hsl(120, 50%, 75%)`

#### 📁 File and MIME Type Parameters

- `{{mime_type}}` - Generates a random MIME type
- Example: `application/json`, `image/png`, `text/html`
- `{{file_ext}}` - Generates a random file extension
- Example: `.jpg`, `.pdf`, `.txt`

#### 👤 Fake Data Generation Parameters

- `{{fake_email}}` - Generates a realistic fake email address
- Example: `john.smith@example.com`
- `{{fake_phone}}` - Generates a fake phone number
- Example: `+1-555-0123`
- `{{fake_name}}` - Generates a fake person name
- Example: `John Smith`
- `{{fake_domain}}` - Generates a fake domain name
- Example: `example-site.com`

#### ⏰ Time Calculation Parameters

- `{{time_add(duration)}}` - Adds duration to current time
- Example: `{{time_add(1h)}}` - Adds 1 hour to current time
- Example: `{{time_add(30m)}}` - Adds 30 minutes to current time
- Supported units: s (seconds), m (minutes), h (hours), d (days)
- `{{time_sub(duration)}}` - Subtracts duration from current time
- Example: `{{time_sub(1d)}}` - Subtracts 1 day from current time
- Example: `{{time_sub(2h30m)}}` - Subtracts 2 hours and 30 minutes

</div>
</details>

Expand Down
75 changes: 75 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,81 @@ ponghub 现已支持强大的参数化配置功能,允许在配置文件中使
- `{{hash_short}}` - 短哈希值(6位十六进制)
- `{{hash_md5_like}}` - MD5风格的长哈希值(32位十六进制)

#### 🌐 网络和系统信息参数

- `{{local_ip}}` - 获取系统本地IP地址
- `{{hostname}}` - 获取系统主机名
- `{{user_agent}}` - 生成随机的User-Agent字符串
- `{{http_method}}` - 生成随机的HTTP方法(GET、POST、PUT、DELETE等)

#### 🔐 编码和解码参数

- `{{base64(内容)}}` - 对提供的内容进行Base64编码
- 示例:`{{base64(hello world)}}` - 将"hello world"编码为Base64
- `{{url_encode(内容)}}` - 对提供的内容进行URL编码
- 示例:`{{url_encode(hello world)}}` - 对"hello world"进行URL编码
- `{{json_escape(内容)}}` - 对提供的内容进行JSON转义
- 示例:`{{json_escape("test")}}` - 转义引号和特殊字符以用于JSON

#### 🔢 数学运算参数

- `{{add(a,b)}}` - 两数相加
- 示例:`{{add(10,5)}}` - 返回15
- `{{sub(a,b)}}` - 两数相减
- 示例:`{{sub(10,5)}}` - 返回5
- `{{mul(a,b)}}` - 两数相乘
- 示例:`{{mul(10,5)}}` - 返回50
- `{{div(a,b)}}` - 两数相除
- 示例:`{{div(10,5)}}` - 返回2

#### 📝 文本处理参数

- `{{upper(文本)}}` - 将文本转换为大写
- 示例:`{{upper(hello)}}` - 返回"HELLO"
- `{{lower(文本)}}` - 将文本转换为小写
- 示例:`{{lower(HELLO)}}` - 返回"hello"
- `{{reverse(文本)}}` - 反转文本
- 示例:`{{reverse(hello)}}` - 返回"olleh"
- `{{substr(文本,起始位置,长度)}}` - 从文本中提取子字符串
- 示例:`{{substr(hello world,0,5)}}` - 返回"hello"

#### 🎨 颜色生成参数

- `{{color_hex}}` - 生成随机的十六进制颜色代码
- 示例:`#FF5733`
- `{{color_rgb}}` - 生成随机的RGB颜色值
- 示例:`rgb(255, 87, 51)`
- `{{color_hsl}}` - 生成随机的HSL颜色值
- 示例:`hsl(120, 50%, 75%)`

#### 📁 文件和MIME类型参数

- `{{mime_type}}` - 生成随机的MIME类型
- 示例:`application/json`、`image/png`、`text/html`
- `{{file_ext}}` - 生成随机的文件扩展名
- 示例:`.jpg`、`.pdf`、`.txt`

#### 👤 虚拟数据生成参数

- `{{fake_email}}` - 生成逼真的虚拟邮箱地址
- 示例:`john.smith@example.com`
- `{{fake_phone}}` - 生成虚拟电话号码
- 示例:`+1-555-0123`
- `{{fake_name}}` - 生成虚拟人名
- 示例:`张三`
- `{{fake_domain}}` - 生成虚拟域名
- 示例:`example-site.com`

#### ⏰ 时间计算参数

- `{{time_add(时长)}}` - 在当前时间基础上增加指定时长
- 示例:`{{time_add(1h)}}` - 在当前时间上增加1小时
- 示例:`{{time_add(30m)}}` - 在当前时间上增加30分钟
- 支持的单位:s(秒)、m(分钟)、h(小时)、d(天)
- `{{time_sub(时长)}}` - 在当前时间基础上减去指定时长
- 示例:`{{time_sub(1d)}}` - 在当前时间上减去1天
- 示例:`{{time_sub(2h30m)}}` - 在当前时间上减去2小时30分钟

</div>
</details>

Expand Down
4 changes: 2 additions & 2 deletions internal/checker/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/wcy-dt/ponghub/internal/common"
"github.com/wcy-dt/ponghub/internal/common/params"
"github.com/wcy-dt/ponghub/internal/types/structures/checker"
"github.com/wcy-dt/ponghub/internal/types/structures/configure"
)
Expand All @@ -33,7 +33,7 @@ func checkEndpoint(cfg *configure.Endpoint, timeout int, maxRetryTimes int, serv
isCertExpired := false

// Generate display URL for smart showing of template vs resolved URL
resolver := common.NewParameterResolver()
resolver := params.NewParameterResolver()
displayURL, highlightSegments := resolver.HighlightChanges(cfg.OriginalURL)
originalURL := cfg.OriginalURL
if originalURL == "" {
Expand Down
115 changes: 115 additions & 0 deletions internal/common/params/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package params

// Character sets for random string generation
const (
DefaultCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
HexCharset = "0123456789abcdef"
)

// TimeFormatReplacements Time format pattern replacements for strftime-like patterns to Go time format
var TimeFormatReplacements = map[string]string{
"%Y": "2006", // 4-digit year
"%y": "06", // 2-digit year
"%m": "01", // month (01-12)
"%d": "02", // day (01-31)
"%H": "15", // hour (00-23)
"%M": "04", // minute (00-59)
"%S": "05", // second (00-59)
"%B": "January", // full month name
"%b": "Jan", // abbreviated month name
"%A": "Monday", // full weekday name
"%a": "Mon", // abbreviated weekday name
"%j": "002", // day of year (001-366)
"%U": "", // week of year (placeholder)
"%W": "", // week of year (placeholder)
"%w": "", // weekday (placeholder)
"%Z": "MST", // timezone name
"%z": "-0700", // timezone offset
"%s": "", // Unix timestamp (placeholder)
}

// HTTPMethods HTTP methods for random HTTP method generation
var HTTPMethods = []string{
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
}

// SensitivePatterns Sensitive environment variable patterns for masking
var SensitivePatterns = []string{
"key",
"secret",
"token",
"password",
"pass",
"pwd",
"auth",
"credential",
"private",
"api_key",
"access",
"jwt",
"bearer",
"signature",
"hash",
"salt",
}

// UserAgents User agent strings for random user agent generation
var UserAgents = LoadUserAgents()

// MimeTypes MIME types for random MIME type generation
var MimeTypes = []string{
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
"video/mp4",
"video/x-msvideo",
"video/x-flv",
"audio/mpeg",
"audio/ogg",
"application/pdf",
"application/zip",
"application/x-rar-compressed",
"text/html",
"text/css",
"text/javascript",
"application/json",
"application/xml",
}

// FileExtensions File extensions for random file extension generation
var FileExtensions = []string{
".jpg",
".jpeg",
".png",
".gif",
".webp",
".mp4",
".avi",
".flv",
".mp3",
".ogg",
".pdf",
".zip",
".rar",
".html",
".css",
".js",
".json",
".xml",
}

// FirstNames First names for fake name generation
var FirstNames = LoadFirstNames()

// LastNames Last names for fake name generation
var LastNames = LoadLastNames()

// FakeDomains Domain names for fake domain generation
var FakeDomains = LoadFakeDomains()
Loading