Created
August 9, 2022 17:21
-
-
Save satishbabariya/16fd4f65844c378994dad8ea01038c18 to your computer and use it in GitHub Desktop.
Go embed
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" | |
"net/http" | |
) | |
//go:embed public | |
var content embed.FS | |
func handler() http.Handler { | |
fsys := fs.FS(content) | |
html, _ := fs.Sub(fsys, "public") | |
return http.FileServer(http.FS(html)) | |
} | |
func main() { | |
mux := http.NewServeMux() | |
mux.Handle("/", handler()) | |
http.ListenAndServe(":8080", mux) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment