MCPcopy Create free account
hub / github.com/github/gh-aw / applyFilesizeFormat

Function applyFilesizeFormat

pkg/console/render.go:643–671  ·  view source on GitHub ↗

applyFilesizeFormat formats a value as a human-readable file size (e.g., "1.2 MB").

(val reflect.Value, baseValue string)

Source from the content-addressed store, hash-verified

641
642// applyFilesizeFormat formats a value as a human-readable file size (e.g., "1.2 MB").
643func applyFilesizeFormat(val reflect.Value, baseValue string) string {
644 if val.CanInterface() {
645 switch v := val.Interface().(type) {
646 case int:
647 return FormatFileSize(int64(v))
648 case int64:
649 return FormatFileSize(v)
650 case int32:
651 return FormatFileSize(int64(v))
652 case uint:
653 // #nosec G115 - Converting uint to int64 for file size display
654 return FormatFileSize(int64(v))
655 case uint64:
656 // #nosec G115 - Converting uint64 to int64 for file size display
657 return FormatFileSize(int64(v))
658 case uint32:
659 return FormatFileSize(int64(v))
660 }
661 }
662 // Fallback for integer kinds
663 if val.Kind() >= reflect.Int && val.Kind() <= reflect.Int64 {
664 return FormatFileSize(val.Int())
665 }
666 if val.Kind() >= reflect.Uint && val.Kind() <= reflect.Uint64 {
667 // #nosec G115 - Converting uint to int64 for file size display
668 return FormatFileSize(int64(val.Uint()))
669 }
670 return baseValue
671}
672
673// FormatNumber formats large numbers in a human-readable way (e.g., "1k", "1.2k", "1.12M")
674func FormatNumber(n int) string {

Callers 1

applyTagFormatFunction · 0.85

Calls 1

FormatFileSizeFunction · 0.85

Tested by

no test coverage detected