Created
July 7, 2021 17:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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