-
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.
Refactor environment variables (#21)
* Refactor env var, create a package * Reorder functions
- Loading branch information
Showing
5 changed files
with
70 additions
and
90 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,65 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
// Environment variables, used to override defaults | ||
const ( | ||
// Channel/Revision of the service snap (has default) | ||
envSnapChannel = "SNAP_CHANNEL" | ||
|
||
// Path to snap instead, used for testing a local snap instead of | ||
// downloading from the store | ||
envSnapPath = "SNAP_PATH" | ||
|
||
// Toggle the teardown operations during tests (has default) | ||
envTeardown = "TEARDOWN" | ||
) | ||
|
||
var ( | ||
// Defaults | ||
snapChannel = "latest/edge" | ||
snapPath = "" | ||
teardown = true | ||
) | ||
|
||
// SnapChannel returns the set snap channel | ||
func SnapChannel() string { | ||
return snapChannel | ||
} | ||
|
||
// SnapPath returns the set path to a local snap | ||
func SnapPath() string { | ||
return snapPath | ||
} | ||
|
||
// SkipTeardownRemoval return | ||
func Teardown() (skip bool) { | ||
return teardown | ||
} | ||
|
||
func init() { | ||
loadEnvVars() | ||
} | ||
|
||
// Read environment variables and perform type conversion/casting | ||
func loadEnvVars() { | ||
|
||
if v := os.Getenv(envSnapChannel); v != "" { | ||
snapChannel = v | ||
} | ||
|
||
if v := os.Getenv(envSnapPath); v != "" { | ||
snapPath = v | ||
} | ||
|
||
if v := os.Getenv(envTeardown); v != "" { | ||
var err error | ||
teardown, err = strconv.ParseBool(v) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
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
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