Last active
January 23, 2021 05:33
-
-
Save regmicmahesh/f2953e20abff11febb7f815fc16c922e to your computer and use it in GitHub Desktop.
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 ( | |
"flag" | |
"log" | |
"net/http" | |
"os" | |
) | |
var folderToServe string | |
func main() { | |
cwd, err := os.Getwd() | |
if err != nil { | |
log.Fatalln("Failed to get your current working directory") | |
} | |
flag.StringVar(&folderToServe, "f", cwd, "The directory to serve with server.") | |
flag.Parse() | |
dir := http.Dir(folderToServe) | |
log.Println("Serving File from", folderToServe) | |
fileServerHandler := http.FileServer(dir) | |
log.Println("Server running at Port 8080") | |
must(http.ListenAndServe(":8080", fileServerHandler), "Failed to Bind Server") | |
} | |
func must(err error, msg string) { | |
if err != nil { | |
log.Fatalln(msg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment