Documentation
¶
Index ¶
- Constants
- Variables
- func App(wa WebApp, systemId string, conf configuration.Configuration)
- func LoggerWithConfig(systemId string, enableLog bool, config LoggerConfig) echo.MiddlewareFunc
- func NewWebAppTemplate(opt RenderOptions, tplSets ...string) *webAppTemplate
- func OptApp(wa WebApp, systemId string, conf configuration.Configuration) *web
- func PrepareCharset(charset string) string
- func RegisterValidation(key string, fn validator.Func) error
- func Trace() echo.MiddlewareFunc
- type Config
- type Delims
- type HTMLOptions
- type LoggerConfig
- type RenderOptions
- type ResponseWriter
- type TemplateFile
- type TemplateFileSystem
- type TemplateSet
- type TplFile
- type TplFileSystem
- type TplRender
- func (r *TplRender) HTML(status int, name string, data interface{}, htmlOpt ...HTMLOptions)
- func (r *TplRender) HTMLSet(status int, setName, tplName string, data interface{}, htmlOpt ...HTMLOptions)
- func (r *TplRender) HTMLSetBytes(setName, tplName string, data interface{}, htmlOpt ...HTMLOptions) ([]byte, error)
- type WebApp
Constants ¶
const DefaultTplSetName = "DEFAULT"
Variables ¶
var ( // DefaultLoggerConfig is the default Logger middleware config. DefaultLoggerConfig = LoggerConfig{ Skipper: middleware.DefaultSkipper, Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` + `"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` + `"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` + `,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n", CustomTimeFormat: "2006-01-02 15:04:05.00000", // contains filtered or unexported fields } )
var SwagHandler echo.HandlerFunc
var (
TemplateEnv = "development"
)
Functions ¶
func App ¶
func App(wa WebApp, systemId string, conf configuration.Configuration)
func LoggerWithConfig ¶
func LoggerWithConfig(systemId string, enableLog bool, config LoggerConfig) echo.MiddlewareFunc
LoggerWithConfig returns a Logger middleware with config. See: `Logger()`.
func NewWebAppTemplate ¶
func NewWebAppTemplate(opt RenderOptions, tplSets ...string) *webAppTemplate
func OptApp ¶
func OptApp(wa WebApp, systemId string, conf configuration.Configuration) *web
func PrepareCharset ¶
func RegisterValidation ¶
RegisterValidation 将验证功能添加到由键表示的验证者的验证者映射中 注意:如果密钥已经存在,则先前的验证功能将被替换。 注意:此方法不是线程安全的,因此应在进行任何验证之前先将它们全部注册
Types ¶
type HTMLOptions ¶
type HTMLOptions struct {
Layout string // 布局模板名称.覆盖Options.Layout.
}
HTMLOptions是用于覆盖特定HTML调用的某些呈现选项的结构
type LoggerConfig ¶
type LoggerConfig struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// Tags to construct the logger format.
//
// - time_unix
// - time_unix_nano
// - time_rfc3339
// - time_rfc3339_nano
// - time_custom
// - id (Request ID)
// - remote_ip
// - uri
// - host
// - method
// - path
// - protocol
// - referer
// - user_agent
// - status
// - error
// - latency (In nanoseconds)
// - latency_human (Human readable)
// - bytes_in (Bytes received)
// - bytes_out (Bytes sent)
// - header:<NAME>
// - query:<NAME>
// - form:<NAME>
//
// Example "${remote_ip} ${status}"
//
// Optional. Default value DefaultLoggerConfig.Format.
Format string `yaml:"format"`
// Optional. Default value DefaultLoggerConfig.CustomTimeFormat.
CustomTimeFormat string `yaml:"custom_time_format"`
// Output is a writer where logs in JSON format are written.
// Optional. Default value os.Stdout.
Output io.Writer
// contains filtered or unexported fields
}
LoggerConfig defines the config for Logger middleware.
type RenderOptions ¶
type RenderOptions struct {
Directory string // 加载模板目标.默认为"templates".
AppendDirectories []string // 附加目录会覆盖默认模板.
Layout string // 布局模板名称. 如果为""代表不会渲染布局.默认是"".
Extensions []string // 用于从中解析模板文件的扩展. 默认值为[".tmpl", ".html"].
Funcs []template.FuncMap // Funcs是FuncMap的一部分,可在编译时应用于模板. 这对于助手功能很有用. 默认是[].
Delims Delims // 将定界符设置为Delims结构中的指定字符串.
Charset string // 将给定的字符集附加到Content-Type标头.默认是"UTF-8".
HTMLContentType string // 允许将输出更改为XHTML而不是HTML.默认是"text/html".
TemplateFileSystem // TemplateFileSystem是用于支持任何模板文件系统实现的接口.
}
RenderOptions 表示用于指定Render中间件的配置选项的结构。.
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Flusher
// Status returns the status code of the response or 0 if the response has
// not been written
Status() int
// Written returns whether or not the ResponseWriter has been written.
Written() bool
// Size returns the size of the response body.
Size() int
// Before allows for a function to be called before the ResponseWriter has been written to. This is
// useful for setting headers or any other operations that must happen before a response has been written.
Before(func(ResponseWriter))
}
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a response writer if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type TemplateFile ¶
表示具有名称且可以读取的模板文件的接口.
type TemplateFileSystem ¶
type TemplateFileSystem interface {
ListFiles() []TemplateFile
Get(string) (io.Reader, error)
}
表示能够列出所有文件的模板文件系统的接口.
type TemplateSet ¶
type TemplateSet struct {
// contains filtered or unexported fields
}
表示类型为*template.Template的模板集。
func (*TemplateSet) GetDir ¶
func (ts *TemplateSet) GetDir(name string) string
func (*TemplateSet) Set ¶
func (ts *TemplateSet) Set(name string, opt *RenderOptions) *template.Template
type TplFileSystem ¶
type TplFileSystem struct {
// contains filtered or unexported fields
}
实现TemplateFileSystem接口.
func NewTemplateFileSystem ¶
func NewTemplateFileSystem(opt RenderOptions, omitData bool) TplFileSystem
使用给定的选项创建新的模板文件系统.
func (TplFileSystem) ListFiles ¶
func (fs TplFileSystem) ListFiles() []TemplateFile
type TplRender ¶
type TplRender struct {
http.ResponseWriter
*TemplateSet
Opt *RenderOptions
Charset string
// contains filtered or unexported fields
}
func (*TplRender) HTML ¶
func (r *TplRender) HTML(status int, name string, data interface{}, htmlOpt ...HTMLOptions)
func (*TplRender) HTMLSet ¶
func (r *TplRender) HTMLSet(status int, setName, tplName string, data interface{}, htmlOpt ...HTMLOptions)
func (*TplRender) HTMLSetBytes ¶
func (r *TplRender) HTMLSetBytes(setName, tplName string, data interface{}, htmlOpt ...HTMLOptions) ([]byte, error)