http

package
v0.0.0-...-8580c6f Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: GPL-3.0, GPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncMaps = template.FuncMap{

	"formatTime": func(i interface{}) string {
		ctime, ok := i.(string)
		if !ok {
			return ""
		}
		t, _ := time.Parse("2006-01-02 15:04:05", ctime)
		return t.Format(time.RFC3339) + "+08:00"
	},
	"format": func(i interface{}, format string) string {
		switch i.(type) {
		case time.Time:
			return (i.(time.Time)).Format(format)
		case int64:
			val := i.(int64)
			return time.Unix(val, 0).Format(format)
		}

		return ""
	},
	"hasPrefix": func(s, prefix string) bool {
		if strings.HasPrefix(s, prefix) {
			return true
		}
		return false
	},
	"add": func(nums ...interface{}) int {
		total := 0
		for _, num := range nums {
			if n, ok := num.(int); ok {
				total += n
			}
		}
		return total
	},
	"mod": func(num1, num2 int) int {
		if num1 == 0 {
			num1 = rand.Intn(500)
		}

		return num1 % num2
	},
	"divide": func(num1, num2 int) int {
		return int(math.Ceil(float64(num1) / float64(num2)))
	},
	"explode": func(s, sep string) []string {
		return strings.Split(s, sep)
	},
	"noescape": func(s string) template.HTML {
		return template.HTML(s)
	},
	"timestamp": func(ts ...time.Time) int64 {
		if len(ts) > 0 {
			return ts[0].Unix()
		}
		return time.Now().Unix()
	},
	"parseJSON": func(str string) map[string]interface{} {
		result := make(map[string]interface{})
		json.Unmarshal([]byte(str), &result)
		return result
	},
	"genList": func(n int, steps ...int) []int {
		step := 1
		if len(steps) > 0 {
			step = steps[0]
		}
		num := int(math.Ceil(float64(n) / float64(step)))
		nums := make([]int, num)
		for i := 0; i < num; i++ {
			nums[i] = i + 1
		}

		return nums
	},
}

funcMap 自定义模板函数

Functions

func FrontendCommon

func FrontendCommon() map[string]interface{}

公共部分

Types

type Common

type Common struct {
	Data    map[string]interface{} //数据
	TplName string                 //模板名称
	Jsons   map[string]interface{} //返回的json串
}

后台总控制器

func (*Common) Render

func (c *Common) Render(ctx echo.Context) error

渲染模板

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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