Created
May 5, 2017 19:15
-
-
Save lcaballero/b98857a3061f3b339e03153b5e2c54c7 to your computer and use it in GitHub Desktop.
Serve directory
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 ( | |
"fmt" | |
"net/http" | |
"os" | |
) | |
func main() { | |
dir := "." | |
if len(os.Args) > 1 { | |
dir = os.Args[1] | |
} | |
port := 80 | |
ip := fmt.Sprintf("%s:%d", "127.0.0.1", port) | |
fmt.Printf("binding web server at %s\n", ip) | |
err := http.ListenAndServe(ip, http.FileServer(http.Dir(dir))) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment