Skip to content

Instantly share code, notes, and snippets.

@whoeverest
Created July 7, 2021 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoeverest/1dbe5034d5c95954fc55dc91e5353e66 to your computer and use it in GitHub Desktop.
Save whoeverest/1dbe5034d5c95954fc55dc91e5353e66 to your computer and use it in GitHub Desktop.
A self-contained website executable, web server + web page. Written in GoLang using the embed directive/package.
package main
import (
"embed"
"io/fs"
"log"
"net/http"
)
//go:embed html
var embeddedFs embed.FS
func main() {
htmlFs, _ := fs.Sub(embeddedFs, "html")
static := http.FileServer(http.FS(htmlFs))
http.Handle("/", static)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("Error Starting the HTTP Server :", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment