tools

package
v0.0.0-...-011315e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 9 Imported by: 0

README

为了解决一下循环套嵌

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFuncs = template.FuncMap{
	"msg": func() string { return "hello this is a msg" },
	"strDefault": func(str string, def string) string {
		if str != "" {
			return str
		}
		return def
	},
	"timeFormat": func(t time.Time) string {
		return t.Format("2006-01-02 15:04:05")
	},
	"time": func(t time.Time, layout string) string {
		return t.Format(layout)
	},
	"now": func() time.Time {
		return time.Now()
	},
	"tTime": func(t utils.JSONTime, layout string) string {
		return t.Format(layout)
	},
	"admin": func() map[string]interface{} {
		return map[string]interface{}{
			"name": "MD webSite",
		}
	}, "site": func(title string, args ...interface{}) *SiteInfo {
		return &SiteInfo{
			Title: title,
			User:  &models.UserModel{},
		}
	},
	"tFormatDate": func(t utils.JSONTime) string {
		return t.Format("2006-01-02")
	},
	"thisWeek": func() string {
		now := time.Now()
		delta := (time.Monday - now.Weekday())
		if delta > 0 {
			delta = -6
		}
		monday := now.AddDate(0, 0, int(delta))
		return monday.Format("2006-01-02")
	},
	"lastWeek": func() string {
		now := time.Now()
		delta := (time.Monday - now.Weekday())
		if delta > 0 {
			delta = -6
		}
		monday := now.AddDate(0, 0, int(delta-7))
		return monday.Format("2006-01-02")
	},
	"today": func() string {
		return time.Now().Format("2006-01-02")
	},
	"yesterday": func() string {
		return time.Now().AddDate(0, 0, -1).Format("2006-01-02")
	},
	"thisMonth": func() string {
		now := time.Now()
		return time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).Format("2006-01-02")
	},
	"lastMonth": func() string {
		now := time.Now()
		return time.Date(now.Year(), now.Month()-1, 1, 0, 0, 0, 0, now.Location()).Format("2006-01-02")
	},
	"url": MakeURL,
	"strJoin": func(str string, args ...interface{}) string {
		return fmt.Sprintf(str, args...)
	},
}

TemplateFuncs 模板方法

Functions

func MakeURL

func MakeURL(_type string, args ...interface{}) string

MakeURL 管理模版中的url

func ParseGlob

func ParseGlob(tpl *template.Template, dir string, pattern string) (t *template.Template, err error)

ParseGlob 自定义模版解析,扫描子目录

Types

type SiteInfo

type SiteInfo struct {
	Title string
	User  *models.UserModel
}

SiteInfo SiteInfo

func (*SiteInfo) SetUser

func (s *SiteInfo) SetUser(user *models.UserModel) string

SetUser SetUser

type TemplateRenderer

type TemplateRenderer struct {
	Templates *template.Template
}

TemplateRenderer is a custom html/template renderer for Echo framework

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL