Golang在OpenShift上,我无法找到本地模块

时间:2014-04-21 10:35:49

标签: go openshift

我想为Golang应用程序使用OpenShift测试环境。

我做了一个测试应用程序:

myproj/
------web.go
------/mylib/
-------------mylib.go

web.go是标准的OpenShift文件:

package main

import (
    "fmt"
    "net/http"
    "os"
    "runtime"
    "./mylib"
)

func main() {
    http.HandleFunc("/", hello)
    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)
    }
}

func hello(res http.ResponseWriter, req *http.Request) {
    str := mylib.Lib();
    fmt.Fprintf(res, "hello, %s from %s", str, runtime.Version())
}

我创建了" mylib"

package mylib

func Lib() string {
    return "world"
}

当我跑步时#34;去运行web.go"在我的本地计算机上一切正常。但是当我尝试将此代码上传到OpenShift时,我收到以下错误:

remote: -----> Using Go 1.1.2
remote: -----> Running: go get -tags openshift ./...
remote: can't load package: /var/lib/openshift/5354e6fd4382ec2dca000223/app-root/runtime/repo/.openshift/g/src/github.com/smarterclayton/goexample/web.go:8:2: local import "./mylib" in non-local package
remote: An error occurred executing 'gear postreceive' (exit code: 1)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/5354e6fd4382ec2dca000223/go

这是什么意思?为什么Golang找不到这个包裹?我无法在一个文件中写入所有代码。我该如何编写OpenShift的应用程序?

1 个答案:

答案 0 :(得分:2)

我知道这个问题已经过时了,但我遇到了同样的问题而且很难找到解决方案,所以我决定问一下谁来解决同样的问题。

解决方案非常简单,可以在github上的go cartdrige repo的自述文件中找到:github.com/smarterclayton/openshift-go-cart

您必须创建名为 .godir 的文件,并在此处输入服务器主程序包的名称。 例如,如果您输入 myserver ,则可以使用:

package main
import "myserver/mylib"
func main() {
    mylib.DoStuff()
}

基本上当你推动openshift时,repo会在构建之前复制到 .godir 中的目录中