Skip to content

Instantly share code, notes, and snippets.

@e7
Created January 9, 2018 10:16
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 e7/2f641be2e8a5c6283520a20354bf3928 to your computer and use it in GitHub Desktop.
Save e7/2f641be2e8a5c6283520a20354bf3928 to your computer and use it in GitHub Desktop.
简单的http文件服务器
package main
import (
"net/http"
"github.com/urfave/negroni"
)
func main() {
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.Dir(".")))
// Example of using a http.FileServer if you want "server-like" rather than "middleware" behavior
// mux.Handle("/public", http.FileServer(http.Dir("/home/public")))
n := negroni.New()
n.UseHandler(mux)
http.ListenAndServe(":8000", n)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment