Skip to content

Instantly share code, notes, and snippets.

@smallnest
Forked from hauxe/http_static_easy.go
Created November 8, 2018 11:36
Show Gist options
  • Save smallnest/bac20a67a5be7bfab5af4202c2ca93fb to your computer and use it in GitHub Desktop.
Save smallnest/bac20a67a5be7bfab5af4202c2ca93fb to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"log"
"net/http"
"strings"
)
func main() {
port := flag.String("p", "3000", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host")
flag.Parse()
http.Handle("/statics/", http.StripPrefix(strings.TrimRight("/statics/", "/"), 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