46 lines
916 B
Go
46 lines
916 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"net/http"
|
||
|
|
"os"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"darjeeling.systemec.nl/rhouben/fibonacci/functions"
|
||
|
|
)
|
||
|
|
|
||
|
|
func MyFibonacci(count int) (fibonaccivalue int) {
|
||
|
|
fibonaccivalue = 1
|
||
|
|
var prev_fibonacci int = 0
|
||
|
|
|
||
|
|
for i := 1; i < count; i++ {
|
||
|
|
fibonaccivalue += prev_fibonacci
|
||
|
|
prev_fibonacci = fibonaccivalue - prev_fibonacci
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
var port_number int
|
||
|
|
var error error
|
||
|
|
var bind_socket string
|
||
|
|
fmt.Println("Hello, world. I'm teaching myself Go.")
|
||
|
|
|
||
|
|
if len(os.Args) <= 1 {
|
||
|
|
port_number = 8088
|
||
|
|
} else {
|
||
|
|
port_number, error = strconv.Atoi(os.Args[1])
|
||
|
|
|
||
|
|
if error != nil {
|
||
|
|
fmt.Printf("I had an error trying to parse %s into a number: %s\n",
|
||
|
|
os.Args[1],
|
||
|
|
error)
|
||
|
|
os.Exit(0)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bind_socket = fmt.Sprintf(":%d", port_number)
|
||
|
|
http.HandleFunc("/fibonacci", functions.HttFibonacci)
|
||
|
|
fmt.Printf("Listening on port %d...", port_number)
|
||
|
|
http.ListenAndServe(bind_socket, nil)
|
||
|
|
}
|