Go 語言寫的 HTTP 服務器:knight
knight 是一個 Go 語言開發,支持自動重載功能的 HTTP 服務器,能夠自動檢測文件的改變并根據需要重啟服務器。用法,基本上你只需要設置一個 watching 路徑。
package main
import (
"fmt"
"net/http"
"github.com/fengsp/knight"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "It works!")
}
func main() {
http.HandleFunc("/", handler)
// pass your root path in
// pass "" to use current working directory
knight := knight.NewKnight("/private/tmp/test")
knight.ListenAndServe(":8000", nil)
}
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!