aboutsummaryrefslogtreecommitdiff
path: root/weed/util/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/util/parse.go')
-rw-r--r--weed/util/parse.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/weed/util/parse.go b/weed/util/parse.go
new file mode 100644
index 000000000..0a8317c19
--- /dev/null
+++ b/weed/util/parse.go
@@ -0,0 +1,26 @@
+package util
+
+import (
+ "strconv"
+)
+
+func ParseInt(text string, defaultValue int) int {
+ count, parseError := strconv.ParseInt(text, 10, 64)
+ if parseError != nil {
+ if len(text) > 0 {
+ return 0
+ }
+ return defaultValue
+ }
+ return int(count)
+}
+func ParseUint64(text string, defaultValue uint64) uint64 {
+ count, parseError := strconv.ParseUint(text, 10, 64)
+ if parseError != nil {
+ if len(text) > 0 {
+ return 0
+ }
+ return defaultValue
+ }
+ return count
+}