Support zero value in template

Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
This commit is contained in:
Peng Gao 2016-08-31 14:04:57 +08:00
parent 4378c9a40e
commit f7f14e07e4
2 changed files with 2 additions and 4 deletions

View File

@ -129,7 +129,7 @@ func (c *cache) Get(k string) ({{.ValueType}}, bool) {
// TODO: inline time.Now implementation // TODO: inline time.Now implementation
if !found || item.Expiration > 0 && time.Now().UnixNano() > item.Expiration { if !found || item.Expiration > 0 && time.Now().UnixNano() > item.Expiration {
c.mu.RUnlock() c.mu.RUnlock()
return {{.ValueType}}(0), false return {{.ZeroValue}}, false
} }
c.mu.RUnlock() c.mu.RUnlock()
return item.Object, true return item.Object, true
@ -207,8 +207,7 @@ func (c *cache) delete(k string) ({{.ValueType}}, bool) {
delete(c.items, k) delete(c.items, k)
return v.Object, true return v.Object, true
} }
//TODO: zeroValue return {{.ZeroValue}}, false
return 0, false
} }
func (c *cache) deleteFast(k string) { func (c *cache) deleteFast(k string) {

View File

@ -147,7 +147,6 @@ FIND:
if typeName == "" { if typeName == "" {
typeName = *valueType typeName = *valueType
} }
fmt.Println("real", typeName, "value", *valueType)
zeroTypeValue := zeroValue(typeName) 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) 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 { if err != nil {