How to Use http.Handler and http.HandlerFunc in Go

Web
Use http.HandlerFunc to convert a function into an http.Handler for serving web requests in Go.

Use http.Handler as an interface for types that implement ServeHTTP, and http.HandlerFunc as a function type that satisfies that interface. Convert a function to a handler by assigning it to http.HandlerFunc and pass it to http.ListenAndServe.

package main

import (
	"fmt"
	"net/http"
)

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