-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (38 loc) · 784 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
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
f := fib()
w.WriteHeader(http.StatusOK)
io.WriteString(w, "Hello World\n")
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
io.WriteString(w, pair[0]+"="+pair[1]+"\n")
}
for i := 1; i <= 90; i++ {
io.WriteString(w, strconv.Itoa(f())+"\n")
}
})
port := "8080"
if len(os.Getenv("PORT")) > 0 {
port = os.Getenv("PORT")
}
fmt.Println(fmt.Sprintf("starting listener on: %s", port))
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
fmt.Println(err)
}
}
func fib() func() int {
a, b := 0, 1
return func() int {
a, b = b, a+b
return a
}
}