On Sun, 2 Apr 2017 16:10:57 -0700 (PDT)
[email protected] wrote:
> In short, I'm trying to cast type of
> function(string, sometype) -> function(interface{}, interface{})
> here is the code:
>
> https://play.golang.org/p/_ZCT8m_m_0
>
> I've tried like 10 possible options, and I believe I just don't see
> something really simple, will highly appreciate some insights on how
> to get it working.
In the onEvict function, make the "value" variable be of type
interface{} and type-assert it to be CacheItem, then pass onEvict
w/o any type-conversions to cache.Set():
func onEvict(key string, value interface{}) {
ci := value.(CacheItem)
fmt.Println(key, ci.v)
}
...
cache.Set("key1", t, onEvict)
Playground link: <https://play.golang.org/p/75OUF5W344>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.