k
This commit is contained in:
34
main.go
Normal file
34
main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Serve is a very simple static file server in go
|
||||
Usage:
|
||||
-p="8100": port to serve on
|
||||
-d=".": the directory of static files to host
|
||||
Navigating to http://localhost:8100 will display the index.html or directory
|
||||
listing file.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
exePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
port := flag.String("p", "8100", "port to serve on")
|
||||
directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host")
|
||||
flag.Parse()
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(*directory)))
|
||||
|
||||
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
|
||||
log.Fatal(http.ListenAndServe(":"+*port, nil))
|
||||
}
|
||||
Reference in New Issue
Block a user