我試圖運行條件基本上看如果對象是空的,但這個錯誤我不斷收到(類似的變化):類型不匹配*字符串,字符串
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]:
我敢肯定,有什麼簡單的方法來做到這一點,但我不是很熟悉,處理的對象/結構