Refactor files
This commit is contained in:
parent
0bc687a538
commit
f2f1a08687
6 changed files with 564 additions and 532 deletions
34
db.go
34
db.go
|
|
@ -1,34 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Get the size of the database and return as nearest human readable size
|
||||
func GetDBSize() string {
|
||||
fileInfo, err := os.Stat("feedvault.db")
|
||||
if err != nil {
|
||||
log.Println("Error getting file info:", err)
|
||||
return "0 B"
|
||||
}
|
||||
|
||||
// Get the file size in bytes
|
||||
fileSize := fileInfo.Size()
|
||||
|
||||
// Convert to human readable size and append the unit (KB, MB, GB)
|
||||
var size float64
|
||||
if fileSize < 1024*1024 {
|
||||
size = float64(fileSize) / 1024
|
||||
return fmt.Sprintf("%.2f KB", size)
|
||||
}
|
||||
|
||||
if fileSize < 1024*1024*1024 {
|
||||
size = float64(fileSize) / (1024 * 1024)
|
||||
return fmt.Sprintf("%.2f MB", size)
|
||||
}
|
||||
|
||||
size = float64(fileSize) / (1024 * 1024 * 1024)
|
||||
return fmt.Sprintf("%.2f GB", size)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue