@@ -35,6 +35,11 @@ func Curl(url string) (string, error) {
35
35
var GlobalDebug = (os .Getenv ("DEBUG" ) != "" )
36
36
var envs = []string {}
37
37
var msg = ""
38
+ var skips = []string {
39
+ "KUBERNETES_" ,
40
+ "K_CONFIG" ,
41
+ "K_SERVICE" ,
42
+ }
38
43
39
44
func Debug (doit bool , format string , args ... interface {}) {
40
45
// If either is 'true' then print it
@@ -47,7 +52,7 @@ func Debug(doit bool, format string, args ...interface{}) {
47
52
}
48
53
49
54
// 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 ) {
51
56
fmt .Fprintf (w , "%s:\n " , msg )
52
57
fmt .Fprintln (w , `. ___ __ ____ ____` )
53
58
fmt .Fprintln (w , `./ __)/ \( \( __)` )
@@ -62,6 +67,18 @@ func PrintMessage(w io.Writer) {
62
67
fmt .Fprintf (w , "Some Env Vars:\n " )
63
68
fmt .Fprintf (w , "--------------\n " )
64
69
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
+ }
65
82
fmt .Fprintf (w , "%s\n " , env )
66
83
}
67
84
}
@@ -70,6 +87,7 @@ func PrintMessage(w io.Writer) {
70
87
func HandleHTTP (w http.ResponseWriter , r * http.Request ) {
71
88
body := []byte {}
72
89
debug := false
90
+ showAll := (os .Getenv ("SHOW" ) != "" )
73
91
74
92
// If there's a body then read it in for later use
75
93
if r .Body != nil {
@@ -82,6 +100,11 @@ func HandleHTTP(w http.ResponseWriter, r *http.Request) {
82
100
debug = true
83
101
}
84
102
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
+
85
108
Debug (debug , "%s:\n %s %s\n Headers:\n %s\n \n Body:\n %s\n " ,
86
109
time .Now ().String (), r .Method , r .URL , r .Header , string (body ))
87
110
@@ -116,13 +139,18 @@ func HandleHTTP(w http.ResponseWriter, r *http.Request) {
116
139
if len (body ) == 0 {
117
140
w .Header ().Add ("Content-Type" , "text/plain" )
118
141
// http://patorjk.com/software/taag/#p=display&f=Graceful&t=Code%0AEngine
119
- PrintMessage (w )
142
+ PrintMessage (w , showAll )
120
143
} else {
121
144
fmt .Fprintf (w , string (body )+ "\n " )
122
145
}
123
146
}
124
147
125
148
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
+
126
154
// If env var CRASH is set then crash immediately.
127
155
// If its value is of the form HH:MM then crash at the specified time
128
156
// time. The time is based on time returned from: http://time.nist.gov:13
@@ -185,7 +213,7 @@ func main() {
185
213
186
214
fmt .Printf ("Hello from helloworld! I'm a batch job! Index: %s\n \n " ,
187
215
jobIndex )
188
- PrintMessage (os .Stdout )
216
+ PrintMessage (os .Stdout , os . Getenv ( "SHOW" ) == "" )
189
217
190
218
} else {
191
219
// Debug the http handler for all requests
0 commit comments