1 Star 0 Fork 2

QunXiongZhuLu / kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
none_template.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
小旭 提交于 2019-10-31 15:27 . btsgen support dao interface
package main
var _noneTemplate = `
// NAME {{or .Comment "get data from cache if miss will call source method, then add to cache."}}
func (d *{{.StructName}}) NAME(c context.Context) (res VALUE, err error) {
addCache := true
res, err = CACHEFUNC(c)
if err != nil {
{{if .CacheErrContinue}}
addCache = false
err = nil
{{else}}
return
{{end}}
}
{{if .EnableNullCache}}
defer func() {
{{if .SimpleValue}} if res == {{.NullCache}} { {{else}} if {{.CheckNullCode}} { {{end}}
res = {{.ZeroValue}}
}
}()
{{end}}
{{if .GoValue}}
if len(res) != 0 {
{{else}}
if res != {{.ZeroValue}} {
{{end}}
cache.MetricHits.Inc("bts:NAME")
return
}
{{if .EnableSingleFlight}}
var rr interface{}
sf := d.cacheSFNAME()
rr, err, _ = cacheSingleFlights[SFNUM].Do(sf, func() (r interface{}, e error) {
cache.MetricMisses.Inc("bts:NAME")
r, e = RAWFUNC(c)
return
})
res = rr.(VALUE)
{{else}}
cache.MetricMisses.Inc("bts:NAME")
res, err = RAWFUNC(c)
{{end}}
if err != nil {
return
}
var miss = res
{{if .EnableNullCache}}
{{if .GoValue}}
if len(miss) == 0 {
{{else}}
if miss == {{.ZeroValue}} {
{{end}}
miss = {{.NullCache}}
}
{{end}}
if !addCache {
return
}
{{if .Sync}}
ADDCACHEFUNC(c, miss)
{{else}}
d.cache.Do(c, func(c context.Context) {
ADDCACHEFUNC(c, miss)
})
{{end}}
return
}
`
1
https://gitee.com/QunXiongZhuLu/kratos.git
git@gitee.com:QunXiongZhuLu/kratos.git
QunXiongZhuLu
kratos
kratos
v0.6.2

搜索帮助

14c37bed 8189591 565d56ea 8189591