diff --git a/main.go b/main.go new file mode 100644 index 0000000..cc00b66 --- /dev/null +++ b/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "net/http" +) + +var portNumber = ":8080" + +// Home is the home page handler +func Home(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "This is the home page") +} + +// About is the about page handler +func About(w http.ResponseWriter, r *http.Request) { + sum := addValues(2, 2) + _, _ = fmt.Fprintf(w, fmt.Sprintf("This is the about page and 2 + 2 is %d", sum)) +} + +// addValues adds twu integers and return the sum +func addValues(x, y int) int { + return x + y +} + +// main is the main application function +func main() { + http.HandleFunc("/", Home) + http.HandleFunc("/about", About) + + fmt.Println(fmt.Sprintf("Staritn application on port %s", portNumber)) + _ = http.ListenAndServe(portNumber, nil) +}