mirror of https://github.com/go-sonic/sonic.git
feat: add new template functions (#316)
* Fix update menu report update menu failed because of updateResult.RowsAffected=0 * Add template function * Add template functionpull/317/head
parent
2998933cee
commit
98d43b885d
@ -0,0 +1,34 @@
|
|||||||
|
package extension
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/go-sonic/sonic/model/dto"
|
||||||
|
"github.com/go-sonic/sonic/service"
|
||||||
|
"github.com/go-sonic/sonic/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type statisticExtension struct {
|
||||||
|
Template *template.Template
|
||||||
|
StatisticService service.StatisticService
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterStatisticFunc(template *template.Template, statisticService service.StatisticService) {
|
||||||
|
s := &statisticExtension{
|
||||||
|
Template: template,
|
||||||
|
StatisticService: statisticService,
|
||||||
|
}
|
||||||
|
s.addGetStatisticsData()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *statisticExtension) addGetStatisticsData() {
|
||||||
|
getStatisticsDataFunc := func() (*dto.Statistic, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
statistic, err := s.StatisticService.Statistic(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return statistic, nil
|
||||||
|
}
|
||||||
|
s.Template.AddFunc("getStatisticsData", getStatisticsDataFunc)
|
||||||
|
}
|
Loading…
Reference in New Issue