Created
February 13, 2018 08:10
-
-
Save jujhars13/eed249121b1e3c62663f291639298012 to your computer and use it in GitHub Desktop.
Kubernetes 101 course - basic web server in Go
This file contains hidden or 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
package main | |
import ( | |
"net/http" | |
"strings" | |
"fmt" | |
) | |
func sayHello(w http.ResponseWriter, r *http.Request) { | |
fmt.Print("Request made to ", r.URL.Path) | |
message := r.URL.Path | |
message = strings.TrimPrefix(message, "/") | |
message = "Hello " + message | |
w.Write([]byte(message)) | |
} | |
func main() { | |
fmt.Print("Serving on port 8080") | |
http.HandleFunc("/", sayHello) | |
if err := http.ListenAndServe(":8080", nil); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment