Skip to content

Instantly share code, notes, and snippets.

@v2keener
Forked from arxdsilva/working_directory.go
Last active March 1, 2018 23:03
Show Gist options
  • Save v2keener/94bf92272dc92e6b2e9b4f986c9a5c2e to your computer and use it in GitHub Desktop.
Save v2keener/94bf92272dc92e6b2e9b4f986c9a5c2e to your computer and use it in GitHub Desktop.
How to get the current working directory in golang
/*
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