forked from RedHatTraining/DO288-apps
-
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
1 parent
05a50b0
commit 9fd8a3b
Showing
1 changed file
with
30 additions
and
0 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,30 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
var lang = flag.String("lang", "en", "run app with language support - default is english") | ||
|
||
func main() { | ||
var port = "8080" | ||
http.HandleFunc("/", rootHandler) | ||
fmt.Printf("Starting server on port %v...\n", port) | ||
http.ListenAndServe(":"+port, nil) | ||
} | ||
|
||
func rootHandler(response http.ResponseWriter, request *http.Request) { | ||
|
||
flag.Parse() | ||
|
||
switch *lang { | ||
case "en": | ||
fmt.Fprintf(response, "Hello %s!. Welcome!\n", request.URL.Path[1:]) | ||
case "es": | ||
fmt.Fprintf(response, "Hola %s!. Bienvenido!\n", request.URL.Path[1:]) | ||
default: | ||
fmt.Fprintf(response, "Error! unknown lang option -> %s\n", *lang) | ||
} | ||
} |