forked from jwilder/whoami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
56 lines (43 loc) · 1.41 KB
/
http.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"os"
"fmt"
"net/http"
"log"
"strings"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
name := os.Getenv("NAME")
desc := os.Getenv("DESC")
ctxt := os.Getenv("CONTEXT_PATH")
fmt.Fprintf(os.Stdout, "Listening on :%s\n", port)
hostname, _ := os.Hostname()
http.HandleFunc("/" + ctxt, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(os.Stdout, "I'm %s \n", hostname)
fmt.Fprintf(os.Stdout, "Name: %s \n", name)
fmt.Fprintf(os.Stdout, "Desc: %s \n", desc)
fmt.Fprintf(w, "I'm %s \n", hostname)
fmt.Fprintf(w, "Name: %s \n", name)
fmt.Fprintf(w, "Desc: %s \n", desc)
fmt.Fprintf(os.Stdout, "==Env \n")
fmt.Fprintf(w, "==Env \n")
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
fmt.Fprintf(os.Stdout, "%s = %s \n", pair[0], pair[1])
fmt.Fprintf(w, "%s = %s \n", pair[0], pair[1])
}
fmt.Fprintf(os.Stdout, "==Headers \n")
fmt.Fprintf(w, "==Headers \n")
for name, values := range r.Header {
for _, value := range values {
fmt.Fprintf(os.Stdout, "%s = %s \n", name, value)
fmt.Fprintf(w, "%s = %s \n", name, value)
}
}
})
log.Fatal(http.ListenAndServe(":" + port, nil))
}