-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
214 additions
and
314 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
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
// Get arguments from environment variables | ||
name := getEnv("ARGS_NAME") | ||
age := getEnv("ARGS_AGE") | ||
|
||
// Get flags from environment variables | ||
uppercase := getEnv("FLAGS_UPPERCASE") == "true" | ||
lowercase := getEnv("FLAGS_LOWERCASE") == "true" | ||
repeat, _ := strconv.Atoi(getEnv("FLAGS_REPEAT")) | ||
|
||
// Construct base greeting | ||
greeting := fmt.Sprintf("Hello %s!", name) | ||
if age != "" { | ||
greeting += fmt.Sprintf(" You are %s years old.", age) | ||
} | ||
|
||
// Apply case transformations | ||
if uppercase { | ||
greeting = strings.ToUpper(greeting) | ||
} else if lowercase { | ||
greeting = strings.ToLower(greeting) | ||
} | ||
|
||
// Output greeting with repetition | ||
for i := 0; i < repeat; i++ { | ||
fmt.Println(greeting) | ||
} | ||
} | ||
|
||
func getEnv(key string) string { | ||
if value, exists := os.LookupEnv(key); exists { | ||
return value | ||
} | ||
return "" | ||
} |
Oops, something went wrong.