- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我是新手,正在尝试使用 gocenter 远程存储库 (Artifactory 6.8) 来解决依赖关系。尽管设置了 GOPROXY 环境变量,但我的 gocenter-cache 存储库仍然是空的。
这是我的代码。
package main
import (
"fmt"
"github.com/naoina/go-stringutil"
)
func main() {
var str string = "hello_world_go"
fmt.Println(stringutil.ToUpperCamelCase(str)) //prints HelloWorldGo
}
我试图解决的依赖关系在这里:https://search.gocenter.io/github.com~2Fnaoina~2Fgo-stringutil/versions
这是我的 GOPROXY 环境变量:
$ echo $GOPROXY
https://<<my Artifactory URL>>/api/go/gocenter
这是 gocenter 存储库定义的截断版本。我用了jfrog docs用于设置:
{
"key" : "gocenter",
"packageType" : "go",
"url" : "https://gocenter.io/",
"rclass" : "remote"
}
当我运行“go get”时,依赖关系解析...
$ go get -v github.com/naoina/go-stringutil
github.com/naoina/go-stringutil (download)
但是 gocenter-cache 是空的,告诉我它没有被使用。
{
"repo" : "gocenter-cache",
"path" : "/",
"created" : "2019-04-17T16:35:37.586Z",
"lastModified" : "2019-04-17T16:35:37.586Z",
"lastUpdated" : "2019-04-17T16:35:37.586Z",
"children" : [ ],
"uri" : "https://<<REDACTED>>/api/storage/gocenter-cache"
}
也许我的“go get”应该有不同的目标?我只是使用 gocenter 中存在的内容:https://search.gocenter.io/github.com~2Fnaoina~2Fgo-stringutil/versions
如果您能帮助指出我做错了什么,我们将不胜感激。我还没有进入模块或类似的东西,因为我是一个 artifactory 管理员而不是开发人员。我只是在尝试制作此功能的原型(prototype),以便我们可以帮助建议用户如何操作。
--更新:我找到了https://golang.org/cmd/go/#hdr-Module_proxy_protocol然后尝试这个:
$ echo $GOPROXY; go get $GOPROXY/github.com/naoina/go-stringutil
https://<<REDACTED>>/api/go/gocenter
package https:/<<REDACTED>>/api/go/gocenter/github.com/naoina/go-stringutil: https:/<<REDACTED>>/api/go/gocenter/github.com/naoina/go-stringutil: invalid import path: malformed import path "https:/<<REDACTED>>/api/go/gocenter/github.com/naoina/go-stringutil": invalid char ':'
所以我的协议(protocol)和我的 url 之间的冒号是无效字符?另外为什么要删除我的一个正斜杠?
--更新 2:我让“go mod init”开始工作,有点:
$ go mod init
go: creating new go.mod: module example/hello
$ ls
go.mod hello.go
$ go build
build example/hello: cannot load github.com/naoina/go-stringutil: cannot find module providing package github.com/naoina/go-stringutil
$ cat go.mod
module example/hello
go 1.12
$ echo $GOPROXY
https://<<REDACTED>>/api/go/gocenter
--更新 3:
$ cat go.mod
module example/hello
go 1.12
require github.com/naoina/go-stringutil v0.1.0
$ go build
hello.go:6:2: cannot find package "github.com/naoina/go-stringutil" in any of:
C:\Go\src\github.com\naoina\go-stringutil (from $GOROOT)
C:\Users\samuelm\go\src\github.com\naoina\go-stringutil (from $GOPATH)
$ echo $GOPROXY
https://<<REDACTED>>/api/go/gocenter
--更新 4:看来我还没有使用模块?
$ go list -m all
go list -m: not using modules
--更新 5,回复:retgits您的步骤有所帮助,但我还没有完全做到。
$ find .
.
./bin
./src
./src/example.com
./src/example.com/hello
./src/example.com/hello/hello.go
$ cd src/
$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello
$ cat go.mod
module example.com/hello
go 1.12
$ go get -v github.com/naoina/go-stringutil
Fetching https://<<REDACTED>>/api/go/gocenter/github.com/naoina/go-stringutil/@v/list
Fetching https://<<REDACTED>>/api/go/gocenter/github.com/naoina/@v/list
Fetching https://<<REDACTED>>/api/go/gocenter/github.com/@v/list
go get github.com/naoina/go-stringutil: unexpected status (https://<<REDACTED>>/api/go/gocenter/github.com/naoina/go-stringutil/@v/list): 404 Not Found
$ go build example.com/hello
can't load package: package example.com/hello: unknown import path "example.com/hello": cannot find module providing package example.com/hello
$ cd example.com/hello/
$ go build
build example.com/hello/example.com/hello: cannot load github.com/naoina/go-stringutil: cannot find module providing package github.com/naoina/go-stringutil
我没有在我的 GOPROXY 中提供凭据,因为我们的最终用户没有帐户,我们在防火墙环境中并允许完全匿名读取访问。如果我们必须提供用户帐户,那么我们将无法支持 Go。
--最终更新:删除我的本地代理解决了 404 问题,retgits 解决方案有效。
最佳答案
您提到您不是 Go 开发人员,所以让我引导您完成所有步骤。我意识到这对这里的某些开发人员来说可能有点矫枉过正,但它可能会对您有所帮助。
根据您放置源代码的位置,您需要设置环境变量 GO111MODULE
.从 go 1.11 开始,建议不要再将源代码放在 $GOPATH 中。如果你把你的代码放在那里并想使用 Go 模块,你必须设置 GO111MODULE
至 true
(我个人将我所有的 Go 代码都放在 $GOPATH 之外)。在 Windows 上,您必须先创建环境变量并进行相应设置(并重新启动终端)。
要创建 Go 模块,您必须运行命令 go mod init <name of your module>
.就我而言,我运行了命令 go mod init github.com/retgits/bla
这创造了一个go.mod
归档
module github.com/retgits/bla
go 1.12
现在添加模块就像运行 go get
一样简单.如果您想使用 GoCenter 或 Artifactory 来帮助解决您的模块。
为了帮助解析模块,您可能需要查看两个选项:
goc
的实用程序使用goc
goc实用程序自动将 GOPROXY 设置为 GoCenter,绕过 Artifactory 等其他代理。 Go 客户端的当前行为是查看一个代理,如果不是所有模块都从那里解析,则构建失败。 goc
将首先查看 GoCenter,如果模块不在 GoCenter 中,它将从其原始位置(如 GitHub)获取模块
使用 Artifactory
如果您想使用 Artifactory 来解析和缓存您的 Go 模块,您必须使用 GoCenter 的设置创建一个远程存储库(如您所提到的,在文档中)。您必须将该远程存储库包含到虚拟存储库中才能使其正常工作。
将 GoCenter 设置为 GOPROXY
第三种选择是仅使用 GoCenter(由 JFrog 创建的公共(public)注册表),但这可能会打败您最初的问题:
export GOPROXY="https://gocenter.io"
go get -v github.com/naoina/go-stringutil
无论您选择哪个选项,它都会更新 go.mod
到
module github.com/retgits/bla
go 1.12
require github.com/naoina/go-stringutil v0.1.0 // indirect
indirect
是因为我还没有创建 .go
包含使用此导入的代码的文件。
如果我现在创建一个 main.go
样本与
package main
import (
"fmt"
"github.com/naoina/go-stringutil"
)
func main() {
str := stringutil.ToSnakeCase("HelloWorld")
fmt.Println(str)
}
// Running go run main.go would result in
// hello_world
它将删除 indirect
来自 go.mod 文件,因为我现在有依赖于我的模块的代码。
关于go - 如何使用 gocenter remote Artifactory repo 进行本地依赖解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55735128/
有什么区别 git ls-remote --heads origin 和 git ls-remote . "refs/remotes/*" ? --heads origin 版本需要一段时间才能运行,
当我执行 git remote -v 时,我得到了 origin git@xxx.yyy.cc:name fetch) origin git@xxx.yyy.cc:name (push) 为什么
要构建我的远程环境,我需要设置几个环境变量(它们在 docker-compose 文件中使用)。这些是在我的 ZSH 环境中设置的,因此从终端运行 docker-compose build 可以按预期
我有一个创建多个 Docker 镜像的项目。我想在 vscode-remote 中为每个图像设置一个 devcontainer,以便我可以为每个图像启动一个容器。 我一次只需要启动并连接到一个容器/图
我设置了以下 Remote : $ git remote korg rorg 以及以下分支: $ git branch -a * (no branch) remotes/korg/gingerbr
这是我得到的错误。我有一个简单的 .Net Remoting 设置。连接空闲几分钟后出现此错误。 对象“/7966b546_734e_410d_817a_a0e701f114f6/lfxehvbczn
我有两个远程 git 分支(称它们为“RemoteA”和“RemoteB”)。 “RemoteB”在过去的某个时候从“RemoteA”中分离出来。在那之后,许多提交已应用于两个分支,但我现在希望“Re
我知道使用下面的 git 命令我可以列出我所有的“远程”分支... [someone@someone-pc somerepo]$ git ls-remote Username for 'https:/
我最需要的是一些建议。 我有以下示例: 应用程序1.exe - 有对象 MyList 应用程序2.exe - 需要访问 MyList 并与对象交互,就好像它是从 Application2 创建的一样。
我有一个大型应用程序,它通过 .net 远程处理使用 COM 从 Web 层调用到中间层。在此模式下启动和运行非常慢。 COM 边界的两边都是我们的代码。 我希望能够(可选)在单个进程中运行它。相当多
假设我有两个 Remote :origin 和 upstream。有没有一种方法可以将对象 upstream 推送到 origin,以便其他从 origin 克隆我的 repo 的人能够运行像 git
简而言之; 如何删除远程多个 merge 的 Remote ? 更多背景; 我有一个 git 存储库,其中包含数十个已 merge 到 master 中的 Remote 。我可以使用以下方法一次删除这
我有一个仓库的本地 git clone。我当然可以使用 git remote 查看我的本地远程 origin。但是,我可以看到我的 Remote origin 的 Remote 吗?我可以查看有关这些
先决条件 - 远程服务器和客户端均已设置,客户端能够通过客户端激活的业务对象在服务器端调用方法并从服务器端接收事件。 在保持服务器和客户端运行的情况下更改远程服务器的IP地址,客户端仍然可以执行上述任
我正在设置一个新的远程主机,每次启动它时,我都会收到以下错误输出:有关如何解决此问题的任何反馈或指示? Pseudo-terminal will not be allocated because st
我只是不明白 Git 的帮助页面。那么会发生什么或有什么区别? 假设我有一个带有子模块 B 的 Git 项目 A。子模块 B 确实有一个子模块 C。克隆存储库后,A 指向 B 的特定提交。B 指向 C
我在 Java 中使用 rmi。但是有一个 ExportException“远程对象实现非法远程接口(interface)”。 这是我的代码,有人可以帮帮我吗? public interface Re
我对 git 越来越熟悉了,但是我遇到了一些让我困惑的事情。我们在这里使用本地镜像,因为我们的线路很慢。为了指向镜子,我在 .gitconfig 中有一些常用的东西。 当我想推送时,问题就来了。看来我
我设置了一个带有 conan“远程”存储库的 jfrog artifactory 来代理官方 conan-center 存储库。我看到三个不同的 conan-center URL,具体取决于我阅读的来
我无法使用 VSCode 远程 SSH 在我的远程服务器上保存任何文件,因为我不是 root 用户。 我关注了 official documentation关于如何使用 SSH 配置文件设置 ssh
我是一名优秀的程序员,十分优秀!