c9b72206a5
* Checkpoint: it builds The config, db, model, network, os, and public packages have had some fixes to glaringly obvious flaws, dead code removed, and stylistic changes. * Style changes and old code removal in router Router needs a lot of work done to its (lack of) error handling. * Dead code removal and style changes Now up to util/email/email.go. After I'm finished with the initial sweep I'll go back and fix error handling and security issues. Then I'll fix the broken API. Then I'll go through to add documentation and fix code visibility. * Finish dead code removal and style changes Vendored libraries not touched. Everything still needs security fixes and documentation. There's also one case of broken functionality. * Fix accidental find-and-replace * Style, error checking, saftey, bug fix changes * Redo error checking erased during merge * Re-add merge-erased fix. Make Safe safe.
34 lignes
730 o
Go
34 lignes
730 o
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func FormatFilesize(bytes int64) string {
|
|
var unit string
|
|
var value float64
|
|
if bytes >= 1024*1024*1024*1024 {
|
|
unit = "TiB"
|
|
value = float64(bytes) / (1024 * 1024 * 1024 * 1024)
|
|
} else if bytes >= 1024*1024*1024 {
|
|
unit = "GiB"
|
|
value = float64(bytes) / (1024 * 1024 * 1024)
|
|
} else if bytes >= 1024*1024 {
|
|
unit = "MiB"
|
|
value = float64(bytes) / (1024 * 1024)
|
|
} else if bytes >= 1024 {
|
|
unit = "KiB"
|
|
value = float64(bytes) / (1024)
|
|
} else {
|
|
unit = "B"
|
|
value = float64(bytes)
|
|
}
|
|
return fmt.Sprintf("%.1f %s", value, unit)
|
|
}
|
|
|
|
func FormatFilesize2(bytes int64) string {
|
|
if bytes == 0 { // this is what gorm returns for NULL
|
|
return "Unknown"
|
|
}
|
|
return FormatFilesize(bytes)
|
|
}
|