Cannot convert nil to type x

Consider the following example:

lock.RLock() var product *Product if store[productId] != nil { //cannot convert nil to type Product product = &Product{} *product = *store[productId] //invalid indirect of store[productId] (type Product) } lock.RUnlock() 

The exceptions are comments, and I don’t understand what I am doing wrong.

store is map[int]Product

any ideas?

+6
source share
1 answer

You are using the store as if it were declared as:

 store := make(map[int]*Product) 
+6
source

Source: https://habr.com/ru/post/972133/


All Articles