Skip to content

Instantly share code, notes, and snippets.

@v2keener
Last active March 1, 2018 23:04
Show Gist options
  • Save v2keener/85dbe0dc13a3a0f0d4087e172ddc6468 to your computer and use it in GitHub Desktop.
Save v2keener/85dbe0dc13a3a0f0d4087e172ddc6468 to your computer and use it in GitHub Desktop.
Golang Static Webserver (for current directory)
/*
This is not secure or recommended for anything other than testing.
Published under MIT or GPL with the most permissiveness
(whichever). No warranty implied or otherwise.
2018 03 01
Gustavo Keener
*/
package main
import (
"log"
"net/http"
"os"
)
func main() {
log.Println("Listening on port 9090...")
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
log.Printf("Listening in directory: %s", dir)
fs := http.FileServer(http.Dir(dir))
http.Handle("/", fs)
http.ListenAndServe(":9090", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment