-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
4 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.xml | ||
config.json | ||
*.mp3 |
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,51 @@ | ||
package lib | ||
|
||
import ( | ||
"strconv" | ||
"unicode" | ||
"strings" | ||
"os/exec" | ||
"os" | ||
) | ||
|
||
func extractInt(text string) int { | ||
filteredString := "" | ||
for _, character := range text { | ||
if unicode.IsDigit(character) { | ||
filteredString += string(character) | ||
} | ||
} | ||
integer, convErr := strconv.Atoi(filteredString) | ||
if convErr != nil { | ||
Error.Println(convErr) | ||
return 1 | ||
} else { | ||
return integer | ||
} | ||
} | ||
|
||
func FileSizeLocal(filename string) int { | ||
fileInfo, fileErr := os.Stat(filename) | ||
if fileErr != nil { | ||
Error.Println(fileErr) | ||
return 1 | ||
} | ||
return int(fileInfo.Size()) | ||
} | ||
|
||
func FileSizeUrl(url string) int { | ||
cmd := exec.Command("curl", "-sIL", url) | ||
cmdOutput, cmdErr := cmd.Output() | ||
if cmdErr != nil { | ||
Error.Println(cmdErr) | ||
return 1 | ||
} else { | ||
for _, line := range strings.Split(string(cmdOutput), "\n") { | ||
if strings.Contains(line, "content-length") { | ||
return extractInt(line) | ||
} | ||
} | ||
} | ||
Error.Printf("No content-length found for %s", url) | ||
return 1 | ||
} |
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