Last active
March 1, 2018 23:04
-
-
Save v2keener/85dbe0dc13a3a0f0d4087e172ddc6468 to your computer and use it in GitHub Desktop.
Golang Static Webserver (for current directory)
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
/* | |
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