MCPcopy
hub / github.com/PatchMon/PatchMon / getEnvBytes

Function getEnvBytes

server-source-code/internal/config/config.go:353–377  ·  view source on GitHub ↗

getEnvBytes parses size strings like "5mb", "2mb", "1gb" into bytes. defaultMB is used when env is empty or parse fails.

(key string, defaultMB int)

Source from the content-addressed store, hash-verified

351// getEnvBytes parses size strings like "5mb", "2mb", "1gb" into bytes.
352// defaultMB is used when env is empty or parse fails.
353func getEnvBytes(key string, defaultMB int) int64 {
354 s := strings.TrimSpace(strings.ToLower(os.Getenv(key)))
355 if s == "" {
356 return int64(defaultMB) * 1024 * 1024
357 }
358 var mult int64 = 1024 * 1024
359 if strings.HasSuffix(s, "kb") {
360 mult = 1024
361 s = strings.TrimSuffix(s, "kb")
362 } else if strings.HasSuffix(s, "mb") {
363 s = strings.TrimSuffix(s, "mb")
364 } else if strings.HasSuffix(s, "gb") {
365 mult = 1024 * 1024 * 1024
366 s = strings.TrimSuffix(s, "gb")
367 } else if strings.HasSuffix(s, "b") {
368 mult = 1
369 s = strings.TrimSuffix(s, "b")
370 }
371 s = strings.TrimSpace(s)
372 v, err := strconv.ParseInt(s, 10, 64)
373 if err != nil || v < 1 {
374 return int64(defaultMB) * 1024 * 1024
375 }
376 return v * mult
377}

Callers 1

LoadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected