Golang部署程序时Buildfile和Procfile的配置指南
Golang部署程序时Buildfile和Procfile的配置指南 我的问题与这个问题类似,并且我已经按照该问题最后一条评论中的建议操作:将简单的GoLang应用程序部署到AWS Elastic Beanstalk - #3 by awais。但我仍然遇到以下错误,我知道在这个过程中我一定做错了什么
application.go:7:2: 在任何路径中都找不到包 “github.com/gorilla/mux”
我的代码结构是这样的

我的 build.sh
#!/bin/bash
go get github.com/gorilla/mux
go build -o bin/application application.go
我的 buildfile.text
make: ./build.sh
我的 Procfile.text
web: bin/application
我是新手,但我唯一能想到的是可能buildfile和/或Procfile可能需要不同的扩展名。
然后我使用 zip …/eb.zip -r * .[^.]* 来压缩我的项目并上传到AWS,但上传完成后总是失败。提示信息是无法找到包 github.com/gorilla/mux。在这个过程中我是否遗漏了什么……我的代码在本地可以编译,代码如下:
package main
import (
"net/http"
"./Controllers"
"runtime"
"github.com/gorilla/mux"
"time"
)
func main() {
println(runtime.Version())
runtime.GOMAXPROCS(runtime.NumCPU())
r := mux.NewRouter()
r.HandleFunc("/testping", Controllers.TestPing)
http.Handle("/", r)
r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("public"))))
srv := &http.Server{
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
IdleTimeout: 120 * time.Second,
Addr: ":5000",
}
srv.ListenAndServe()
}
更多关于Golang部署程序时Buildfile和Procfile的配置指南的实战教程也可以访问 https://www.itying.com/category-94-b0.html
对我来说,https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html 文档读起来像是当存在 bin/application.go 文件时,构建文件和进程文件会被忽略,因为文档在列举应用程序构建方式的要点中首先提到了这一点。
请尝试重命名该文件并相应修改您的构建文件。
免责声明:本人从未使用过AWS,以上理解完全基于对上述链接文档的解读。
更多关于Golang部署程序时Buildfile和Procfile的配置指南的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


