-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from christopherwoodall/1-env-auth-over-ride
Set/Get environmental variables in `main.go`
- Loading branch information
Showing
4 changed files
with
54 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,50 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Angelina Tsuboi [email protected] | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ANG13T/SatIntel/cli" | ||
) | ||
|
||
func setEnvironmentalVariable(envKey string) string { | ||
reader := bufio.NewReader(os.Stdin) | ||
fmt.Printf("%s: ", envKey) | ||
input, err := reader.ReadString('\n') | ||
|
||
if err != nil { | ||
fmt.Println("Error reading input:", err) | ||
os.Exit(1) | ||
} | ||
input = strings.TrimSuffix(input, "\n") | ||
|
||
if err := os.Setenv(envKey, input); err != nil { | ||
fmt.Printf("Error setting environment variable %s: %v\n", envKey, err) | ||
os.Exit(1) | ||
} | ||
|
||
return input | ||
} | ||
|
||
|
||
func checkEnvironmentalVariable(envKey string) { | ||
_, found := os.LookupEnv(envKey) | ||
if !found { | ||
setEnvironmentalVariable(envKey) | ||
} | ||
} | ||
|
||
|
||
func main() { | ||
os.Setenv("SPACE_TRACK_USERNAME", "username") | ||
os.Setenv("SPACE_TRACK_PASSWORD", "password") | ||
os.Setenv("N2YO_API_KEY", "api-key") | ||
checkEnvironmentalVariable("SPACE_TRACK_USERNAME") | ||
checkEnvironmentalVariable("SPACE_TRACK_PASSWORD") | ||
checkEnvironmentalVariable("N2YO_API_KEY") | ||
|
||
cli.SatIntel() | ||
} |
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