我正在尝试进入RUN go get github.com/<user>/<repo>docker 内部。我想用 GitHub 的个人访问令牌来做到这一点。为此我尝试跑步
git config --global url.\xe2\x80\x9dhttps://${GIT_TOKEN}@github.com/".insteadOf \xe2\x80\x9chttps://github.com/"\nRun Code Online (Sandbox Code Playgroud)\n和
\ngit config --global url.\xe2\x80\x9dhttps://${GITHUB_USER}:${GIT_TOKEN}@github.com/".insteadOf \xe2\x80\x9chttps://github.com/"\nRun Code Online (Sandbox Code Playgroud)\n这两个命令都抛出类似的错误
\nerror: invalid key: url.\xe2\x80\x9dhttps://<pa_token>@github.com/.insteadOf \xe2\x80\x9chttps://github.com/\nRun Code Online (Sandbox Code Playgroud)\n有人可以告诉我使用 GitHub PAT 的正确方法是什么吗?
\n我是 Golang 的新手。我必须map[string]interface{}像JSON.stringify在 javascript 中那样在 Golang 中对 a 进行字符串化。在 javascript 中,undefined当你这样做时,它们的值会被省略,JSON.stringify当我json.Marshal在 Golang 中为nil值做时,我想要同样的事情。例如在javascript中
var activity = {"isvalid": true, "value": {"prop": undefined}, "prop": undefined}
console.log(JSON.stringify(activity))
// Output: {"isvalid":true,"value":{}}
Run Code Online (Sandbox Code Playgroud)
但是在 Golang 如果我这样做
activity := map[string]interface{}{
"isvalid": true,
"value": map[string]interface{}{"prop": nil},
"prop": nil,
}
jsonStr, _ := json.Marshal(activity)
fmt.Println(string(jsonStr))
// output: {"isvalid":true,"prop":null,"value":{"prop":null}}
Run Code Online (Sandbox Code Playgroud)
https://play.golang.org/p/dvmz32phdNU
输出有所不同,在 Golang 中使输出与 Javascript 相同的好方法是什么?
编辑:
用例涉及从类型map[string]interface{}和键可以是任意的各种来源获取数据,因此将其转换为结构对我来说不是一个选择。