diff --git a/internal/config/config.go b/internal/config/config.go index 0036e0e..5262a01 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,6 +27,12 @@ import ( "gopkg.in/yaml.v3" ) +// 默认配置常量。 +const ( + // DefaultPprofPath pprof 端点的默认路径。 + DefaultPprofPath = "/debug/pprof" +) + // Config 根配置结构,支持单服务器和多虚拟主机两种模式。 // // 包含服务器配置、日志配置、性能配置和监控配置等模块。 diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 408c6be..9bddffb 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -168,7 +168,7 @@ func DefaultConfig() *Config { }, Pprof: PprofConfig{ Enabled: false, - Path: "/debug/pprof", + Path: DefaultPprofPath, Allow: []string{"127.0.0.1"}, }, }, diff --git a/internal/config/validate.go b/internal/config/validate.go index 406a133..30253d5 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -868,64 +868,3 @@ func validateVariables(v *VariablesConfig) error { } return nil } - -// parseSize 解析大小字符串为字节数。 -// -// 支持单位:b, kb, mb, gb(不区分大小写)。 -// 纯数字默认为字节。 -// -// 参数: -// - s: 大小字符串,如 "16KB", "1MB", "1024" -// -// 返回值: -// - int64: 字节数 -// - error: 解析失败时返回错误 -func parseSize(s string) (int64, error) { - s = strings.TrimSpace(s) - if s == "" { - return 0, errors.New("大小字符串不能为空") - } - - // 提取数字部分和单位 - var numStr string - var unit string - for i := len(s) - 1; i >= 0; i-- { - c := s[i] - if c >= '0' && c <= '9' || c == '.' { - numStr = s[:i+1] - unit = strings.ToLower(s[i+1:]) - break - } - } - - if numStr == "" { - return 0, fmt.Errorf("无效的大小格式: %s", s) - } - - // 解析数字 - var value float64 - _, err := fmt.Sscanf(numStr, "%f", &value) - if err != nil { - return 0, fmt.Errorf("无法解析数字: %s", numStr) - } - - // 转换单位 - var multiplier int64 - switch unit { - case "", "b": - multiplier = 1 - case "k", "kb": - multiplier = 1024 - case "m", "mb": - multiplier = 1024 * 1024 - case "g", "gb": - multiplier = 1024 * 1024 * 1024 - default: - return 0, fmt.Errorf("未知单位: %s", unit) - } - - return int64(value * float64(multiplier)), nil -} - -// unused: kept for potential future use in size parsing -var _ = parseSize diff --git a/internal/server/pprof.go b/internal/server/pprof.go index a76b74e..34b083f 100644 --- a/internal/server/pprof.go +++ b/internal/server/pprof.go @@ -62,7 +62,7 @@ func NewPprofHandler(cfg *config.PprofConfig) (*PprofHandler, error) { path := cfg.Path if path == "" { - path = "/debug/pprof" + path = config.DefaultPprofPath } h := &PprofHandler{path: path}