@@ -56,14 +56,15 @@ func init() {
5656
5757// Data whoami information.
5858type 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"`
6768}
6869
6970func main () {
@@ -207,7 +208,9 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
207208}
208209
209210func 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" )
211214 if len (wait ) > 0 {
212215 duration , err := time .ParseDuration (wait )
213216 if err == nil {
@@ -231,11 +234,28 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
231234 http .Error (w , err .Error (), http .StatusInternalServerError )
232235 return
233236 }
237+
238+ if ok , _ := strconv .ParseBool (queryParams .Get ("env" )); ok {
239+ for _ , env := range os .Environ () {
240+ _ , _ = fmt .Fprintln (w , env )
241+ }
242+ }
234243}
235244
236245func apiHandler (w http.ResponseWriter , r * http.Request ) {
246+ queryParams := r .URL .Query ()
247+
237248 hostname , _ := os .Hostname ()
238249
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+
239259 data := Data {
240260 Hostname : hostname ,
241261 IP : getIPs (),
@@ -245,6 +265,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
245265 Method : r .Method ,
246266 Name : name ,
247267 RemoteAddr : r .RemoteAddr ,
268+ Environ : environ ,
248269 }
249270
250271 w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments