From 3d374a90c21660a33c069e48a2eb99c156529286 Mon Sep 17 00:00:00 2001 From: b3t0 Date: Fri, 12 Apr 2024 16:25:46 -0600 Subject: [PATCH] main.go added, main func with two handlers --- main.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 main.go 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) +}