如何在Google App Engine中使用golang的bunch或引用自定义依赖项

huangapple go评论96阅读模式
英文:

How to use bunch in golang for Google App Engine or referencing Custom Dependancies

问题

目前我正在使用bunch来进行npm风格的类型构建,并在我的Web项目中使用符号链接,以便在不必从git存储库中拉取的情况下进行构建。

例如,我的目录结构如下所示:

testapp/
.vendor
-controllers
--user_controller.go
-routers
--router.go
-models
--user.go
server.go
Bunchfile

所以在.vendor/src目录中

我还有

.vendor/src/example.com/tgo/testapp/routers

因此,如果我不想在.vendor目录中复制我的文件夹,我将使用符号链接-当我执行以下操作时,这非常有效

ln -s ~/Documents/dev/go/testapp/ ~/Documents/dev/go/testapp/.vendor/src/example.com/tgo/

bunch go build

但是对于Google App Engine-我正在尝试看看是否可以工作,但还没有弄清楚。

以下是server.go的代码

package main

import (
  "example.com/tgo/testapp/routers"
  "github.com/codegangsta/negroni"
  "net/http"
  "log"
)

func init(){
  //For Google App Engine
  //settings.Init()
  router :=  routers.InitRoutes()
  n := negroni.Classic()
  n.UseHandler(router)
  http.Handle("/", n)
}
func main() {
  router :=  routers.InitRoutes()
  n := negroni.Classic()
  n.UseHandler(router)
  log.Println("Listening......")
  http.ListenAndServe(":3001", n)

}
英文:

Currently I'm using the bunch to do npm style type builds as well as using symbolic links in my web project to be able to do builds without have to pull from a git repository.

For example my directory structure is like the following

testapp/
.vendor
-controllers
--user_controller.go
-routers
--router.go
-models
--user.go
server.go
Bunchfile

so inside the .vendor/src directory

I also have

.vendor/src/example.com/tgo/testapp/routers

So if i don't want to have to duplicate my folders in the .vendor directory I will use a symbolic link - this works great when I do

ln -s ~/Documents/dev/go/testapp/ ~/Documents/dev/go/testapp/.vendor/src/example.com/tgo/

bunch go build

However for Google App Engine - Trying to see if this will work, haven't been able to figure it out yet.

Here is the code for server.go

package main

import (
  "example.com/tgo/testapp/routers"
  "github.com/codegangsta/negroni"
  "net/http"
  "log"
)

func init(){
  //For Google App Engine
  //settings.Init()
  router :=  routers.InitRoutes()
  n := negroni.Classic()
  n.UseHandler(router)
  http.Handle("/", n)
}
func main() {
  router :=  routers.InitRoutes()
  n := negroni.Classic()
  n.UseHandler(router)
  log.Println("Listening......")
  http.ListenAndServe(":3001", n)

}

答案1

得分: 0

我实际上找到了问题所在,与在上传到App Engine之前分配$GOPATH有关。

所以我只需要一个脚本,将环境变量$GOPATH设置为.vendor目录,然后运行goapp serve或goapp deploy,一切都正常工作!

期待将所有内容迁移到App Engine上!

英文:

I actually figured it out the issue has to do with Assigning $GOPATH before you run the upload to App Engine.

So I just have a script that sets the environment Variable $GOPATH to the .vendor directory then run goapp serve or goapp deploy and everything works!

Look forward to moving everything over to app engine!

huangapple
  • 本文由 发表于 2016年3月24日 17:26:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/36196819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定