From f7f14e07e48f1705d94e72db9c880ef052178ce2 Mon Sep 17 00:00:00 2001 From: Peng Gao Date: Wed, 31 Aug 2016 14:04:57 +0800 Subject: [PATCH] Support zero value in template Signed-off-by: Peng Gao --- cachemap/cache.tmpl | 5 ++--- cachemap/main.go | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cachemap/cache.tmpl b/cachemap/cache.tmpl index b77273e..1e10eaa 100644 --- a/cachemap/cache.tmpl +++ b/cachemap/cache.tmpl @@ -129,7 +129,7 @@ func (c *cache) Get(k string) ({{.ValueType}}, bool) { // TODO: inline time.Now implementation if !found || item.Expiration > 0 && time.Now().UnixNano() > item.Expiration { c.mu.RUnlock() - return {{.ValueType}}(0), false + return {{.ZeroValue}}, false } c.mu.RUnlock() return item.Object, true @@ -207,8 +207,7 @@ func (c *cache) delete(k string) ({{.ValueType}}, bool) { delete(c.items, k) return v.Object, true } - //TODO: zeroValue - return 0, false + return {{.ZeroValue}}, false } func (c *cache) deleteFast(k string) { diff --git a/cachemap/main.go b/cachemap/main.go index fc63fd7..deab2ba 100644 --- a/cachemap/main.go +++ b/cachemap/main.go @@ -147,7 +147,6 @@ FIND: if typeName == "" { typeName = *valueType } - fmt.Println("real", typeName, "value", *valueType) zeroTypeValue := zeroValue(typeName) f, err := os.OpenFile(fmt.Sprintf("%s2%s_cachemap.go", *keyType, *valueType), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0644) if err != nil {