How to create HTTP server

Start a Go HTTP server by defining a handler function and calling http.ListenAndServe with your desired port.

Use the net/http package to define a handler function and pass it to 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, World!")
	})
	http.ListenAndServe(":8080", nil)
}