英文:
Deploying Go App with Heroku
问题
我正在使用这个指南来构建一个小的Go应用程序:
https://codegangsta.gitbooks.io/building-web-apps-with-go/index.html
文件夹结构如下:
go/src/fileserver/
main.go
fileserver.exe
public/
index.html
css/
bootstrap.min.css
部署说明中提到了一个"procfile"和一个".godir"文件,但不太清楚这些文件应该包含什么内容,以及它们应该在哪里实现。我也不确定我的文件夹结构是否正确。
我遇到的错误是:
Failed to detect set buildpack https://github.com/kr/heroku-buildpack-go.git
英文:
I'm using this guide to build a small Go app:
https://codegangsta.gitbooks.io/building-web-apps-with-go/index.html
Folder structure looks like this:
go/src/fileserver/
main.go
fileserver.exe
public/
index.html
css/
bootstrap.min.css
The deployment instructions mention a "procfile" and a ".godir" file but it's a bit unclear what these are supposed to contain or where they are to be implemented. I'm not quite sure if my folder structure is correct either.
The error I'm getting is:
Failed to detect set buildpack https://github.com/kr/heroku-buildpack-go.git
答案1
得分: 2
我将引用Heroku文档很多次。
Procfile
> 定义Procfile
> 在应用程序的根目录中使用Procfile,这是一个文本文件,明确声明启动应用程序所需执行的命令。
你部署的示例应用程序中的Procfile如下所示:
>web: go-getting-started
> 这声明了一个单一的进程类型web,并指定了运行它所需的命令。这里的名称web很重要。它声明了这个进程类型将附加到Heroku的HTTP路由堆栈,并在部署时接收Web流量。这里使用的命令go-getting-started是入门应用程序的编译二进制文件。
Procfile可以包含其他进程类型。例如,你可以声明一个用于处理队列中的项目的后台工作进程。
所以在你的示例中,你将在根目录下有一个名为'Procfile'的文件,内容如下:
web: fileserver
.godir
.godir
文件只是一个简单地指定你的Go项目的根目录的文件。当你有多个用不同语言编写的模块的Web应用程序时,这很有用。例如,给定具有以下树形结构的存储库。
github.com
└──someuser
└── somerepo
├── .godir
├── go_module
└── node_module
你的.godir
文件的内容将是:
github.com/someuser/somerepo/go_module
关于.godir
的更详细解释以及它的使用场景可以在这里找到。
英文:
Am going to be quoting the heroku documentation a lot.
Procfile
> Define a Procfile
> Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app.
The Procfile in the example app you deployed looks like this:
>web: go-getting-started
> This declares a single process type, web, and the command needed to run it. The name web is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed. The command used here, go-getting-started is the compiled binary of the getting started app.
Procfiles can contain additional process types. For example, you might declare one for a background worker process that processes items off of a queue.
So in your example you would have a file named 'Procfile' in your root directory with contents being:
web: fileserver
.godir
The .godir
file is simply a file that simply specifies the root directory of your go project. This is useful when you say have a number of modules for a web app in different languages. So for example given a repo with the following tree.
github.com
└──someuser
└── somerepo
├── .godir
├── go_module
└── node_module
Where the contents of your .godir
file would be:
github.com/someuser/somerepo/go_module
A more verbose explanation of what .godir
is for and when it is used can be found here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论