When the following code:
if map == nil {
log.Fatal("map is empty")
}
is run, the log statement is not executed, while fmt.Println(map)
indicates that the map is empty:
map[]
You can use len
:
if len(map) == 0 {
....
}
From https://golang.org/ref/spec#Length_and_capacity
len(s) map[K]T map length (number of defined keys)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加