mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Nothing special: Linting
This commit is contained in:
parent
679b707751
commit
a337b4768d
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultBasicAuth is "Authorization Required"
|
// DefaultBasicAuthRealm is "Authorization Required"
|
||||||
DefaultBasicAuthRealm = "Authorization Required"
|
DefaultBasicAuthRealm = "Authorization Required"
|
||||||
// DefaultBasicAuthContextKey is the "auth"
|
// DefaultBasicAuthContextKey is the "auth"
|
||||||
// this key is used to do context.Set("auth", theUsernameFromBasicAuth)
|
// this key is used to do context.Set("auth", theUsernameFromBasicAuth)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import "github.com/imdario/mergo"
|
import "github.com/imdario/mergo"
|
||||||
|
|
||||||
|
// Editor the configs for the Editor plugin
|
||||||
type Editor struct {
|
type Editor struct {
|
||||||
// Host if empty used the iris server's host
|
// Host if empty used the iris server's host
|
||||||
Host string
|
Host string
|
||||||
|
@ -34,7 +35,7 @@ func (c Editor) Merge(cfg []Editor) (config Editor) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge MergeSingle the default with the given config and returns the result
|
// MergeSingle merges the default with the given config and returns the result
|
||||||
func (c Editor) MergeSingle(cfg Editor) (config Editor) {
|
func (c Editor) MergeSingle(cfg Editor) (config Editor) {
|
||||||
|
|
||||||
config = cfg
|
config = cfg
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultProfilePath is the default profile(http debug) path which is /debug/pprof
|
||||||
const DefaultProfilePath = "/debug/pprof"
|
const DefaultProfilePath = "/debug/pprof"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -145,7 +146,7 @@ func (c Iris) Merge(cfg []Iris) (config Iris) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge MergeSingle the default with the given config and returns the result
|
// MergeSingle merges the default with the given config and returns the result
|
||||||
func (c Iris) MergeSingle(cfg Iris) (config Iris) {
|
func (c Iris) MergeSingle(cfg Iris) (config Iris) {
|
||||||
|
|
||||||
config = cfg
|
config = cfg
|
||||||
|
|
|
@ -13,6 +13,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Logger contains the configs for the Logger
|
||||||
Logger struct {
|
Logger struct {
|
||||||
Out io.Writer
|
Out io.Writer
|
||||||
Prefix string
|
Prefix string
|
||||||
|
@ -20,6 +21,7 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultLogger returns the default configs for the Logger
|
||||||
func DefaultLogger() Logger {
|
func DefaultLogger() Logger {
|
||||||
return Logger{Out: os.Stdout, Prefix: "", Flag: 0}
|
return Logger{Out: os.Stdout, Prefix: "", Flag: 0}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ var (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultCookieName the secret cookie's name for sessions
|
// DefaultCookieName the secret cookie's name for sessions
|
||||||
DefaultCookieName = "irissessionid"
|
DefaultCookieName = "irissessionid"
|
||||||
|
// DefaultSessionGcDuration is the default Session Manager's GCDuration , which is 2 hours
|
||||||
DefaultSessionGcDuration = time.Duration(2) * time.Hour
|
DefaultSessionGcDuration = time.Duration(2) * time.Hour
|
||||||
// DefaultRedisNetwork the redis network option, "tcp"
|
// DefaultRedisNetwork the redis network option, "tcp"
|
||||||
DefaultRedisNetwork = "tcp"
|
DefaultRedisNetwork = "tcp"
|
||||||
|
@ -97,7 +98,7 @@ func (c Sessions) Merge(cfg []Sessions) (config Sessions) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge MergeSingle the default with the given config and returns the result
|
// MergeSingle merges the default with the given config and returns the result
|
||||||
func (c Sessions) MergeSingle(cfg Sessions) (config Sessions) {
|
func (c Sessions) MergeSingle(cfg Sessions) (config Sessions) {
|
||||||
|
|
||||||
config = cfg
|
config = cfg
|
||||||
|
@ -135,7 +136,7 @@ func (c Redis) Merge(cfg []Redis) (config Redis) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge MergeSingle the default with the given config and returns the result
|
// MergeSingle merges the default with the given config and returns the result
|
||||||
func (c Redis) MergeSingle(cfg Redis) (config Redis) {
|
func (c Redis) MergeSingle(cfg Redis) (config Redis) {
|
||||||
|
|
||||||
config = cfg
|
config = cfg
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (ctx *Context) Render(name string, binding interface{}, layout ...string) e
|
||||||
return ctx.HTML(StatusOK, name, binding, layout...)
|
return ctx.HTML(StatusOK, name, binding, layout...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderStrings accepts a template filename, its context data and returns the result of the parsed template (string)
|
// RenderString accepts a template filename, its context data and returns the result of the parsed template (string)
|
||||||
func (ctx *Context) RenderString(name string, binding interface{}, layout ...string) (result string, err error) {
|
func (ctx *Context) RenderString(name string, binding interface{}, layout ...string) (result string, err error) {
|
||||||
return ctx.station.templates.RenderString(name, binding, layout...)
|
return ctx.station.templates.RenderString(name, binding, layout...)
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func (ctx *Context) ExecuteTemplate(tmpl *template.Template, pageContext interfa
|
||||||
// receives three parameters, it's low-level function, instead you can use .ServeFile(string)
|
// receives three parameters, it's low-level function, instead you can use .ServeFile(string)
|
||||||
//
|
//
|
||||||
// You can define your own "Content-Type" header also, after this function call
|
// You can define your own "Content-Type" header also, after this function call
|
||||||
func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) (err error) {
|
func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) error {
|
||||||
if t, err := time.Parse(TimeFormat, ctx.RequestHeader(IfModifiedSince)); err == nil && modtime.Before(t.Add(1*time.Second)) {
|
if t, err := time.Parse(TimeFormat, ctx.RequestHeader(IfModifiedSince)); err == nil && modtime.Before(t.Add(1*time.Second)) {
|
||||||
ctx.RequestCtx.Response.Header.Del(ContentType)
|
ctx.RequestCtx.Response.Header.Del(ContentType)
|
||||||
ctx.RequestCtx.Response.Header.Del(ContentLength)
|
ctx.RequestCtx.Response.Header.Del(ContentLength)
|
||||||
|
@ -119,7 +119,7 @@ func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime
|
||||||
out = ctx.RequestCtx.Response.BodyWriter()
|
out = ctx.RequestCtx.Response.BodyWriter()
|
||||||
|
|
||||||
}
|
}
|
||||||
_, err = io.Copy(out, content)
|
_, err := io.Copy(out, content)
|
||||||
return ErrServeContent.With(err)
|
return ErrServeContent.With(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
iris.go
6
iris.go
|
@ -59,8 +59,8 @@ var (
|
||||||
DefaultEngine = config.DefaultEngine
|
DefaultEngine = config.DefaultEngine
|
||||||
// NoEngine conversion for config.NoEngine
|
// NoEngine conversion for config.NoEngine
|
||||||
NoEngine = config.NoEngine
|
NoEngine = config.NoEngine
|
||||||
//
|
// NoLayout to disable layout for a particular template file
|
||||||
|
// conversion for config.NoLayout
|
||||||
NoLayout = config.NoLayout
|
NoLayout = config.NoLayout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ func (s *Iris) printBanner() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var i uint64 = 0
|
var i uint64
|
||||||
|
|
||||||
printTicker.OnTick(func() {
|
printTicker.OnTick(func() {
|
||||||
if len(banner) <= int(atomic.LoadUint64(&i)) {
|
if len(banner) <= int(atomic.LoadUint64(&i)) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultIris in order to use iris.Get(...,...) we need a default Iris on the package level
|
// DefaultIris in order to use iris.Get(...,...) we need a default Iris on the package level
|
||||||
var DefaultIris *Iris = New()
|
var DefaultIris = New()
|
||||||
|
|
||||||
// Listen starts the standalone http server
|
// Listen starts the standalone http server
|
||||||
// which listens to the addr parameter which as the form of
|
// which listens to the addr parameter which as the form of
|
||||||
|
|
9
party.go
9
party.go
|
@ -179,7 +179,8 @@ func (p *GardenParty) API(path string, controller HandlerAPI, middlewares ...Han
|
||||||
}
|
}
|
||||||
|
|
||||||
func(path string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, method string) {
|
func(path string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, method string) {
|
||||||
handlersFn := make([]HandlerFunc, 0)
|
var handlersFn []HandlerFunc
|
||||||
|
|
||||||
handlersFn = append(handlersFn, middlewares...)
|
handlersFn = append(handlersFn, middlewares...)
|
||||||
handlersFn = append(handlersFn, func(ctx *Context) {
|
handlersFn = append(handlersFn, func(ctx *Context) {
|
||||||
newController := reflect.New(typ).Elem()
|
newController := reflect.New(typ).Elem()
|
||||||
|
@ -223,7 +224,8 @@ func (p *GardenParty) API(path string, controller HandlerAPI, middlewares ...Han
|
||||||
}
|
}
|
||||||
|
|
||||||
func(registedPath string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, paramsLen int, method string) {
|
func(registedPath string, typ reflect.Type, contextField reflect.StructField, methodFunc reflect.Value, paramsLen int, method string) {
|
||||||
handlersFn := make([]HandlerFunc, 0)
|
var handlersFn []HandlerFunc
|
||||||
|
|
||||||
handlersFn = append(handlersFn, middlewares...)
|
handlersFn = append(handlersFn, middlewares...)
|
||||||
handlersFn = append(handlersFn, func(ctx *Context) {
|
handlersFn = append(handlersFn, func(ctx *Context) {
|
||||||
newController := reflect.New(typ).Elem()
|
newController := reflect.New(typ).Elem()
|
||||||
|
@ -407,7 +409,7 @@ func (p *GardenParty) StaticHandlerFunc(systemPath string, stripSlashes int, com
|
||||||
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
||||||
func (p *GardenParty) Static(relative string, systemPath string, stripSlashes int) {
|
func (p *GardenParty) Static(relative string, systemPath string, stripSlashes int) {
|
||||||
if relative[len(relative)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath
|
if relative[len(relative)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath
|
||||||
relative += "/"
|
relative += Slash
|
||||||
}
|
}
|
||||||
|
|
||||||
h := p.StaticHandlerFunc(systemPath, stripSlashes, false, false, nil)
|
h := p.StaticHandlerFunc(systemPath, stripSlashes, false, false, nil)
|
||||||
|
@ -447,7 +449,6 @@ func (p *GardenParty) StaticFS(reqPath string, systemPath string, stripSlashes i
|
||||||
// * stripSlashes = 1, original path: "/foo/bar", result: "/bar"
|
// * stripSlashes = 1, original path: "/foo/bar", result: "/bar"
|
||||||
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
||||||
// * if you don't know what to put on stripSlashes just 1
|
// * if you don't know what to put on stripSlashes just 1
|
||||||
|
|
||||||
func (p *GardenParty) StaticWeb(reqPath string, systemPath string, stripSlashes int) {
|
func (p *GardenParty) StaticWeb(reqPath string, systemPath string, stripSlashes int) {
|
||||||
if reqPath[len(reqPath)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath
|
if reqPath[len(reqPath)-1] != SlashByte { // if / then /*filepath, if /something then /something/*filepath
|
||||||
reqPath += "/"
|
reqPath += "/"
|
||||||
|
|
27
plugin.go
27
plugin.go
|
@ -45,6 +45,7 @@ type (
|
||||||
// parameter is the Route
|
// parameter is the Route
|
||||||
PreHandle(IRoute)
|
PreHandle(IRoute)
|
||||||
}
|
}
|
||||||
|
// PreHandleFunc implements the simple function listener for the PreHandle(IRoute)
|
||||||
PreHandleFunc func(IRoute)
|
PreHandleFunc func(IRoute)
|
||||||
// IPluginPostHandle implements the PostHandle(IRoute) method
|
// IPluginPostHandle implements the PostHandle(IRoute) method
|
||||||
IPluginPostHandle interface {
|
IPluginPostHandle interface {
|
||||||
|
@ -53,6 +54,7 @@ type (
|
||||||
// parameter is the Route
|
// parameter is the Route
|
||||||
PostHandle(IRoute)
|
PostHandle(IRoute)
|
||||||
}
|
}
|
||||||
|
// PostHandleFunc implements the simple function listener for the PostHandle(IRoute)
|
||||||
PostHandleFunc func(IRoute)
|
PostHandleFunc func(IRoute)
|
||||||
// IPluginPreListen implements the PreListen(*Iris) method
|
// IPluginPreListen implements the PreListen(*Iris) method
|
||||||
IPluginPreListen interface {
|
IPluginPreListen interface {
|
||||||
|
@ -61,6 +63,7 @@ type (
|
||||||
// parameter is the station
|
// parameter is the station
|
||||||
PreListen(*Iris)
|
PreListen(*Iris)
|
||||||
}
|
}
|
||||||
|
// PreListenFunc implements the simple function listener for the PreListen(*Iris)
|
||||||
PreListenFunc func(*Iris)
|
PreListenFunc func(*Iris)
|
||||||
// IPluginPostListen implements the PostListen(*Iris) method
|
// IPluginPostListen implements the PostListen(*Iris) method
|
||||||
IPluginPostListen interface {
|
IPluginPostListen interface {
|
||||||
|
@ -68,6 +71,7 @@ type (
|
||||||
// parameter is the station
|
// parameter is the station
|
||||||
PostListen(*Iris)
|
PostListen(*Iris)
|
||||||
}
|
}
|
||||||
|
// PostListenFunc implements the simple function listener for the PostListen(*Iris)
|
||||||
PostListenFunc func(*Iris)
|
PostListenFunc func(*Iris)
|
||||||
// IPluginPreClose implements the PreClose(*Iris) method
|
// IPluginPreClose implements the PreClose(*Iris) method
|
||||||
IPluginPreClose interface {
|
IPluginPreClose interface {
|
||||||
|
@ -77,6 +81,7 @@ type (
|
||||||
// The plugin is deactivated after this state
|
// The plugin is deactivated after this state
|
||||||
PreClose(*Iris)
|
PreClose(*Iris)
|
||||||
}
|
}
|
||||||
|
// PreCloseFunc implements the simple function listener for the PreClose(*Iris)
|
||||||
PreCloseFunc func(*Iris)
|
PreCloseFunc func(*Iris)
|
||||||
|
|
||||||
// IPluginPreDownload It's for the future, not being used, I need to create
|
// IPluginPreDownload It's for the future, not being used, I need to create
|
||||||
|
@ -91,6 +96,8 @@ type (
|
||||||
// must return a boolean, if false then the plugin is not permmited to download this file
|
// must return a boolean, if false then the plugin is not permmited to download this file
|
||||||
PreDownload(plugin IPlugin, downloadURL string) // bool
|
PreDownload(plugin IPlugin, downloadURL string) // bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreDownloadFunc implements the simple function listener for the PreDownload(IPlugin,string)
|
||||||
PreDownloadFunc func(IPlugin, string)
|
PreDownloadFunc func(IPlugin, string)
|
||||||
|
|
||||||
// IPluginContainer is the interface which the PluginContainer should implements
|
// IPluginContainer is the interface which the PluginContainer should implements
|
||||||
|
@ -137,26 +144,46 @@ type (
|
||||||
|
|
||||||
// convert the functions to IPlugin
|
// convert the functions to IPlugin
|
||||||
|
|
||||||
|
// PreHandle it's being called every time BEFORE a Route is registed to the Router
|
||||||
|
//
|
||||||
|
// parameter is the Route
|
||||||
func (fn PreHandleFunc) PreHandle(route IRoute) {
|
func (fn PreHandleFunc) PreHandle(route IRoute) {
|
||||||
fn(route)
|
fn(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostHandle it's being called every time AFTER a Route successfully registed to the Router
|
||||||
|
//
|
||||||
|
// parameter is the Route
|
||||||
func (fn PostHandleFunc) PostHandle(route IRoute) {
|
func (fn PostHandleFunc) PostHandle(route IRoute) {
|
||||||
fn(route)
|
fn(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreListen it's being called only one time, BEFORE the Server is started (if .Listen called)
|
||||||
|
// is used to do work at the time all other things are ready to go
|
||||||
|
// parameter is the station
|
||||||
func (fn PreListenFunc) PreListen(station *Iris) {
|
func (fn PreListenFunc) PreListen(station *Iris) {
|
||||||
fn(station)
|
fn(station)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostListen it's being called only one time, AFTER the Server is started (if .Listen called)
|
||||||
|
// parameter is the station
|
||||||
func (fn PostListenFunc) PostListen(station *Iris) {
|
func (fn PostListenFunc) PostListen(station *Iris) {
|
||||||
fn(station)
|
fn(station)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreClose it's being called only one time, BEFORE the Iris .Close method
|
||||||
|
// any plugin cleanup/clear memory happens here
|
||||||
|
//
|
||||||
|
// The plugin is deactivated after this state
|
||||||
func (fn PreCloseFunc) PreClose(station *Iris) {
|
func (fn PreCloseFunc) PreClose(station *Iris) {
|
||||||
fn(station)
|
fn(station)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreDownload it's being called every time a plugin tries to download something
|
||||||
|
//
|
||||||
|
// first parameter is the plugin
|
||||||
|
// second parameter is the download url
|
||||||
|
// must return a boolean, if false then the plugin is not permmited to download this file
|
||||||
func (fn PreDownloadFunc) PreDownload(pl IPlugin, downloadURL string) {
|
func (fn PreDownloadFunc) PreDownload(pl IPlugin, downloadURL string) {
|
||||||
fn(pl, downloadURL)
|
fn(pl, downloadURL)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,19 @@ import (
|
||||||
"github.com/kataras/iris/config"
|
"github.com/kataras/iris/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Engine the amber template engine
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
Config *config.Template
|
Config *config.Template
|
||||||
templateCache map[string]*template.Template
|
templateCache map[string]*template.Template
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates and returns a new amber engine
|
||||||
func New(cfg config.Template) *Engine {
|
func New(cfg config.Template) *Engine {
|
||||||
return &Engine{Config: &cfg}
|
return &Engine{Config: &cfg}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildTemplates builds the amber templates
|
||||||
func (e *Engine) BuildTemplates() error {
|
func (e *Engine) BuildTemplates() error {
|
||||||
opt := amber.DirOptions{}
|
opt := amber.DirOptions{}
|
||||||
opt.Recursive = true
|
opt.Recursive = true
|
||||||
|
@ -67,6 +70,7 @@ func (e *Engine) fromCache(relativeName string) *template.Template {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecuteWriter executes a templates and write its results to the out writer
|
||||||
func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
||||||
if tmpl := e.fromCache(name); tmpl != nil {
|
if tmpl := e.fromCache(name); tmpl != nil {
|
||||||
return tmpl.ExecuteTemplate(out, name, binding)
|
return tmpl.ExecuteTemplate(out, name, binding)
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Engine the html/template engine
|
||||||
Engine struct {
|
Engine struct {
|
||||||
Config *config.Template
|
Config *config.Template
|
||||||
Templates *template.Template
|
Templates *template.Template
|
||||||
|
|
|
@ -11,7 +11,7 @@ type Engine struct {
|
||||||
*html.Engine
|
*html.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
// new creates and returns a new JadeEngine with its configs
|
// New creates and returns a new JadeEngine with its configs
|
||||||
func New(cfg config.Template) *Engine {
|
func New(cfg config.Template) *Engine {
|
||||||
|
|
||||||
underline := &Engine{Engine: html.New(cfg)}
|
underline := &Engine{Engine: html.New(cfg)}
|
||||||
|
|
|
@ -16,7 +16,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Supports RAW markdown only, no context binding or layout, to use dynamic markdown with other template engine use the context.Markdown/MarkdownString
|
// Supports RAW markdown only, no context binding or layout, to use dynamic markdown with other template engine use the context.Markdown/MarkdownString
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Engine the jade engine
|
||||||
Engine struct {
|
Engine struct {
|
||||||
Config *config.Template
|
Config *config.Template
|
||||||
templateCache map[string][]byte
|
templateCache map[string][]byte
|
||||||
|
@ -29,6 +31,7 @@ func New(c config.Template) *Engine {
|
||||||
return &Engine{Config: &c, templateCache: make(map[string][]byte)}
|
return &Engine{Config: &c, templateCache: make(map[string][]byte)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildTemplates builds the templates
|
||||||
func (e *Engine) BuildTemplates() error {
|
func (e *Engine) BuildTemplates() error {
|
||||||
if e.Config.Asset == nil || e.Config.AssetNames == nil {
|
if e.Config.Asset == nil || e.Config.AssetNames == nil {
|
||||||
return e.buildFromDir()
|
return e.buildFromDir()
|
||||||
|
@ -140,7 +143,8 @@ func (e *Engine) fromCache(relativeName string) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// layout here is unnesecery
|
// ExecuteWriter executes a templates and write its results to the out writer
|
||||||
|
// layout here is useless
|
||||||
func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
||||||
if tmpl := e.fromCache(name); tmpl != nil {
|
if tmpl := e.fromCache(name); tmpl != nil {
|
||||||
_, err := out.Write(tmpl)
|
_, err := out.Write(tmpl)
|
||||||
|
|
6
route.go
6
route.go
|
@ -24,7 +24,7 @@ type (
|
||||||
//
|
//
|
||||||
|
|
||||||
// used to check arguments with the route's named parameters and return the correct url
|
// used to check arguments with the route's named parameters and return the correct url
|
||||||
// second parameter is false when the action cannot be done
|
// second return value is false when the action cannot be done
|
||||||
Parse(...interface{}) (string, bool)
|
Parse(...interface{}) (string, bool)
|
||||||
|
|
||||||
// GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic)
|
// GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic)
|
||||||
|
@ -169,6 +169,8 @@ func (r *Route) setHost(s string) {
|
||||||
r.host = s
|
r.host = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse used to check arguments with the route's named parameters and return the correct url
|
||||||
|
// second return value is false when the action cannot be done
|
||||||
func (r *Route) Parse(args ...interface{}) (string, bool) {
|
func (r *Route) Parse(args ...interface{}) (string, bool) {
|
||||||
// check if arguments are not equal to the named parameters ( : = 1, * = all named parameters split to / ), if this happens then send not found err
|
// check if arguments are not equal to the named parameters ( : = 1, * = all named parameters split to / ), if this happens then send not found err
|
||||||
///TODO: I'm thinking of making an option to disable these checks and just return a result, because they have cost when rendering an html/template, not too big compared to the render action but... we will see
|
///TODO: I'm thinking of making an option to disable these checks and just return a result, because they have cost when rendering an html/template, not too big compared to the render action but... we will see
|
||||||
|
@ -210,6 +212,8 @@ func (r *Route) Parse(args ...interface{}) (string, bool) {
|
||||||
return fmt.Sprintf(r.formattedPath, args...), true
|
return fmt.Sprintf(r.formattedPath, args...), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic)
|
||||||
|
// instead of Parse it just returns an empty string if path parse is failed
|
||||||
func (r *Route) GetURI(args ...interface{}) (uri string) {
|
func (r *Route) GetURI(args ...interface{}) (uri string) {
|
||||||
scheme := "http://"
|
scheme := "http://"
|
||||||
if r.isTLS {
|
if r.isTLS {
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (r *router) optimize() {
|
||||||
func (r *router) optimizeLookups() {
|
func (r *router) optimizeLookups() {
|
||||||
// set the isTLS on all routes and the listening full host
|
// set the isTLS on all routes and the listening full host
|
||||||
listeningHost := r.station.server.Listener().Addr().String()
|
listeningHost := r.station.server.Listener().Addr().String()
|
||||||
for idx, _ := range r.lookups {
|
for idx := range r.lookups {
|
||||||
theR := r.lookups[idx]
|
theR := r.lookups[idx]
|
||||||
theR.setTLS(r.station.server.IsSecure())
|
theR.setTLS(r.station.server.IsSecure())
|
||||||
if theR.GetDomain() == "" { // means local, no subdomain
|
if theR.GetDomain() == "" { // means local, no subdomain
|
||||||
|
|
|
@ -13,6 +13,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Provider is the redis provider
|
||||||
Provider = sessions.NewProvider("redis")
|
Provider = sessions.NewProvider("redis")
|
||||||
// redis is the default redis service, you can set configs via this object
|
// redis is the default redis service, you can set configs via this object
|
||||||
redis = service.New()
|
redis = service.New()
|
||||||
|
|
|
@ -215,7 +215,7 @@ func dial(network string, addr string, pass string) (redis.Conn, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if pass != "" {
|
if pass != "" {
|
||||||
if _, err := c.Do("AUTH", pass); err != nil {
|
if _, err = c.Do("AUTH", pass); err != nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ func (r *Service) Connect() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := red.Do("SELECT", c.Database); err != nil {
|
if _, err = red.Do("SELECT", c.Database); err != nil {
|
||||||
red.Close()
|
red.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
2
tree.go
2
tree.go
|
@ -132,7 +132,7 @@ func (_tree *tree) serve(reqCtx *fasthttp.RequestCtx, path string) bool {
|
||||||
// response because older user agents may not understand 301/307.
|
// response because older user agents may not understand 301/307.
|
||||||
// Shouldn't send the response for POST or HEAD; that leaves GET.
|
// Shouldn't send the response for POST or HEAD; that leaves GET.
|
||||||
if _tree.method == MethodGet {
|
if _tree.method == MethodGet {
|
||||||
note := "<a href=\"" + utils.HtmlEscape(urlToRedirect) + "\">Moved Permanently</a>.\n"
|
note := "<a href=\"" + utils.HTMLEscape(urlToRedirect) + "\">Moved Permanently</a>.\n"
|
||||||
ctx.Write(note)
|
ctx.Write(note)
|
||||||
}
|
}
|
||||||
_tree.pool.Put(ctx)
|
_tree.pool.Put(ctx)
|
||||||
|
|
|
@ -22,8 +22,8 @@ var htmlReplacer = strings.NewReplacer(
|
||||||
"'", "'",
|
"'", "'",
|
||||||
)
|
)
|
||||||
|
|
||||||
// HtmlEscape returns a string which has no valid html code
|
// HTMLEscape returns a string which has no valid html code
|
||||||
func HtmlEscape(s string) string {
|
func HTMLEscape(s string) string {
|
||||||
return htmlReplacer.Replace(s)
|
return htmlReplacer.Replace(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user