From 9fd8a3b97a6e571038995c6a344f5a862a9311a7 Mon Sep 17 00:00:00 2001
From: Richard Allred <richardmallred@gmail.com>
Date: Thu, 27 Jun 2019 05:30:40 +0200
Subject: [PATCH] adding go-hello for ch5 lab

---
 go-hello/app.go |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/go-hello/app.go b/go-hello/app.go
new file mode 100644
index 0000000..199a595
--- /dev/null
+++ b/go-hello/app.go
@@ -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)
+  }
+}

--
Gitblit v1.9.3