Skip to content

Instantly share code, notes, and snippets.

@0xAhmed
Created September 25, 2017 14:19
Show Gist options
  • Select an option

  • Save 0xAhmed/b49cae312e75f047dd512d5efc11ce14 to your computer and use it in GitHub Desktop.

Select an option

Save 0xAhmed/b49cae312e75f047dd512d5efc11ce14 to your computer and use it in GitHub Desktop.
Example Go app for hosting on k8s: Originally hosted at https://github.com/DockbitExamples/kubernetes/blob/master/app/app.go
package main
import (
"fmt"
"net/http"
)
const version string = "1.0"
func getFrontpage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Congratulations! Version %s of your application is running on Kubernetes.", version)
}
func health(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func getVersion(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s\n", version)
}
func main() {
http.HandleFunc("/", getFrontpage)
http.HandleFunc("/health", health)
http.HandleFunc("/version", getVersion)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment