Created
May 4, 2015 01:55
-
-
Save adamveld12/84be49a9144341026c31 to your computer and use it in GitHub Desktop.
Static file server implementation
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" | |
"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