Last active
December 16, 2015 16:55
-
-
Save marcusandre/4eb7ac1402af782dc6a5 to your computer and use it in GitHub Desktop.
Serve static files using http.FileServer
This file contains hidden or 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
mkdir files | |
echo "32c3 is coming!" > files/file.txt | |
nohup go run main.go > /dev/null & | |
curl localhost:8080/file.txt |
This file contains hidden or 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 ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("files")))) | |
if err := http.ListenAndServe(":8080", nil); err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment