How to Serve Embedded Static Files from an HTTP Server

Web
Serve embedded static files in Go by creating an embed.FS variable and passing it to http.FileServer.

Serve embedded static files by registering a http.FileServer handler with the embed.FS filesystem.

package main

import (
	"embed"
	"net/http"
)

//go:embed static
var staticFS embed.FS

func main() {
	http.Handle("/", http.FileServer(http.FS(staticFS)))
	http.ListenAndServe(":8080", nil)
}