35 lines
704 B
Go
35 lines
704 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
const portNumber = ":8080"
|
|
|
|
// Home is the about 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, "This is the about page and 2 + 2 is %d", sum)
|
|
}
|
|
|
|
// addValues adds two integers and returns 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.Printf("Starting application on port %s\n", portNumber)
|
|
|
|
_ = http.ListenAndServe(portNumber, nil)
|
|
}
|