我將如何在運(yùn)行 golang 的 openshift 中安裝 github.com/gorilla/mux。我知道在本地我們確實(shí)去獲取并安裝。openshift 的等價(jià)物是什么。給出的代碼在我的電腦上運(yùn)行良好。但是在實(shí)時(shí)站點(diǎn)中給出 503 Service Unavailable。package mainimport ( "github.com/gorilla/mux" "fmt" "net/http" "os" "io/ioutil" )func homeHandler(res http.ResponseWriter, req *http.Request) { http.ServeFile(res,req, "home/index.html")}func dataHandler(res http.ResponseWriter, req * http.Request){ params:= mux.Vars(req) fName,_:=params["fname"] res.Header().Set("Access-Control-Allow-Origin", "*") contents,_ := ioutil.ReadFile("home/data/"+fName) res.Header().Set("Content-Type", "application/json") res.Write(contents)}func main() { r := mux.NewRouter() r.PathPrefix("/home/css/").Handler(http.StripPrefix("/home/css/",http.FileServer(http.Dir("home/css/")))) r.PathPrefix("/home/lib/").Handler(http.StripPrefix("/home/lib/",http.FileServer(http.Dir("home/lib/")))) r.PathPrefix("/home/views/").Handler(http.StripPrefix("/home/views/",http.FileServer(http.Dir("home/views/")))) r.PathPrefix("/home/images/").Handler(http.StripPrefix("/home/images/",http.FileServer(http.Dir("home/images/")))) r.HandleFunc("/home/data/{fname:.+}", dataHandler) r.HandleFunc(`/home/{name:.*}`,homeHandler) http.Handle("/", r) bind := fmt.Sprintf("%s:%s", os.Getenv("HOST"), os.Getenv("PORT")) fmt.Printf("listening on %s...", bind) err := http.ListenAndServe(bind, nil) if err != nil { panic(err) }
2 回答

呼如林
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
盡管我沒有使用 openshift 的經(jīng)驗(yàn),但通常您會(huì)希望提供您的依賴項(xiàng)。通過這樣做,您可以確保您的應(yīng)用程序可以使用正確的版本,而不必?fù)?dān)心 openshifts(或任何其他應(yīng)用程序平臺(tái))自己的構(gòu)建系統(tǒng)。
- 2 回答
- 0 關(guān)注
- 194 瀏覽
添加回答
舉報(bào)
0/150
提交
取消