小编dra*_*oon的帖子

GitHub 中个人访问令牌的正确全局 git 配置

我正在尝试进入RUN go get github.com/<user>/<repo>docker 内部。我想用 GitHub 的个人访问令牌来做到这一点。为此我尝试跑步

\n
git config --global url.\xe2\x80\x9dhttps://${GIT_TOKEN}@github.com/".insteadOf \xe2\x80\x9chttps://github.com/"\n
Run Code Online (Sandbox Code Playgroud)\n

\n
git config --global url.\xe2\x80\x9dhttps://${GITHUB_USER}:${GIT_TOKEN}@github.com/".insteadOf \xe2\x80\x9chttps://github.com/"\n
Run Code Online (Sandbox Code Playgroud)\n

这两个命令都抛出类似的错误

\n
error: invalid key: url.\xe2\x80\x9dhttps://<pa_token>@github.com/.insteadOf \xe2\x80\x9chttps://github.com/\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以告诉我使用 GitHub PAT 的正确方法是什么吗?

\n

git github

7
推荐指数
1
解决办法
1万
查看次数

JSON.stringify 在 Golang 中等效于 map[string]interface{}

我是 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{}和键可以是任意的各种来源获取数据,因此将其转换为结构对我来说不是一个选择。

javascript json go

1
推荐指数
1
解决办法
3866
查看次数

标签 统计

git ×1

github ×1

go ×1

javascript ×1

json ×1