Initial commit

This commit is contained in:
XOF
2025-11-20 12:12:26 +08:00
commit 179a58b55a
169 changed files with 64463 additions and 0 deletions

34
internal/utils/parser.go Normal file
View File

@@ -0,0 +1,34 @@
// Filename: internal/utils/parser.go
package utils
import (
"encoding/json"
"regexp"
"strings"
)
// ParseKeysFromText 是一个共享的工具函数,用于从各种格式的文本中解析出密钥列表。
// 因为它是共享的,所以函数名首字母大写以导出。
func ParseKeysFromText(text string) []string {
var keys []string
if json.Unmarshal([]byte(text), &keys) == nil && len(keys) > 0 {
var cleanedKeys []string
for _, key := range keys {
trimmed := strings.TrimSpace(key)
if trimmed != "" {
cleanedKeys = append(cleanedKeys, trimmed)
}
}
return cleanedKeys
}
keys = []string{}
delimiters := regexp.MustCompile(`[\s,;|\n\r\t]+`)
splitKeys := delimiters.Split(strings.TrimSpace(text), -1)
for _, key := range splitKeys {
trimmed := strings.TrimSpace(key)
if trimmed != "" {
keys = append(keys, trimmed)
}
}
return keys
}

View File

@@ -0,0 +1,20 @@
// Filename: internal/utils/validators.go
package utils
import "regexp"
const MaxGroupNameLength = 32
// groupNameRegex validates that a group name consists only of lowercase letters, numbers, and hyphens.
var groupNameRegex = regexp.MustCompile(`^[a-z0-9-]+$`)
// IsValidGroupName checks if the provided string is a valid group name.
func IsValidGroupName(name string) bool {
if name == "" {
return false
}
if len(name) > MaxGroupNameLength {
return false
}
return groupNameRegex.MatchString(name)
}