mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Nothing special(2): remaining linting
This commit is contained in:
parent
a337b4768d
commit
a3f3e7ebd2
|
@ -146,7 +146,7 @@ func (ctx *Context) Session() store.IStore {
|
||||||
return ctx.sessionStore
|
return ctx.sessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionDestroy destroys the whole session, calls the provider's destory and remove the cookie
|
// SessionDestroy destroys the whole session, calls the provider's destroy and remove the cookie
|
||||||
func (ctx *Context) SessionDestroy() {
|
func (ctx *Context) SessionDestroy() {
|
||||||
if ctx.station.sessionManager != nil {
|
if ctx.station.sessionManager != nil {
|
||||||
if store := ctx.Session(); store != nil {
|
if store := ctx.Session(); store != nil {
|
||||||
|
|
|
@ -228,7 +228,7 @@ func (c *Cors) Conflicts() string {
|
||||||
|
|
||||||
// Serve serves the middleware
|
// Serve serves the middleware
|
||||||
func (c *Cors) Serve(ctx *iris.Context) {
|
func (c *Cors) Serve(ctx *iris.Context) {
|
||||||
if ctx.MethodString() == "OPTIONS" {
|
if ctx.MethodString() == iris.MethodOptions {
|
||||||
c.logf("Serve: Preflight request")
|
c.logf("Serve: Preflight request")
|
||||||
c.handlePreflight(ctx)
|
c.handlePreflight(ctx)
|
||||||
// Preflight requests are standalone and should stop the chain as some other
|
// Preflight requests are standalone and should stop the chain as some other
|
||||||
|
@ -249,7 +249,7 @@ func (c *Cors) Serve(ctx *iris.Context) {
|
||||||
func (c *Cors) handlePreflight(ctx *iris.Context) {
|
func (c *Cors) handlePreflight(ctx *iris.Context) {
|
||||||
origin := ctx.RequestHeader("Origin")
|
origin := ctx.RequestHeader("Origin")
|
||||||
|
|
||||||
if ctx.MethodString() != "OPTIONS" {
|
if ctx.MethodString() != iris.MethodOptions {
|
||||||
c.logf(" Preflight aborted: %s!=OPTIONS", ctx.MethodString())
|
c.logf(" Preflight aborted: %s!=OPTIONS", ctx.MethodString())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package pongo
|
package pongo
|
||||||
|
|
||||||
/* TODO:
|
|
||||||
1. Find if pongo2 supports layout, it should have extends or something like django but I don't know yet, if exists then do something with the layour parameter in Exeucte/Gzip.
|
|
||||||
|
|
||||||
*/
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -19,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Engine the pongo2 engine
|
||||||
Engine struct {
|
Engine struct {
|
||||||
Config *config.Template
|
Config *config.Template
|
||||||
templateCache map[string]*pongo2.Template
|
templateCache map[string]*pongo2.Template
|
||||||
|
@ -31,6 +28,7 @@ func New(c config.Template) *Engine {
|
||||||
return &Engine{Config: &c, templateCache: make(map[string]*pongo2.Template)}
|
return &Engine{Config: &c, templateCache: make(map[string]*pongo2.Template)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildTemplates builds the templates
|
||||||
func (p *Engine) BuildTemplates() error {
|
func (p *Engine) BuildTemplates() error {
|
||||||
// Add our filters. first
|
// Add our filters. first
|
||||||
for k, v := range p.Config.Pongo.Filters {
|
for k, v := range p.Config.Pongo.Filters {
|
||||||
|
@ -91,9 +89,8 @@ func (p *Engine) buildFromDir() (templateErr error) {
|
||||||
name := filepath.ToSlash(rel)
|
name := filepath.ToSlash(rel)
|
||||||
p.templateCache[name], templateErr = set.FromString(string(buf))
|
p.templateCache[name], templateErr = set.FromString(string(buf))
|
||||||
|
|
||||||
//_, templateErr = p.Templates.FromCache(rel) // use Relative, no from path because it calculates the basedir of the fsLoader
|
|
||||||
if templateErr != nil {
|
if templateErr != nil {
|
||||||
return templateErr // break the file walk(;)
|
return templateErr
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -137,7 +134,7 @@ func (p *Engine) buildFromAsset() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
name := filepath.ToSlash(rel)
|
name := filepath.ToSlash(rel)
|
||||||
p.templateCache[name], err = set.FromString(string(buf)) // I don't konw if that will work, yet
|
p.templateCache[name], err = set.FromString(string(buf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
templateErr = err
|
templateErr = err
|
||||||
break
|
break
|
||||||
|
@ -167,19 +164,20 @@ func getPongoContext(templateData interface{}) pongo2.Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Engine) fromCache(relativeName string) *pongo2.Template {
|
func (p *Engine) fromCache(relativeName string) *pongo2.Template {
|
||||||
p.mu.Lock()
|
p.mu.Lock() // defer is slow
|
||||||
|
|
||||||
tmpl, ok := p.templateCache[relativeName]
|
tmpl, ok := p.templateCache[relativeName]
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
p.mu.Unlock() // defer is slow
|
p.mu.Unlock()
|
||||||
return tmpl
|
return tmpl
|
||||||
}
|
}
|
||||||
p.mu.Unlock() // defer is slow
|
p.mu.Unlock()
|
||||||
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 (p *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
func (p *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
||||||
if tmpl := p.fromCache(name); tmpl != nil {
|
if tmpl := p.fromCache(name); tmpl != nil {
|
||||||
return tmpl.ExecuteWriter(getPongoContext(binding), out)
|
return tmpl.ExecuteWriter(getPongoContext(binding), out)
|
||||||
|
|
|
@ -60,7 +60,7 @@ var routes = []route{
|
||||||
func TestRouter(t *testing.T) {
|
func TestRouter(t *testing.T) {
|
||||||
api := iris.New()
|
api := iris.New()
|
||||||
|
|
||||||
for idx, _ := range routes {
|
for idx := range routes {
|
||||||
r := routes[idx]
|
r := routes[idx]
|
||||||
if r.Register {
|
if r.Register {
|
||||||
api.HandleFunc(r.Method, r.Path, func(ctx *iris.Context) {
|
api.HandleFunc(r.Method, r.Path, func(ctx *iris.Context) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user