mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
It was a git-push error - remove previous' versions configuration https://github.com/kataras/iris/issues/280
This commit is contained in:
parent
b99afb2875
commit
e0ebc84bfe
101
config/logger.go
101
config/logger.go
|
@ -1,101 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/imdario/mergo"
|
|
||||||
)
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultLoggerPrefix is the prefix (expect the [IRIS]), is empty for now
|
|
||||||
const DefaultLoggerPrefix = ""
|
|
||||||
|
|
||||||
var (
|
|
||||||
// TimeFormat default time format for any kind of datetime parsing
|
|
||||||
TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// Logger contains the full configuration options fields for the Logger
|
|
||||||
Logger struct {
|
|
||||||
// Out the (file) writer which the messages/logs will printed to
|
|
||||||
// Default is os.Stdout
|
|
||||||
Out *os.File
|
|
||||||
// Prefix the prefix for each message
|
|
||||||
// Default is ""
|
|
||||||
Prefix string
|
|
||||||
// Disabled default is false
|
|
||||||
Disabled bool
|
|
||||||
|
|
||||||
// foreground colors single SGR Code
|
|
||||||
|
|
||||||
// ColorFgDefault the foreground color for the normal message bodies
|
|
||||||
ColorFgDefault int
|
|
||||||
// ColorFgInfo the foreground color for info messages
|
|
||||||
ColorFgInfo int
|
|
||||||
// ColorFgSuccess the foreground color for success messages
|
|
||||||
ColorFgSuccess int
|
|
||||||
// ColorFgWarning the foreground color for warning messages
|
|
||||||
ColorFgWarning int
|
|
||||||
// ColorFgDanger the foreground color for error messages
|
|
||||||
ColorFgDanger int
|
|
||||||
// OtherFgColor the foreground color for the rest of the message types
|
|
||||||
ColorFgOther int
|
|
||||||
|
|
||||||
// background colors single SGR Code
|
|
||||||
|
|
||||||
// ColorBgDefault the background color for the normal messages
|
|
||||||
ColorBgDefault int
|
|
||||||
// ColorBgInfo the background color for info messages
|
|
||||||
ColorBgInfo int
|
|
||||||
// ColorBgSuccess the background color for success messages
|
|
||||||
ColorBgSuccess int
|
|
||||||
// ColorBgWarning the background color for warning messages
|
|
||||||
ColorBgWarning int
|
|
||||||
// ColorBgDanger the background color for error messages
|
|
||||||
ColorBgDanger int
|
|
||||||
// OtherFgColor the background color for the rest of the message types
|
|
||||||
ColorBgOther int
|
|
||||||
|
|
||||||
// banners are the force printed/written messages, doesn't care about Disabled field
|
|
||||||
|
|
||||||
// ColorFgBanner the foreground color for the banner
|
|
||||||
ColorFgBanner int
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultLogger returns the default configs for the Logger
|
|
||||||
func DefaultLogger() Logger {
|
|
||||||
return Logger{
|
|
||||||
Out: os.Stdout,
|
|
||||||
Prefix: "",
|
|
||||||
Disabled: false,
|
|
||||||
// foreground colors
|
|
||||||
ColorFgDefault: int(color.FgHiWhite),
|
|
||||||
ColorFgInfo: int(color.FgHiCyan),
|
|
||||||
ColorFgSuccess: int(color.FgHiGreen),
|
|
||||||
ColorFgWarning: int(color.FgHiMagenta),
|
|
||||||
ColorFgDanger: int(color.FgHiRed),
|
|
||||||
ColorFgOther: int(color.FgHiYellow),
|
|
||||||
// background colors
|
|
||||||
ColorBgDefault: 0,
|
|
||||||
ColorBgInfo: 0,
|
|
||||||
ColorBgSuccess: 0,
|
|
||||||
ColorBgWarning: 0,
|
|
||||||
ColorBgDanger: 0,
|
|
||||||
ColorBgOther: 0,
|
|
||||||
// banner color
|
|
||||||
ColorFgBanner: int(color.FgHiBlue),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeSingle merges the default with the given config and returns the result
|
|
||||||
func (c Logger) MergeSingle(cfg Logger) (config Logger) {
|
|
||||||
|
|
||||||
config = cfg
|
|
||||||
mergo.Merge(&config, c)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
249
config/render.go
249
config/render.go
|
@ -1,249 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
|
|
||||||
"github.com/flosch/pongo2"
|
|
||||||
"github.com/imdario/mergo"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// NoEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are disabled
|
|
||||||
NoEngine EngineType = -1
|
|
||||||
// HTMLEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are html/template
|
|
||||||
HTMLEngine EngineType = 0
|
|
||||||
// PongoEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are flosch/pongo2
|
|
||||||
PongoEngine EngineType = 1
|
|
||||||
// MarkdownEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are .md files
|
|
||||||
MarkdownEngine EngineType = 2
|
|
||||||
// JadeEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are joker/jade
|
|
||||||
JadeEngine EngineType = 3
|
|
||||||
// AmberEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are eknkc/amber
|
|
||||||
AmberEngine EngineType = 4
|
|
||||||
// HandlebarsEngine is a Template's config for engine type
|
|
||||||
// when use this, the templates are aymerick/raymond
|
|
||||||
HandlebarsEngine EngineType = 5
|
|
||||||
// DefaultEngine is the HTMLEngine
|
|
||||||
DefaultEngine EngineType = HTMLEngine
|
|
||||||
|
|
||||||
// NoLayout to disable layout for a particular template file
|
|
||||||
NoLayout = "@.|.@iris_no_layout@.|.@"
|
|
||||||
// TemplateLayoutContextKey is the name of the user values which can be used to set a template layout from a middleware and override the parent's
|
|
||||||
TemplateLayoutContextKey = "templateLayout"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Charset character encoding.
|
|
||||||
Charset = "UTF-8"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// Rest is a struct for specifying configuration options for the rest.Render object.
|
|
||||||
Rest struct {
|
|
||||||
// Appends the given character set to the Content-Type header. Default is "UTF-8".
|
|
||||||
Charset string
|
|
||||||
// Gzip enable it if you want to render with gzip compression. Default is false
|
|
||||||
Gzip bool
|
|
||||||
// Outputs human readable JSON.
|
|
||||||
IndentJSON bool
|
|
||||||
// Outputs human readable XML. Default is false.
|
|
||||||
IndentXML bool
|
|
||||||
// Prefixes the JSON output with the given bytes. Default is false.
|
|
||||||
PrefixJSON []byte
|
|
||||||
// Prefixes the XML output with the given bytes.
|
|
||||||
PrefixXML []byte
|
|
||||||
// Unescape HTML characters "&<>" to their original values. Default is false.
|
|
||||||
UnEscapeHTML bool
|
|
||||||
// Streams JSON responses instead of marshalling prior to sending. Default is false.
|
|
||||||
StreamingJSON bool
|
|
||||||
// Disables automatic rendering of http.StatusInternalServerError when an error occurs. Default is false.
|
|
||||||
DisableHTTPErrorRendering bool
|
|
||||||
// MarkdownSanitize sanitizes the markdown. Default is false.
|
|
||||||
MarkdownSanitize bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// EngineType is the type of template engine
|
|
||||||
EngineType int8
|
|
||||||
|
|
||||||
// Template the configs for templates (template/view engines)
|
|
||||||
// contains common configs for all template engines
|
|
||||||
Template struct {
|
|
||||||
// Engine the type of template engine
|
|
||||||
// default is DefaultEngine (HTMLEngine)
|
|
||||||
Engine EngineType
|
|
||||||
// Gzip enable gzip compression
|
|
||||||
// default is false
|
|
||||||
Gzip bool
|
|
||||||
// Minify minifies the html result,
|
|
||||||
// Note: according to this https://github.com/tdewolff/minify/issues/35, also it removes some </tags> when minify on writer, remove this from Iris until fix.
|
|
||||||
// Default is false
|
|
||||||
//Minify bool
|
|
||||||
|
|
||||||
// IsDevelopment re-builds the templates on each request
|
|
||||||
// default is false
|
|
||||||
IsDevelopment bool
|
|
||||||
// Directory the system path which the templates live
|
|
||||||
// default is ./templates
|
|
||||||
Directory string
|
|
||||||
// Extensions the allowed file extension
|
|
||||||
// default is []string{".html"}
|
|
||||||
Extensions []string
|
|
||||||
// ContentType is the Content-Type response header
|
|
||||||
// default is text/html but you can change if if needed
|
|
||||||
ContentType string
|
|
||||||
// Charset the charset, default is UTF-8
|
|
||||||
Charset string
|
|
||||||
// Asset is a func which returns bytes, use it to load the templates by binary
|
|
||||||
Asset func(name string) ([]byte, error)
|
|
||||||
// AssetNames should returns the template filenames, look Asset
|
|
||||||
AssetNames func() []string
|
|
||||||
// Layout the template file ( with its extension) which is the mother of all
|
|
||||||
// use it to have it as a root file, and include others with {{ yield }}, refer the docs
|
|
||||||
Layout string
|
|
||||||
|
|
||||||
// HTMLTemplate contains specific configs for HTMLTemplate standard html/template
|
|
||||||
HTMLTemplate HTMLTemplate
|
|
||||||
// Jade contains specific configs for Jade
|
|
||||||
Jade Jade
|
|
||||||
// Pongo contains specific configs for pongo2
|
|
||||||
Pongo Pongo
|
|
||||||
// Markdown contains specific configs for markdown
|
|
||||||
// this doesn't supports Layout & binding context
|
|
||||||
Markdown Markdown
|
|
||||||
// Amber contains specific configs for amber
|
|
||||||
Amber Amber
|
|
||||||
// Handlebars contains specific configs for handlebars
|
|
||||||
Handlebars Handlebars
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTMLTemplate the configs for HTMLEngine
|
|
||||||
HTMLTemplate struct {
|
|
||||||
// RequirePartials default is false
|
|
||||||
RequirePartials bool
|
|
||||||
// Delims
|
|
||||||
// Left delimeter, default is {{
|
|
||||||
Left string
|
|
||||||
// Right delimeter, default is }}
|
|
||||||
Right string
|
|
||||||
// Funcs like html/template
|
|
||||||
Funcs map[string]interface{}
|
|
||||||
// LayoutFuncs like html/template
|
|
||||||
// the difference from Funcs is that these funcs
|
|
||||||
// can be used inside a layout and can override the predefined (yield,partial...) or add more custom funcs
|
|
||||||
// these can override the Funcs inside no-layout templates also, use it when you know what you're doing
|
|
||||||
LayoutFuncs map[string]interface{}
|
|
||||||
}
|
|
||||||
// Jade the configs for JadeEngine
|
|
||||||
Jade HTMLTemplate
|
|
||||||
// Pongo the configs for PongoEngine
|
|
||||||
Pongo struct {
|
|
||||||
// Filters for pongo2, map[name of the filter] the filter function . The filters are auto register
|
|
||||||
Filters map[string]pongo2.FilterFunction
|
|
||||||
// Globals share context fields between templates. https://github.com/flosch/pongo2/issues/35
|
|
||||||
Globals map[string]interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Markdown the configs for MarkdownEngine
|
|
||||||
Markdown struct {
|
|
||||||
Sanitize bool // if true then returns safe html, default is false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Amber the configs for AmberEngine
|
|
||||||
Amber struct {
|
|
||||||
// Funcs for the html/template result, amber default funcs are not overrided so use it without worries
|
|
||||||
Funcs template.FuncMap
|
|
||||||
}
|
|
||||||
// Handlebars the configs for HandlebarsEngine
|
|
||||||
Handlebars struct {
|
|
||||||
// Helpers for Handlebars, you can register your own by raymond.RegisterHelper(name string, a interface{}) or RegisterHelpers(map[string]interface{})
|
|
||||||
// or just fill this method, do not override it it is not nil by default (because of Iris' helpers (url and urlpath)
|
|
||||||
Helpers map[string]interface{}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultRest returns the default config for rest
|
|
||||||
func DefaultRest() Rest {
|
|
||||||
return Rest{
|
|
||||||
Charset: Charset,
|
|
||||||
IndentJSON: false,
|
|
||||||
IndentXML: false,
|
|
||||||
PrefixJSON: []byte(""),
|
|
||||||
PrefixXML: []byte(""),
|
|
||||||
UnEscapeHTML: false,
|
|
||||||
StreamingJSON: false,
|
|
||||||
DisableHTTPErrorRendering: false,
|
|
||||||
MarkdownSanitize: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge merges the default with the given config and returns the result
|
|
||||||
func (c Rest) Merge(cfg []Rest) (config Rest) {
|
|
||||||
|
|
||||||
if len(cfg) > 0 {
|
|
||||||
config = cfg[0]
|
|
||||||
mergo.Merge(&config, c)
|
|
||||||
} else {
|
|
||||||
_default := c
|
|
||||||
config = _default
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeSingle merges the default with the given config and returns the result
|
|
||||||
func (c Rest) MergeSingle(cfg Rest) (config Rest) {
|
|
||||||
|
|
||||||
config = cfg
|
|
||||||
mergo.Merge(&config, c)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultTemplate returns the default template configs
|
|
||||||
func DefaultTemplate() Template {
|
|
||||||
return Template{
|
|
||||||
Engine: DefaultEngine, //or HTMLTemplate
|
|
||||||
Gzip: false,
|
|
||||||
IsDevelopment: false,
|
|
||||||
Directory: "templates",
|
|
||||||
Extensions: []string{".html"},
|
|
||||||
ContentType: "text/html",
|
|
||||||
Charset: "UTF-8",
|
|
||||||
Layout: "", // currently this is the only config which not working for pongo2 yet but I will find a way
|
|
||||||
HTMLTemplate: HTMLTemplate{Left: "{{", Right: "}}", Funcs: make(map[string]interface{}, 0), LayoutFuncs: make(map[string]interface{}, 0)},
|
|
||||||
Jade: Jade{Left: "{{", Right: "}}", Funcs: make(map[string]interface{}, 0), LayoutFuncs: make(map[string]interface{}, 0)},
|
|
||||||
Pongo: Pongo{Filters: make(map[string]pongo2.FilterFunction, 0), Globals: make(map[string]interface{}, 0)},
|
|
||||||
Markdown: Markdown{Sanitize: false},
|
|
||||||
Amber: Amber{Funcs: template.FuncMap{}},
|
|
||||||
Handlebars: Handlebars{Helpers: make(map[string]interface{}, 0)},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge merges the default with the given config and returns the result
|
|
||||||
func (c Template) Merge(cfg []Template) (config Template) {
|
|
||||||
|
|
||||||
if len(cfg) > 0 {
|
|
||||||
config = cfg[0]
|
|
||||||
mergo.Merge(&config, c)
|
|
||||||
} else {
|
|
||||||
_default := c
|
|
||||||
config = _default
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeSingle merges the default with the given config and returns the result
|
|
||||||
func (c Template) MergeSingle(cfg Template) (config Template) {
|
|
||||||
|
|
||||||
config = cfg
|
|
||||||
mergo.Merge(&config, c)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user