Skip to content

Commit e53c5b5

Browse files
author
Doug Davis
committed
all show all opt
Signed-off-by: Doug Davis <[email protected]>
1 parent 9c82857 commit e53c5b5

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

helloworld/helloworld.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func Curl(url string) (string, error) {
3535
var GlobalDebug = (os.Getenv("DEBUG") != "")
3636
var envs = []string{}
3737
var msg = ""
38+
var skips = []string{
39+
"KUBERNETES_",
40+
"K_CONFIG",
41+
"K_SERVICE",
42+
}
3843

3944
func Debug(doit bool, format string, args ...interface{}) {
4045
// If either is 'true' then print it
@@ -47,7 +52,7 @@ func Debug(doit bool, format string, args ...interface{}) {
4752
}
4853

4954
// Just print an cool essage to the Writer that's passed in
50-
func PrintMessage(w io.Writer) {
55+
func PrintMessage(w io.Writer, showAll bool) {
5156
fmt.Fprintf(w, "%s:\n", msg)
5257
fmt.Fprintln(w, `. ___ __ ____ ____`)
5358
fmt.Fprintln(w, `./ __)/ \( \( __)`)
@@ -62,6 +67,18 @@ func PrintMessage(w io.Writer) {
6267
fmt.Fprintf(w, "Some Env Vars:\n")
6368
fmt.Fprintf(w, "--------------\n")
6469
for _, env := range envs {
70+
if !showAll {
71+
skipIt := false
72+
for _, skip := range skips {
73+
if strings.HasPrefix(env, skip) {
74+
skipIt = true
75+
break
76+
}
77+
}
78+
if skipIt {
79+
continue
80+
}
81+
}
6582
fmt.Fprintf(w, "%s\n", env)
6683
}
6784
}
@@ -70,6 +87,7 @@ func PrintMessage(w io.Writer) {
7087
func HandleHTTP(w http.ResponseWriter, r *http.Request) {
7188
body := []byte{}
7289
debug := false
90+
showAll := (os.Getenv("SHOW") != "")
7391

7492
// If there's a body then read it in for later use
7593
if r.Body != nil {
@@ -82,6 +100,11 @@ func HandleHTTP(w http.ResponseWriter, r *http.Request) {
82100
debug = true
83101
}
84102

103+
// Allow for people to enable 'showAll' on a per request basis
104+
if _, ok := r.URL.Query()["show"]; ok {
105+
showAll = true
106+
}
107+
85108
Debug(debug, "%s:\n%s %s\nHeaders:\n%s\n\nBody:\n%s\n",
86109
time.Now().String(), r.Method, r.URL, r.Header, string(body))
87110

@@ -116,13 +139,18 @@ func HandleHTTP(w http.ResponseWriter, r *http.Request) {
116139
if len(body) == 0 {
117140
w.Header().Add("Content-Type", "text/plain")
118141
// http://patorjk.com/software/taag/#p=display&f=Graceful&t=Code%0AEngine
119-
PrintMessage(w)
142+
PrintMessage(w, showAll)
120143
} else {
121144
fmt.Fprintf(w, string(body)+"\n")
122145
}
123146
}
124147

125148
func main() {
149+
// Just for fun
150+
if os.Getenv("SHOW") == "" {
151+
os.Setenv("z", "Set env var 'SHOW' to see all variables")
152+
}
153+
126154
// If env var CRASH is set then crash immediately.
127155
// If its value is of the form HH:MM then crash at the specified time
128156
// time. The time is based on time returned from: http://time.nist.gov:13
@@ -185,7 +213,7 @@ func main() {
185213

186214
fmt.Printf("Hello from helloworld! I'm a batch job! Index: %s\n\n",
187215
jobIndex)
188-
PrintMessage(os.Stdout)
216+
PrintMessage(os.Stdout, os.Getenv("SHOW") == "")
189217

190218
} else {
191219
// Debug the http handler for all requests

0 commit comments

Comments
 (0)