Created
October 2, 2015 05:05
-
-
Save francoishill/50c471fc5a74c7f0a79f to your computer and use it in GitHub Desktop.
Simple static golang static site server
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 ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func printRecovery() { | |
if r := recover(); r != nil { | |
log.Fatalln(fmt.Sprintf("ERROR: %+v", r)) | |
} | |
} | |
func main() { | |
defer printRecovery() | |
if len(os.Args) < 2 { | |
panic("Require first command-line argument to be port") | |
} | |
portStr := os.Args[1] | |
log.Println(fmt.Sprintf("Listening on %s...", portStr)) | |
panic(http.ListenAndServe(":"+portStr, http.FileServer(http.Dir(".")))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment