-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// IsStringInSlice check if a string is in a given slice | ||
func IsStringInSlice(s string, sl []string) bool { | ||
for i := range sl { | ||
if sl[i] == s { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func CalculateDirSizeInMb(path string) (float64, error) { | ||
var size int64 | ||
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() { | ||
size += info.Size() | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
const bytesInMegabyte = 1000 * 1000 | ||
return float64(size) / bytesInMegabyte, nil // Return size in Megabyte | ||
} |