Skip to content

Commit

Permalink
main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
rbague committed Jan 7, 2020
1 parent 8d25856 commit d8323d8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"flag"
"log"
"net/http"
"path/filepath"
)

func main() {
dir := flag.String("dir", ".", "the directory of which to serve files")
port := flag.String("port", "8080", "on which port to listen to")
flag.Parse()

directory, err := filepath.Abs(*dir)
if err != nil {
log.Fatalf("could not get absolute path from %q: %v", *dir, err)
}

mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.Dir(directory)))

if err := http.ListenAndServe(":"+*port, mux); err != http.ErrServerClosed {
log.Fatalf("server closed unexpectedly: %v", err)
}
}

0 comments on commit d8323d8

Please sign in to comment.