Skip to content

Instantly share code, notes, and snippets.

@gdiggs
Created April 16, 2014 02:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdiggs/10798802 to your computer and use it in GitHub Desktop.
Save gdiggs/10798802 to your computer and use it in GitHub Desktop.
One Line Go server to serve static assets from current folder
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
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