Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Created January 5, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codethereforam/d0cf8195a150088089458db39ecff371 to your computer and use it in GitHub Desktop.
Save codethereforam/d0cf8195a150088089458db39ecff371 to your computer and use it in GitHub Desktop.
go file server
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "8100", "port to serve on")
directory := flag.String("d", ".", "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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment