36 lines
731 B
Go
36 lines
731 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
|
|
"darjeeling.systemec.nl/rhouben/fibonacci/functions"
|
|
)
|
|
|
|
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)
|
|
http.HandleFunc("/sum", functions.HttSum)
|
|
fmt.Printf("Listening on port %d...\n", port_number)
|
|
http.ListenAndServe(bind_socket, nil)
|
|
}
|