Advertisement
frankjonen

Static Webserver in Go - Compile Ready

Oct 19th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.44 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "log"
  5.     "fmt"
  6.     "net/http"
  7.     "os/user"
  8. )
  9.  
  10. func main() {
  11. // Get the user folder.
  12. // We'll be serving the site from there.
  13.     usr, err := user.Current()
  14.     if err != nil {
  15.         log.Fatal(err)
  16.     }
  17.  
  18. // Website
  19.     fs := http.FileServer(http.Dir(usr.HomeDir+"/where/your/stuff/is/at"))
  20.     http.Handle("/", fs)
  21.  
  22.     fmt.Println("\r\n")
  23.     log.Println("| Serving the static has begun! \n")
  24.     http.ListenAndServe(":8080", nil)
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement