-
-
Save v2keener/94bf92272dc92e6b2e9b4f986c9a5c2e to your computer and use it in GitHub Desktop.
How to get the current working directory in golang
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. Based on the gist | |
from which it was forked. | |
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