Skip to content

Instantly share code, notes, and snippets.

@adamveld12
Created May 4, 2015 01:55
Show Gist options
  • Save adamveld12/84be49a9144341026c31 to your computer and use it in GitHub Desktop.
Save adamveld12/84be49a9144341026c31 to your computer and use it in GitHub Desktop.
Static file server implementation
package main
import (
"flag"
"fmt"
"log"
"net/http"
"path/filepath"
)
var (
dir = flag.String("path", "./", "The directory to serve files from")
port = flag.Int("port", 8080, "The port to serve on")
)
func main() {
flag.Parse()
root, err := filepath.Abs(*dir)
if err != nil {
log.Fatal("Could not get the absolute file path.")
} else {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), http.FileServer(http.Dir(root))))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment