We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 05a50b0 commit 9fd8a3bCopy full SHA for 9fd8a3b
go-hello/app.go
@@ -0,0 +1,30 @@
1
+package main
2
+
3
+import (
4
+ "net/http"
5
+ "flag"
6
+ "fmt"
7
+)
8
9
+var lang = flag.String("lang", "en", "run app with language support - default is english")
10
11
+func main() {
12
+ var port = "8080"
13
+ http.HandleFunc("/", rootHandler)
14
+ fmt.Printf("Starting server on port %v...\n", port)
15
+ http.ListenAndServe(":"+port, nil)
16
+}
17
18
+func rootHandler(response http.ResponseWriter, request *http.Request) {
19
20
+ flag.Parse()
21
22
+ switch *lang {
23
+ case "en":
24
+ fmt.Fprintf(response, "Hello %s!. Welcome!\n", request.URL.Path[1:])
25
+ case "es":
26
+ fmt.Fprintf(response, "Hola %s!. Bienvenido!\n", request.URL.Path[1:])
27
+ default:
28
+ fmt.Fprintf(response, "Error! unknown lang option -> %s\n", *lang)
29
+ }
30
0 commit comments