From a3f3e7ebd2dd841f4e50dbac4efeabea92ba749b Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Fri, 3 Jun 2016 05:20:27 +0300 Subject: [PATCH] Nothing special(2): remaining linting --- context_storage.go | 2 +- middleware/cors/cors.go | 4 ++-- render/template/engine/pongo/pongo.go | 20 +++++++++----------- tests/router_test.go | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/context_storage.go b/context_storage.go index e272f44a..4cf394a2 100644 --- a/context_storage.go +++ b/context_storage.go @@ -146,7 +146,7 @@ func (ctx *Context) Session() store.IStore { 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() { if ctx.station.sessionManager != nil { if store := ctx.Session(); store != nil { diff --git a/middleware/cors/cors.go b/middleware/cors/cors.go index 91fb5020..d06a25a5 100644 --- a/middleware/cors/cors.go +++ b/middleware/cors/cors.go @@ -228,7 +228,7 @@ func (c *Cors) Conflicts() string { // Serve serves the middleware func (c *Cors) Serve(ctx *iris.Context) { - if ctx.MethodString() == "OPTIONS" { + if ctx.MethodString() == iris.MethodOptions { c.logf("Serve: Preflight request") c.handlePreflight(ctx) // 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) { origin := ctx.RequestHeader("Origin") - if ctx.MethodString() != "OPTIONS" { + if ctx.MethodString() != iris.MethodOptions { c.logf(" Preflight aborted: %s!=OPTIONS", ctx.MethodString()) return } diff --git a/render/template/engine/pongo/pongo.go b/render/template/engine/pongo/pongo.go index 93411a19..e5f946e6 100644 --- a/render/template/engine/pongo/pongo.go +++ b/render/template/engine/pongo/pongo.go @@ -1,9 +1,5 @@ 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 ( "io" "io/ioutil" @@ -19,6 +15,7 @@ import ( ) type ( + // Engine the pongo2 engine Engine struct { Config *config.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)} } +// BuildTemplates builds the templates func (p *Engine) BuildTemplates() error { // Add our filters. first for k, v := range p.Config.Pongo.Filters { @@ -91,9 +89,8 @@ func (p *Engine) buildFromDir() (templateErr error) { name := filepath.ToSlash(rel) 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 { - return templateErr // break the file walk(;) + return templateErr } break } @@ -137,7 +134,7 @@ func (p *Engine) buildFromAsset() error { break } 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 { templateErr = err break @@ -167,19 +164,20 @@ func getPongoContext(templateData interface{}) pongo2.Context { } func (p *Engine) fromCache(relativeName string) *pongo2.Template { - p.mu.Lock() + p.mu.Lock() // defer is slow tmpl, ok := p.templateCache[relativeName] if ok { - p.mu.Unlock() // defer is slow + p.mu.Unlock() return tmpl } - p.mu.Unlock() // defer is slow + p.mu.Unlock() 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 { if tmpl := p.fromCache(name); tmpl != nil { return tmpl.ExecuteWriter(getPongoContext(binding), out) diff --git a/tests/router_test.go b/tests/router_test.go index 034497f8..33beaa49 100644 --- a/tests/router_test.go +++ b/tests/router_test.go @@ -60,7 +60,7 @@ var routes = []route{ func TestRouter(t *testing.T) { api := iris.New() - for idx, _ := range routes { + for idx := range routes { r := routes[idx] if r.Register { api.HandleFunc(r.Method, r.Path, func(ctx *iris.Context) {