Created
January 26, 2016 15:04
-
-
Save henryscala/54855e4adf9c3bd04a90 to your computer and use it in GitHub Desktop.
A simple http server implemented in golang, can be used to serve static contents in a directory.
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 ( | |
"flag" | |
"fmt" | |
"net/http" | |
) | |
const () | |
func main() { | |
var path string | |
var port int | |
flag.StringVar(&path, "path", "", "specify the local path") | |
flag.IntVar(&port, "port", 8080, "specify listen port number") | |
flag.Parse() | |
dir := http.Dir(path) | |
hdr := http.FileServer(dir) | |
addr := fmt.Sprintf(":%d", port) | |
fmt.Println("starting http server on", dir, addr) | |
err := http.ListenAndServe(addr, hdr) | |
if err != nil { | |
fmt.Println("error happened while start http server", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment