helpers

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AnonymousContextKey = "anonymous_key"
View Source
const CSRFContextKey = "csrf_key"

Variables

View Source
var Map template.FuncMap = template.FuncMap{
	"build": func() build.Build {
		return build.Current
	},
	"headTags": func() template.HTML {
		return template.HTML(web.HeadTags)
	},
	"timeFormat": func(date time.Time) string {
		return date.Local().Format("Jan _2 2006 15:04:05")
	},
	"timeHumanize": func(date time.Time) string {
		return humanize.Time(date)
	},
	"bytesHumanize": func(bytes int64) string {
		return humanize.Bytes(uint64(bytes))
	},
	"json": func(data any) string {
		jsonData, err := json.MarshalIndent(data, "", "  ")
		if err != nil {
			panic(err)
		}

		return string(jsonData)
	},
	"unescape": func(s string) template.HTML {
		return template.HTML(s)
	},
	"query": func(queries map[string]string, vals ...any) template.URL {
		return template.URL(Query(queries, vals...))
	},
	"set": func(c fiber.Map, name string, value any) fiber.Map {
		return fiber.Map{
			"Meta": c["Meta"],
			name:   value,
		}
	},
	"csrf": func(c fiber.Map) template.HTML {
		return template.HTML(fmt.Sprintf(`<input type="hidden" name="csrf" value="%s" />`, c["Meta"].(Meta).CSRF))
	},
}

Functions

func Error

func Error(c *fiber.Ctx, err error, codes ...int) error

func IsHTMXRequest added in v0.12.0

func IsHTMXRequest(c *fiber.Ctx) bool

func NotFound

func NotFound(c *fiber.Ctx) error

func Query

func Query(queries map[string]string, vals ...any) string

func Redirect added in v0.12.0

func Redirect(c *fiber.Ctx, path string) error

func Render added in v0.12.0

func Render(c *fiber.Ctx, name string, data fiber.Map, layouts ...string) error

Types

type Meta added in v0.12.0

type Meta struct {
	Anonymous bool
	CSRF      string
}

Jump to

Keyboard shortcuts

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