package main import fmt io net http strconv time func fib int int if r

 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
package main
import (
"fmt"
"io"
"net/http"
"strconv"
"time"
)
func fib(n int) int {
if n < 2 {
return 1
} else {
return fib(n-1) + fib(n-2)
}
}
func handler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-type", "text/html")
start_time := time.Now()
g, err := strconv.Atoi(req.FormValue("fib"))
if err != nil {
}
x := fib(g)
end_time := time.Since(start_time)
io.WriteString(w, fmt.Sprintf("Hello, World!<br />fib(n): %d<br />%s", x, end_time))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", handler)
http.ListenAndServe(":3000", mux)
}