forked from rnzsgh/hello-world-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 739 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
package main
import (
"io"
"net/http"
"os"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
f := fib()
w.WriteHeader(http.StatusOK)
io.WriteString(w, "Hello World - new!\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")
}
log.Info("Hello world called - this is the log message")
})
http.ListenAndServe(":80", nil)
}
func fib() func() int {
a, b := 0, 1
return func() int {
a, b = b, a+b
return a
}
}