From 45b12df11a0b046f4c05407ea886728fd6904783 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Tue, 13 Sep 2016 16:28:22 -0400 Subject: [PATCH] Made hello-openshift read the message from an environment variable This is a minor enhancement to the hello-openshift image to optionally read the response string from the RESPONSE environment variable. --- examples/hello-openshift/README.md | 6 ++++++ examples/hello-openshift/hello_openshift.go | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/hello-openshift/README.md b/examples/hello-openshift/README.md index c91318e44866..e1daa2214f29 100644 --- a/examples/hello-openshift/README.md +++ b/examples/hello-openshift/README.md @@ -11,6 +11,12 @@ This example will serve an HTTP response of "Hello OpenShift!". $ curl 10.1.0.2:8080 Hello OpenShift! +The response message can be set by using the RESPONSE environment variable: + $ oc set env pod/hello-openshift RESPONSE="Hello World!" + + $ curl 10.1.0.2:8080 + Hello World! + To test from external network, you need to create router. Please refer to [Running the router](https://github.com/openshift/origin/blob/master/docs/routing.md) If you need to rebuild the image: diff --git a/examples/hello-openshift/hello_openshift.go b/examples/hello-openshift/hello_openshift.go index d0e387f2d33d..911ac655b333 100644 --- a/examples/hello-openshift/hello_openshift.go +++ b/examples/hello-openshift/hello_openshift.go @@ -7,7 +7,12 @@ import ( ) func helloHandler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello OpenShift!") + response := os.Getenv("RESPONSE") + if len(response) == 0 { + response = "Hello OpenShift!" + } + + fmt.Fprintln(w, response) fmt.Println("Servicing request.") }