Richard Allred
2019-08-03 99e73490b45f1f76040216418afeec9ff9770e57
commit | author | age
9fd8a3 1 package main
RA 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 }