Skip to content

Instantly share code, notes, and snippets.

@lcaballero
Created May 5, 2017 19:15
Show Gist options
  • Save lcaballero/b98857a3061f3b339e03153b5e2c54c7 to your computer and use it in GitHub Desktop.
Save lcaballero/b98857a3061f3b339e03153b5e2c54c7 to your computer and use it in GitHub Desktop.
Serve directory
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