Panic occurs when you use the new create struct to access the key
sandaawa opened this issue · comments
sandaawa commented
Hello, I am a Golang novice. When I was learning your code, I found that I used new() to create the struct. When I access the data, panic prompt Err :nil.Is this a bug?
Christian Muehlhaeuser commented
You shouldn't usually use new
to allocate a struct in Go. There's no such thing as a constructor, but you'll typically find methods that initialize the struct. In idiomatic Go that would be NewCache
or NewTable
, but cache2go has a fairly old and established API, so here it works something like this:
cache := cache2go.Cache("myCache")
Please refer to the README and examples for more information on how to use cache2go.