In one file that's in path /operations/validate
:
package operations
import (
"strings"
)
func CheckEnv(environment string) bool {
env := strings.ToLower(environment)
return env == "qa" || env == "dev" || env == "prd"
}
In the next file that calls the function:
package prompts
import (
"bufio"
"fmt"
"os"
val "thirsty/operations"
)
// AskEnv prompts for Environment
func AskEnv() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter environment (ex: dev, qa, prd): ")
environment, _ := reader.ReadString('
')
fmt.Println(environment)
env := val.CheckEnv(environment)
if !env {
fmt.Printf("Invalid Argument: No environment found for %s", environment)
return
}
os.Setenv("env", environment)
fmt.Printf("Environment set to %s", environment)
}
During the prompt, I've tried qa
or dev
but I keep getting false
as response. I am not sure why this is occurring and would appreciate any insight provided.