In this recipe, we will define three routes, such as /, /login, and /logout along with their handlers. Perform the following steps:
- Create http-server-basic-routing.go and copy the following content:
package mainimport ( "fmt" "log" "net/http")const ( CONN_HOST = "localhost" CONN_PORT = "8080")func helloWorld(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!")}func login(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Login Page!")}func logout(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Logout Page!")}func main() { http.HandleFunc("/", helloWorld) http.HandleFunc("/login", login) http.HandleFunc("/logout", logout) err := http.ListenAndServe(CONN_HOST+":"+CONN_PORT, nil) if err ...