-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 779 Bytes
/
main.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
package main
import (
"fmt"
"net"
"net/http"
"os"
"log"
)
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hell theno\n")
}
func headers(w http.ResponseWriter, req *http.Request) {
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}
}
func main() {
port := "8080"
if val, ok := os.LookupEnv("PORT"); ok {
port = val
}
http.HandleFunc("/hello", hello)
http.HandleFunc("/headers", headers)
listener, err := net.Listen("tcp", "0.0.0.0:"+port)
if err != nil {
log.Fatal(err)
}
// Log server started
log.Printf("Server started at port %v", listener.Addr().(*net.TCPAddr).Port)
panic(http.Serve(listener, nil))
}