英文:
My changes are not ending up in the go app. What's going on with go?
问题
我是你的中文翻译助手,以下是你要翻译的内容:
我是Go语言的新手。
我克隆了这个项目:oauth2_proxy
我想要添加另一个提供者。所以我在providers文件夹中创建了提供者文件,并在switch语句中添加了提供者名称。
然而,当我构建生成的二进制文件时,提供者仍然回退到了Google。
看起来我的提供者没有被添加进去。我怀疑是因为go build可能从GitHub获取提供者并忽略了我本地的更改。是这样吗?如何构建这个东西?
我正在使用go build
进行构建,因为./dist.sh
脚本对我不起作用。我成功生成了一个二进制文件。但是似乎我的代码文件没有被包含进去。我知道这是因为当我在生成的二进制文件中使用grep搜索"google"、"linkedin"或任何提供者名称时,它会显示:Binary file oauth2_proxy matches
。但是对于我的自定义提供者,没有匹配项。
这可能与我编译应用程序的方式有关。我该怎么做?在GitHub页面上没有提供相关的说明。对不起,我对此一无所知。我来自C++背景,那更加逻辑。Go似乎会自动处理依赖关系!?
根据@Topo的建议,执行以下操作:
matthewh@xen:~/dev/oauth2_proxy$ export GOPATH=`pwd`
matthewh@xen:~/dev/oauth2_proxy$ rm -rf src
matthewh@xen:~/dev/oauth2_proxy$ go get ./...
go install: no install location for directory /home/matthewh/dev/oauth2_proxy outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/api outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/cookie outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/providers outside GOPATH
For more details see: 'go help gopath'
src/cloud.google.com/go/internal/retry.go:21:2: cannot find package "github.com/googleapis/gax-go" in any of:
/usr/local/go/src/github.com/googleapis/gax-go (from $GOROOT)
/home/matthewh/dev/oauth2_proxy/src/github.com/googleapis/gax-go (from $GOPATH)
src/google.golang.org/api/internal/settings.go:22:2: cannot find package "google.golang.org/grpc" in any of:
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/home/matthewh/dev/oauth2_proxy/src/google.golang.org/grpc (from $GOPATH)
src/google.golang.org/api/transport/dial.go:30:2: cannot find package "google.golang.org/grpc/credentials" in any of:
/usr/local/go/src/google.golang.org/grpc/credentials (from $GOROOT)
...
[1]: https://github.com/bitly/oauth2_proxy
英文:
I'm new to go.
I have cloned this project: oauth2_proxy
I'm wanting to add another provider. So I created the provider file in providers. Added the provider name to the providers switch statement.
However, when I build the resulting binary, the provider keeps falling back to google.
It seems my provider has not been added. I suspect that go build might be pulling the providers from github and ignoring my local changes. Would that be right? How do you build this thing?
I'm building with go build
because ./dist.sh script didn't work for me. I'm managing to produce a binary. But it doesn't appear my code file ended up in it. I know this because when I grep for "google" or "linkedin" or any of the provider names on the resulting binary it says: Binary file oauth2_proxy matches
. But for my own provider, there is no match.
It's probably got something to do with the way I'm compiling the app. How do I do that? no instructions on the github page for doing that are provided. Sorry for my ignorance. I'm coming from a c++ background which is more logical. Go seems to pick up dependancies automagically!?
Following suggestions from @Topo
matthewh@xen:~/dev/oauth2_proxy$ export GOPATH=`pwd`
matthewh@xen:~/dev/oauth2_proxy$ rm -rf src
matthewh@xen:~/dev/oauth2_proxy$ go get ./...
go install: no install location for directory /home/matthewh/dev/oauth2_proxy outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/api outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/cookie outside GOPATH
For more details see: 'go help gopath'
go install: no install location for directory /home/matthewh/dev/oauth2_proxy/providers outside GOPATH
For more details see: 'go help gopath'
src/cloud.google.com/go/internal/retry.go:21:2: cannot find package "github.com/googleapis/gax-go" in any of:
/usr/local/go/src/github.com/googleapis/gax-go (from $GOROOT)
/home/matthewh/dev/oauth2_proxy/src/github.com/googleapis/gax-go (from $GOPATH)
src/google.golang.org/api/internal/settings.go:22:2: cannot find package "google.golang.org/grpc" in any of:
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/home/matthewh/dev/oauth2_proxy/src/google.golang.org/grpc (from $GOPATH)
src/google.golang.org/api/transport/dial.go:30:2: cannot find package "google.golang.org/grpc/credentials" in any of:
/usr/local/go/src/google.golang.org/grpc/credentials (from $GOROOT)
...
[1]: https://github.com/bitly/oauth2_proxy
答案1
得分: 1
我刚刚在我的机器上运行了go get -v github.com/bitly/oauth2_proxy
命令。
详细信息请参考:http://pasted.co/60e2b56d
生成的二进制文件位于$GOPATH/bin/oauth2_proxy
下。
首先设置你的Go工作空间(如何编写Go代码),选择一个目录作为GOPATH。
例如:/Users/matt/dev
export GOPATH=/Users/matt/dev
然后使用go get
命令获取oauth2_proxy
。通常go get
相当于克隆该代码库。
go get github.com/bitly/oauth2_proxy
它会获取源代码并运行go install
命令。成功执行后,你将在$GOPATH/bin
目录下看到二进制文件。
现在按照你的需求修改源代码,并运行go install
来构建二进制文件。
go install github.com/bitly/oauth2_proxy
或者
cd $GOPATH/src/github.com/bitly/oauth2_proxy
go install
如果你想手动安装而不是使用go get
命令,那么选择一个目录作为GOPATH
并进行导出(如上所述),然后执行以下步骤:
mkdir -p $GOPATH/src/github.com/bitly
cd $GOPATH/src/github.com/bitly
git clone https://github.com/bitly/oauth2_proxy.git
cd oauth2_proxy
go get ./...
go install
现在二进制文件将位于$GOPATH/bin
目录下。
英文:
EDIT:
I just did go get -v github.com/bitly/oauth2_proxy
on my machine.
Verbose Details: http://pasted.co/60e2b56d
Binary is produced under $GOPATH/bin/oauth2_proxy
.
-rwxr-xr-x 1 jeeva staff 10M Jul 11 19:02 oauth2_proxy
Let's start from basis. First setup your Go workspace (How to Write Go Code) pick a directory for GOPATH.
For example: /Users/matt/dev
export GOPATH=/Users/matt/dev
Then do go get
to get the oauth2_proxy
. Typically go get is git clone of that repository.
go get github.com/bitly/oauth2_proxy
It will get the source code and runs go install
. After successful execution of this command. You will see binary file in $GOPATH/bin
.
Now modified the source code as you need and run go install to build the binary.
go install github.com/bitly/oauth2_proxy
OR
cd $GOPATH/src/github.com/bitly/oauth2_proxy
go install
If you would like to manually instead of go get
. Then pick a directory for GOPATH
and export it (as mentioned above) then
mkdir -p $GOPATH/src/github.com/bitly
cd $GOPATH/src/github.com/bitly
git clone https://github.com/bitly/oauth2_proxy.git
cd oauth2_proxy
go get ./...
go install
Now binary will be in $GOPATH/bin
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论