Created
July 15, 2019 15:22
-
-
Save ZenLiuCN/04e53fdbe352516598044ab17ff4fef8 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"net/http" | |
"os" | |
"path/filepath" | |
"log" | |
) | |
func main() { | |
var dir string | |
if len(os.Args) > 1 { | |
dir = os.Args[1] | |
} else { | |
dir = filepath.Dir(os.Args[0]) | |
} | |
srv := http.FileServer(http.Dir(dir)) | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
log.Println(r.RemoteAddr, r.RequestURI) | |
srv.ServeHTTP(w, r) | |
}) | |
log.Println("server listen on :8080") | |
err := http.ListenAndServe(":8080", nil) | |
if err != nil { | |
log.Fatal("Error ListenAndServe: ", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment