github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/main/chapter/ch9_01_tools/http/fb_server.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "net/http" 7 _ "net/http/pprof" 8 ) 9 10 func GetFibonacciSerie(n int) []int { 11 ret := make([]int, 2, n) 12 ret[0] = 1 13 ret[1] = 1 14 for i := 2; i < n; i++ { 15 ret = append(ret, ret[i-2]+ret[i-1]) 16 } 17 return ret 18 } 19 20 func index(w http.ResponseWriter, r *http.Request) { 21 w.Write([]byte("Welcome!")) 22 } 23 24 func createFBS(w http.ResponseWriter, r *http.Request) { 25 var fbs []int 26 for i := 0; i < 1000000; i++ { 27 fbs = GetFibonacciSerie(50) 28 } 29 w.Write([]byte(fmt.Sprintf("%v", fbs))) 30 31 } 32 33 func main() { 34 http.HandleFunc("/", index) 35 http.HandleFunc("/fb", createFBS) 36 log.Fatal(http.ListenAndServe(":8081", nil)) 37 }