Serving static content with a root URL with the Gorilla toolkit

后端 未结 5 2138
礼貌的吻别
礼貌的吻别 2020-12-12 18:42

I am attempting to use the Gorilla toolkit\'s mux package to route URLs in a Go web server. Using this question as a guide I have the following Go code:

fu         


        
5条回答
  •  渐次进展
    2020-12-12 19:36

    I think you might be looking for PathPrefix...

    func main() {
        r := mux.NewRouter()
        r.HandleFunc("/search/{searchTerm}", Search)
        r.HandleFunc("/load/{dataId}", Load)
        r.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
        http.ListenAndServe(":8100", r)
    }
    

提交回复
热议问题