Commit 099de8fa authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

Add Go server

parent 8d37b2ff
......@@ -25,3 +25,12 @@ make run
```
Your server should be listening on `0.0.0.0:8080`.
## Golang
A Go HTTP server is also provided for comparison. It uses the standard "net/http" package. To run it:
```shell
go run golang/server.go
```
package main
import (
"fmt"
"net/http"
//"runtime"
)
func handle_root(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, World!")
}
func fibonacci(n uint32) uint32 {
var i, a, b uint32
a, b = 0, 1
for i = 0; i < n; i++ {
a, b = b, a + b
}
return a
}
func handle_fibonacci(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Fibonacci(10^6) = %d (with overflow)\n", fibonacci(1000000))
}
func main() {
//runtime.GOMAXPROCS(2)
http.HandleFunc("/", handle_root)
http.HandleFunc("/fibonacci", handle_fibonacci)
fmt.Println("Serving on :8080")
http.ListenAndServe(":8080", nil)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment