我试图运行一个条件来基本上查看对象是否为空,但我不断收到此错误的(类似变体):
invalid operation: release.Name == "" (mismatched types *string and string)
这是即将死亡的代码:
import (
"github.com/google/go-github/github"
)
func TestLatestTag(user, project string) {
var client *github.Client
client = github.NewClient(nil)
releases, _, err := client.Repositories.ListTags(user, project, nil)
var release github.RepositoryTag
if err != nil {
fmt.Println("Error")
} else {
if release.Name == "" {
fmt.Println("None")
} else {
fmt.Println(releases[0])
}
}
}
如果我将 if 语句更改*release.Name == ""为错误提示,我会得到一个不同的错误,我不太明白:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x26fd]
goroutine 1 [running]:
我确信有任何简单的方法可以做到这一点,但我对处理对象/结构不是很熟悉
HUH函数
眼眸繁星
扬帆大鱼
相关分类