9.7 static file

➜  recipe07 tree .
.
├── html
│   └── page.html
├── static.go
└── welcome.txt

1 directory, 3 files
package main

import (
	"net/http"
)

func main() {

	fileSrv := http.FileServer(http.Dir("html"))
	fileSrv = http.StripPrefix("/html", fileSrv)

	http.HandleFunc("/welcome", serveWelcome)
	http.Handle("/html/", fileSrv)
	http.ListenAndServe(":8080", nil)
}

func serveWelcome(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "welcome.txt")
}

/*

 */

posted @ 2018-03-27 00:08  cucy_to  阅读(103)  评论(0)    收藏  举报