-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathenv.go
More file actions
36 lines (31 loc) · 775 Bytes
/
env.go
File metadata and controls
36 lines (31 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"log"
"net/http"
"os"
"strings"
)
func handler(w http.ResponseWriter, req *http.Request) {
fmt.Printf("%+v\n", req)
fmt.Fprintln(w, strings.Join(os.Environ(), "\n"))
}
func crashHandler(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Crashing...")
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
os.Exit(1)
}
// headerHandler prints out the active headers in the request
func headersHandler(w http.ResponseWriter, req *http.Request) {
req.Header.Write(w)
}
func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/crash", crashHandler)
http.HandleFunc("/headers", headersHandler)
addr := ":" + os.Getenv("PORT")
fmt.Printf("Listening on %v\n", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}