How to Handle Routes in Go with net/http

Web
Handle routes in Go by mapping URL patterns to functions using http.HandleFunc and starting the server with http.ListenAndServe.

Use http.HandleFunc to map URL patterns to handler functions, then call http.ListenAndServe to start the server.

package main

import (
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %s", r.URL.Path)
	})
	http.ListenAndServe(":8080", nil)
}