Created
April 16, 2014 02:18
-
-
Save gdiggs/10798802 to your computer and use it in GitHub Desktop.
One Line Go server to serve static assets from current folder
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
echo "package main; import \"net/http\"; import \"os\"; import \"os/exec\"; import \"os/signal\"; func main() { go func() { sigchan := make(chan os.Signal, 2); signal.Notify(sigchan, os.Interrupt); <-sigchan; cmd := exec.Command(\"rm\", \"tempserver.go\"); cmd.Run(); os.Exit(0) }(); panic(http.ListenAndServe(\":8000\", http.FileServer(http.Dir(\".\")))) }" > tempserver.go && go run tempserver.go |
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 "net/http" | |
import "os" | |
import "os/exec" | |
import "os/signal" | |
func main() { | |
go func() { | |
sigchan := make(chan os.Signal, 2) | |
signal.Notify(sigchan, os.Interrupt) | |
<-sigchan | |
cmd := exec.Command("rm", "tempserver.go") | |
cmd.Run() | |
os.Exit(0) | |
}() | |
panic(http.ListenAndServe(":8000", http.FileServer(http.Dir(".")))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment