render

package
v1.22.12 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 13 Imported by: 32

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFuncMapSkipper = func(c echo.Context) bool {
	return c.Format() != echo.ContentTypeHTML && !c.IsAjax() && !c.IsPjax()
}
View Source
var (
	DefaultOptions = &Options{
		Skipper:              echo.DefaultSkipper,
		ErrorPages:           make(map[int]string),
		DefaultHTTPErrorCode: http.StatusInternalServerError,
		SetFuncMap:           []echo.HandlerFunc{},
		DefaultRenderer:      defaultRender,
		UsingDefaultRenderer: usingDefaultRender,
	}
)

Functions

func Auto added in v1.3.7

func Auto() echo.MiddlewareFunc

func Del

func Del(key string)

func EmptyRouteUsingDefaultRender added in v1.21.6

func EmptyRouteUsingDefaultRender(c echo.Context) bool

EmptyRouteUsingDefaultRender checks if the current route is empty and uses the default renderer.

func ErrorHTMLTemplate added in v1.21.1

func ErrorHTMLTemplate(_ string) ([]byte, error)

func HTTPErrorHandler added in v1.1.0

func HTTPErrorHandler(opt *Options) echo.HTTPErrorHandler

HTTPErrorHandler returns a HTTP error handler that renders error pages based on the provided options.

func Middleware

func Middleware(d echo.Renderer) echo.MiddlewareFunc

Middleware set renderer

func New

func New(key string, tmplDir string, args ...logger.Logger) Driver

func Reg

func Reg(key string, val func(string) Driver)

Types

type Config added in v1.1.0

type Config struct {
	// TmplDir is the directory where templates are stored.
	TmplDir string
	// Theme is the name of the theme to be used for rendering templates.
	Theme string
	// Engine is the name of the template engine to be used for rendering templates.
	Engine string
	// Style is the name of the style to be used for rendering templates.
	Style string
	// Reload indicates whether the templates should be reloaded on each modify.
	Reload bool
	// ParseStrings is a map of strings to be replaced in the template content.
	ParseStrings map[string]string
	// ParseStringFuncs is a map of functions that return strings to be replaced in the template content.
	ParseStringFuncs map[string]func() string
	StaticOptions    *middleware.StaticOptions
	Debug            bool

	FuncMapGlobal map[string]interface{}
	RendererDo    []func(driver.Driver)
	CustomParser  func(tmpl string, content []byte) []byte

	// ErrorPages defines the error pages to be used for specific HTTP error codes.
	ErrorPages map[int]string
	// DefaultHTTPErrorCode is the default HTTP error code to use when no specific error code is provided.
	DefaultHTTPErrorCode int
	// ErrorProcessors defines a list of error processors that can be used to handle errors.
	ErrorProcessors []ErrorProcessor
	// ErrorCodeLinks defines a mapping of error codes to links that can be used to provide additional information about the error.
	ErrorCodeLinks map[code.Code]echo.KVList
	// DefaultRenderer is a function that can be used to render the default response for an error.
	DefaultRenderer func(c echo.Context, data echo.H, code int) ([]byte, error)
	// UsingDefaultRenderer is a function that can be used to determine if the default renderer should be used.
	UsingDefaultRenderer func(echo.Context) bool
	// contains filtered or unexported fields
}

func (*Config) AddFuncSetter added in v1.3.9

func (t *Config) AddFuncSetter(set ...echo.HandlerFunc) *Config

func (*Config) AddRendererDo added in v1.4.3

func (t *Config) AddRendererDo(rd ...func(driver.Driver)) *Config

func (*Config) ApplyTo added in v1.1.1

func (t *Config) ApplyTo(e *echo.Echo, manager ...driver.Manager) *Config

func (*Config) HTTPErrorHandler added in v1.6.0

func (t *Config) HTTPErrorHandler() echo.HTTPErrorHandler

func (*Config) MakeRenderer added in v1.6.0

func (t *Config) MakeRenderer(manager ...driver.Manager) driver.Driver

func (*Config) NewRenderer added in v1.1.1

func (t *Config) NewRenderer(manager ...driver.Manager) driver.Driver

NewRenderer 新建渲染接口

func (*Config) Parser added in v1.1.0

func (t *Config) Parser() func(tmpl string, content []byte) []byte

func (*Config) Renderer added in v1.1.1

func (t *Config) Renderer() driver.Driver

func (*Config) SetFuncSetter added in v1.3.9

func (t *Config) SetFuncSetter(set ...echo.HandlerFunc) *Config

func (*Config) SetRendererDo added in v1.4.3

func (t *Config) SetRendererDo(rd ...func(driver.Driver)) *Config

func (*Config) StaticMiddleware added in v1.6.0

func (t *Config) StaticMiddleware() interface{}

func (*Config) ThemeDir added in v1.1.1

func (t *Config) ThemeDir(args ...string) string

ThemeDir 主题所在文件夹的路径

type ErrorProcessor added in v1.6.0

type ErrorProcessor func(ctx echo.Context, err error) (processed bool, newErr error)

type Options added in v1.1.1

type Options struct {
	Skipper              echo.Skipper
	ErrorPages           map[int]string
	ErrorProcessors      []ErrorProcessor
	ErrorCodeLinks       map[code.Code]echo.KVList
	DefaultHTTPErrorCode int
	SetFuncMap           []echo.HandlerFunc
	DefaultRenderer      func(c echo.Context, data echo.H, code int) ([]byte, error)
	UsingDefaultRenderer func(echo.Context) bool
}

func (*Options) AddErrorProcessor added in v1.6.0

func (opt *Options) AddErrorProcessor(h ...ErrorProcessor) *Options

func (*Options) AddFuncSetter added in v1.3.9

func (opt *Options) AddFuncSetter(set ...echo.HandlerFunc) *Options

func (*Options) GenTmplGetter added in v1.21.2

func (opt *Options) GenTmplGetter() func(code int) string

func (*Options) SetDefaultRender added in v1.21.3

func (opt *Options) SetDefaultRender(renderer func(c echo.Context, data echo.H, code int) ([]byte, error)) *Options

func (*Options) SetErrorProcessor added in v1.6.0

func (opt *Options) SetErrorProcessor(h ...ErrorProcessor) *Options

func (*Options) SetFuncSetter added in v1.3.9

func (opt *Options) SetFuncSetter(set ...echo.HandlerFunc) *Options

Directories

Path Synopsis
jet
test command
sse
test command
*
test command

Jump to

Keyboard shortcuts

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