FileServer (StripPrefix) in Go

Posted by GoDoc
Public (Editable by Users)

FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.

Go
Edit
package main

import "net/http"

func main() {
	// To serve a directory on disk (/tmp) under an alternate URL
	// path (/tmpfiles/), use StripPrefix to modify the request
	// URL's path before the FileServer sees it:
	http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
}