-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New slice and math utils and replaced environment utils with environm…
…ent package.
- Loading branch information
1 parent
7814629
commit 242c422
Showing
5 changed files
with
70 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package environment | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func StringVar(key, defaultValue string) string { | ||
v := os.Getenv(key) | ||
if v != "" { | ||
return v | ||
} | ||
return defaultValue | ||
} | ||
|
||
func IntVar(key string, defaultValue int) (int, error) { | ||
v := StringVar(key, fmt.Sprintf("%d", defaultValue)) | ||
pv, err := strconv.Atoi(v) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed parsing int from environment variable %s", key) | ||
} | ||
return pv, nil | ||
} | ||
|
||
func BoolVar(key string, defaultValue bool) (bool, error) { | ||
v := StringVar(key, strconv.FormatBool(defaultValue)) | ||
pv, err := strconv.ParseBool(v) | ||
if err != nil { | ||
return false, fmt.Errorf("failed parsing boolean from environment variable %s", key) | ||
} | ||
return pv, nil | ||
} | ||
|
||
func DurationVar(key string, defaultValue time.Duration) (time.Duration, error) { | ||
v := StringVar(key, defaultValue.String()) | ||
pv, err := time.ParseDuration(v) | ||
if err != nil { | ||
return time.Second * 0, fmt.Errorf("failed parsing duration from environment variable %s", key) | ||
} | ||
return pv, nil | ||
} |
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,8 @@ | ||
package utils | ||
|
||
func Min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} |
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