diff --git a/.gitignore b/.gitignore index cbe47dc..cd286ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -## INTELII = IDEA = mad brainx = polish = editor -.idea/ -*.iml +# inetelli G idea.jet.brainz +*.iml +.idea/ + diff --git a/README.md b/README.md index e0df12b..7fa6552 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,29 @@ -modules -======= +--- +title: Modules Overview +section: modules +--- -Set of officially supported modules for Revel applications +Revel Modules +================================== + +## Core Modules + +These modules are part of the core revel and a dependancy + +- [Static](static/) = Serves static files +- [Jobs](jobs/) = The Cron Jobs runner +- [TestRunner](testrunner/) = Test sweet + +## Upcoming + +- [csrf](csrf/) +- [pprof](/pprof/) + + +## Xperimental + +- [Auth](/auth/) +- [Db](/testrunner/) ### Caution this is a work in progress \ No newline at end of file diff --git a/auth/driver/secret/bcrypt.go b/auth/driver/secret/bcrypt.go index e0649b8..536d4aa 100644 --- a/auth/driver/secret/bcrypt.go +++ b/auth/driver/secret/bcrypt.go @@ -3,8 +3,8 @@ package secret import ( "errors" - "golang.org/x/crypto/bcrypt" "github.com/revel/modules/auth" + "golang.org/x/crypto/bcrypt" ) // example implementation of a Revel auth security driver diff --git a/csrf/app/csrf.go b/csrf/app/csrf.go index de67be7..6a43fcb 100644 --- a/csrf/app/csrf.go +++ b/csrf/app/csrf.go @@ -41,7 +41,7 @@ func RefreshToken(c *revel.Controller) { // // Usage: // 1) Add `csrf.CsrfFilter` to the app's filters (it must come after the revel.SessionFilter). -// 2) Add CSRF fields to a form with the template tag `{{ csrftoken . }}`. The filter adds a function closure to the `RenderArgs` that can pull out the secret and make the token as-needed, caching the value in the request. Ajax support provided through the `X-CSRFToken` header. +// 2) Add CSRF fields to a form with the template tag `{{ csrftoken . }}`. The filter adds a function closure to the `ViewArgs` that can pull out the secret and make the token as-needed, caching the value in the request. Ajax support provided through the `X-CSRFToken` header. func CsrfFilter(c *revel.Controller, fc []revel.Filter) { token, foundToken := c.Session["csrf_token"] @@ -91,9 +91,9 @@ func CsrfFilter(c *revel.Controller, fc []revel.Filter) { fc[0](c, fc[1:]) - // Only add token to RenderArgs if the request is: not AJAX, not missing referer header, and is same origin. + // Only add token to ViewArgs if the request is: not AJAX, not missing referer header, and is same origin. if c.Request.Header.Get("X-CSRFToken") == "" && isSameOrigin { - c.RenderArgs["_csrftoken"] = token + c.ViewArgs["_csrftoken"] = token } } @@ -111,9 +111,9 @@ func sameOrigin(u1, u2 *url.URL) bool { } func init() { - revel.TemplateFuncs["csrftoken"] = func(renderArgs map[string]interface{}) template.HTML { - if tokenFunc, ok := renderArgs["_csrftoken"]; !ok { - panic("REVEL CSRF: _csrftoken missing from RenderArgs.") + revel.TemplateFuncs["csrftoken"] = func(viewArgs map[string]interface{}) template.HTML { + if tokenFunc, ok := viewArgs["_csrftoken"]; !ok { + panic("REVEL CSRF: _csrftoken missing from ViewArgs.") } else { return template.HTML(tokenFunc.(func() string)()) } diff --git a/csrf/app/csrf_test.go b/csrf/app/csrf_test.go index dcf1cce..88d900d 100644 --- a/csrf/app/csrf_test.go +++ b/csrf/app/csrf_test.go @@ -163,7 +163,7 @@ func TestNoTokenInArgsWhenCORs(t *testing.T) { testFilters[0](c, testFilters) - if _, ok := c.RenderArgs["_csrftoken"]; ok { - t.Fatal("RenderArgs should not contain token when not same origin") + if _, ok := c.ViewArgs["_csrftoken"]; ok { + t.Fatal("ViewArgs should not contain token when not same origin") } } diff --git a/db/app/db.go b/db/app/db.go index 7ff43ca..1e3e1f4 100644 --- a/db/app/db.go +++ b/db/app/db.go @@ -1,4 +1,8 @@ -// This module configures a database connection for the application. +// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved. +// Revel Framework source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +// Package db module configures a database connection for the application. // // Developers use this module by importing and calling db.Init(). // A "Transactional" controller type is provided as a way to import interceptors @@ -11,23 +15,26 @@ package db import ( "database/sql" + "github.com/revel/revel" ) +// Database connection variables var ( Db *sql.DB Driver string Spec string ) +// Init method used to initialize DB module on `OnAppStart` func Init() { // Read configuration. var found bool if Driver, found = revel.Config.String("db.driver"); !found { - revel.ERROR.Fatal("No db.driver found.") + revel.ERROR.Fatal("db.driver not configured") } if Spec, found = revel.Config.String("db.spec"); !found { - revel.ERROR.Fatal("No db.spec found.") + revel.ERROR.Fatal("db.spec not configured") } // Open a connection. @@ -38,6 +45,7 @@ func Init() { } } +// Transactional definition for database transaction type Transactional struct { *revel.Controller Txn *sql.Tx diff --git a/jobs/app/controllers/status.go b/jobs/app/controllers/status.go index 4c12eb3..5761329 100644 --- a/jobs/app/controllers/status.go +++ b/jobs/app/controllers/status.go @@ -19,7 +19,9 @@ func (c Jobs) Status() revel.Result { remoteAddress = proxiedAddress[0] } } - if !strings.HasPrefix(remoteAddress, "127.0.0.1") && !strings.HasPrefix(remoteAddress, "::1") { + if !strings.HasPrefix(remoteAddress, "127.0.0.1") && + !strings.HasPrefix(remoteAddress, "::1") && + !strings.HasPrefix(remoteAddress, "[::1]") { return c.Forbidden("%s is not local", remoteAddress) } entries := jobs.MainCron.Entries() diff --git a/jobs/app/jobs/job.go b/jobs/app/jobs/job.go index 9a1c3ee..dd85130 100644 --- a/jobs/app/jobs/job.go +++ b/jobs/app/jobs/job.go @@ -17,12 +17,12 @@ type Job struct { running sync.Mutex } -const UNNAMED = "(unnamed)" +const UnNamed = "(unnamed)" func New(job cron.Job) *Job { name := reflect.TypeOf(job).Name() if name == "Func" { - name = UNNAMED + name = UnNamed } return &Job{ Name: name, diff --git a/jobs/app/jobs/plugin.go b/jobs/app/jobs/plugin.go index 75b7fc6..882928a 100644 --- a/jobs/app/jobs/plugin.go +++ b/jobs/app/jobs/plugin.go @@ -7,7 +7,7 @@ import ( "github.com/revel/revel" ) -const DEFAULT_JOB_POOL_SIZE = 10 +const DefaultJobPoolSize = 10 var ( // Singleton instance of the underlying job scheduler. @@ -23,7 +23,7 @@ var ( func init() { MainCron = cron.New() revel.OnAppStart(func() { - if size := revel.Config.IntDefault("jobs.pool", DEFAULT_JOB_POOL_SIZE); size > 0 { + if size := revel.Config.IntDefault("jobs.pool", DefaultJobPoolSize); size > 0 { workPermits = make(chan struct{}, size) } selfConcurrent = revel.Config.BoolDefault("jobs.selfconcurrent", false) diff --git a/static/app/controllers/static.go b/static/app/controllers/static.go index 7c8aeef..d4fd8f3 100644 --- a/static/app/controllers/static.go +++ b/static/app/controllers/static.go @@ -1,18 +1,24 @@ +// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved. +// Revel Framework source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + package controllers import ( - "github.com/revel/revel" "os" fpath "path/filepath" "strings" "syscall" + + "github.com/revel/revel" ) +// Static file serving controller type Static struct { *revel.Controller } -// This method handles requests for files. The supplied prefix may be absolute +// Serve method handles requests for files. The supplied prefix may be absolute // or relative. If the prefix is relative it is assumed to be relative to the // application directory. The filepath may either be just a file or an // additional filepath to search for the given file. This response may return @@ -52,7 +58,7 @@ func (c Static) Serve(prefix, filepath string) revel.Result { return serve(c, prefix, filepath) } -// This method allows modules to serve binary files. The parameters are the same +// ServeModule method allows modules to serve binary files. The parameters are the same // as Static.Serve with the additional module name pre-pended to the list of // arguments. func (c Static) ServeModule(moduleName, prefix, filepath string) revel.Result { @@ -74,7 +80,6 @@ func (c Static) ServeModule(moduleName, prefix, filepath string) revel.Result { return serve(c, absPath, filepath) } - // This method allows static serving of application files in a verified manner. func serve(c Static, prefix, filepath string) revel.Result { var basePath string diff --git a/testrunner/app/controllers/testrunner.go b/testrunner/app/controllers/testrunner.go index 8ce9724..bb5a553 100644 --- a/testrunner/app/controllers/testrunner.go +++ b/testrunner/app/controllers/testrunner.go @@ -1,3 +1,7 @@ +// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved. +// Revel Framework source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + package controllers import ( @@ -68,7 +72,7 @@ var ( // Index is an action which renders the full list of available test suites and their tests. func (c TestRunner) Index() revel.Result { - c.RenderArgs["suiteFound"] = len(testSuites) > 0 + c.ViewArgs["suiteFound"] = len(testSuites) > 0 return c.Render(testSuites) } @@ -81,9 +85,9 @@ func (c TestRunner) Suite(suite string) revel.Result { } } - c.RenderArgs["testSuites"] = foundTestSuites - c.RenderArgs["suiteFound"] = len(foundTestSuites) > 0 - c.RenderArgs["suiteName"] = suite + c.ViewArgs["testSuites"] = foundTestSuites + c.ViewArgs["suiteFound"] = len(foundTestSuites) > 0 + c.ViewArgs["suiteName"] = suite return c.RenderTemplate("TestRunner/Index.html") } @@ -118,7 +122,7 @@ func (c TestRunner) Run(suite, test string) revel.Result { // Render the error and save to the result structure. var buffer bytes.Buffer tmpl, _ := revel.MainTemplateLoader.Template("TestRunner/FailureDetail.html") - tmpl.Render(&buffer, map[string]interface{}{ + _ = tmpl.Render(&buffer, map[string]interface{}{ "error": panicErr, "response": res, "postfix": suite + "_" + test, @@ -149,13 +153,13 @@ func (c TestRunner) Run(suite, test string) revel.Result { result.Passed = true }() - return c.RenderJson(result) + return c.RenderJSON(result) } // List returns a JSON list of test suites and tests. // It is used by revel test command line tool. func (c TestRunner) List() revel.Result { - return c.RenderJson(testSuites) + return c.RenderJSON(testSuites) } /* @@ -209,21 +213,21 @@ func describeSuite(testSuite interface{}) TestSuiteDesc { // errorSummary gets an error and returns its summary in human readable format. func errorSummary(err *revel.Error) (message string) { - expected_prefix := "(expected)" - actual_prefix := "(actual)" + expectedPrefix := "(expected)" + actualPrefix := "(actual)" errDesc := err.Description //strip the actual/expected stuff to provide more condensed display. - if strings.Index(errDesc, expected_prefix) == 0 { - errDesc = errDesc[len(expected_prefix):len(errDesc)] + if strings.Index(errDesc, expectedPrefix) == 0 { + errDesc = errDesc[len(expectedPrefix):] } - if strings.LastIndex(errDesc, actual_prefix) > 0 { - errDesc = errDesc[0 : len(errDesc)-len(actual_prefix)] + if strings.LastIndex(errDesc, actualPrefix) > 0 { + errDesc = errDesc[0 : len(errDesc)-len(actualPrefix)] } errFile := err.Path slashIdx := strings.LastIndex(errFile, "/") if slashIdx > 0 { - errFile = errFile[slashIdx+1 : len(errFile)] + errFile = errFile[slashIdx+1:] } message = fmt.Sprintf("%s %s#%d", errDesc, errFile, err.Line) diff --git a/testrunner/app/views/TestRunner/Index.html b/testrunner/app/views/TestRunner/Index.html index f5fe75a..dcb695d 100644 --- a/testrunner/app/views/TestRunner/Index.html +++ b/testrunner/app/views/TestRunner/Index.html @@ -200,7 +200,7 @@

if (result.Passed) { passCount++; } else { - console.log("fail: result.Name"); + console.log("fail:", result.Name); failCount++; var resultLnk = $("a", resultCell); $(resultLnk).text(result.ErrorSummary);