Display size of file served when verbose flag is passed
This commit is contained in:
parent
1fe42cb217
commit
3801421567
18
cmd/files.go
18
cmd/files.go
|
@ -79,6 +79,24 @@ func (p *Path) Decrement() {
|
|||
p.Number = p.Number - 1
|
||||
}
|
||||
|
||||
func humanReadableSize(bytes int) string {
|
||||
const unit = 1000
|
||||
|
||||
if bytes < unit {
|
||||
return fmt.Sprintf("%d B", bytes)
|
||||
}
|
||||
|
||||
div, exp := int64(unit), 0
|
||||
|
||||
for n := bytes / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f %cB",
|
||||
float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
func preparePath(path string) string {
|
||||
if runtime.GOOS == "windows" {
|
||||
path = fmt.Sprintf("/%v", filepath.ToSlash(path))
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.18.3"
|
||||
var Version = "0.18.4"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
|
@ -218,9 +218,10 @@ func serveStaticFile(w http.ResponseWriter, r *http.Request, paths []string) err
|
|||
w.Write(buf)
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%v | Served \"%v\" to %v in %v\n",
|
||||
fmt.Printf("%v | Served %v (%v) to %v in %v\n",
|
||||
startTime.Format(LOGDATE),
|
||||
filePath,
|
||||
humanReadableSize(len(buf)),
|
||||
r.RemoteAddr,
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue