duanfu1942 2014-11-28 10:21 采纳率: 100%
浏览 60

如何在openshift中将外部软件包添加到golang

how would I install github.com/gorilla/mux in openshift running golang. I know locally we do go get and go install. What is the equivalent for openshift. The code given works fine on my computer. But gives 503 Service Unavailable in the live site.

package main

import (
    "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条回答 默认 最新

  • duanaoyuan7202 2014-11-30 10:22
    关注

    Even though I have no experience with openshift, generally you will want to vendor your dependencies. By doing so, you can be sure the right version is available to your application, and don't have to worry about openshifts (or any other application platforms) own build system.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度