Skip to content

Instantly share code, notes, and snippets.

@jujhars13
Created February 13, 2018 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jujhars13/eed249121b1e3c62663f291639298012 to your computer and use it in GitHub Desktop.
Save jujhars13/eed249121b1e3c62663f291639298012 to your computer and use it in GitHub Desktop.
Kubernetes 101 course - basic web server in Go
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