@@ -56,14 +56,15 @@ func init() {
56
56
57
57
// Data whoami information.
58
58
type Data struct {
59
- Hostname string `json:"hostname,omitempty"`
60
- IP []string `json:"ip,omitempty"`
61
- Headers http.Header `json:"headers,omitempty"`
62
- URL string `json:"url,omitempty"`
63
- Host string `json:"host,omitempty"`
64
- Method string `json:"method,omitempty"`
65
- Name string `json:"name,omitempty"`
66
- RemoteAddr string `json:"remoteAddr,omitempty"`
59
+ Hostname string `json:"hostname,omitempty"`
60
+ IP []string `json:"ip,omitempty"`
61
+ Headers http.Header `json:"headers,omitempty"`
62
+ URL string `json:"url,omitempty"`
63
+ Host string `json:"host,omitempty"`
64
+ Method string `json:"method,omitempty"`
65
+ Name string `json:"name,omitempty"`
66
+ RemoteAddr string `json:"remoteAddr,omitempty"`
67
+ Environ map [string ]string `json:"environ,omitempty"`
67
68
}
68
69
69
70
func main () {
@@ -207,7 +208,9 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
207
208
}
208
209
209
210
func whoamiHandler (w http.ResponseWriter , r * http.Request ) {
210
- wait := r .URL .Query ().Get ("wait" )
211
+ queryParams := r .URL .Query ()
212
+
213
+ wait := queryParams .Get ("wait" )
211
214
if len (wait ) > 0 {
212
215
duration , err := time .ParseDuration (wait )
213
216
if err == nil {
@@ -231,11 +234,28 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
231
234
http .Error (w , err .Error (), http .StatusInternalServerError )
232
235
return
233
236
}
237
+
238
+ if ok , _ := strconv .ParseBool (queryParams .Get ("env" )); ok {
239
+ for _ , env := range os .Environ () {
240
+ _ , _ = fmt .Fprintln (w , env )
241
+ }
242
+ }
234
243
}
235
244
236
245
func apiHandler (w http.ResponseWriter , r * http.Request ) {
246
+ queryParams := r .URL .Query ()
247
+
237
248
hostname , _ := os .Hostname ()
238
249
250
+ environ := make (map [string ]string )
251
+
252
+ if ok , _ := strconv .ParseBool (queryParams .Get ("env" )); ok {
253
+ for _ , env := range os .Environ () {
254
+ before , after , _ := strings .Cut (env , "=" )
255
+ environ [before ] = after
256
+ }
257
+ }
258
+
239
259
data := Data {
240
260
Hostname : hostname ,
241
261
IP : getIPs (),
@@ -245,6 +265,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
245
265
Method : r .Method ,
246
266
Name : name ,
247
267
RemoteAddr : r .RemoteAddr ,
268
+ Environ : environ ,
248
269
}
249
270
250
271
w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments