daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package main
  3.  
  4. import (
  5.     "flag"
  6.     "log"
  7.     "net/http"
  8.     "os"
  9. )
  10.  
  11. var port string
  12. var dir string
  13.  
  14. func init() {
  15.     flag.StringVar(&port, "p", "8080", "Port for the server to run on.")
  16.     flag.StringVar(&dir, "d", "", "Path to serve.")
  17. }
  18.  
  19. func main() {
  20.     flag.Parse()
  21.     if dir == "" {
  22.         dir, _ = os.Getwd()
  23.     }
  24.     http.Handle("/", http.FileServer(http.Dir(dir)))
  25.     log.Printf("Serving Dir: %s on port %s\n", dir, port)
  26.     err := http.ListenAndServe(":"+port, nil)
  27.     if err != nil {
  28.         log.Fatal("ListenAndServe: ", err)
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top