diff --git a/Vendor.md b/Vendor.md index 022244078..34fa126b7 100755 --- a/Vendor.md +++ b/Vendor.md @@ -1,9 +1,12 @@ # Vendor -## revel 0.18 +## Install leanote_revel cmd + +基于revel 0.18 ``` -revel run github.com/leanote/leanote +go install github.com/leanote/leanote/cmd/leanote_revel +leanote_revel run github.com/leanote/leanote ```` ## build leanote diff --git a/cmd/leanote_revel/build.go b/cmd/leanote_revel/build.go old mode 100755 new mode 100644 index eb6146e39..fa7ba310a --- a/cmd/leanote_revel/build.go +++ b/cmd/leanote_revel/build.go @@ -60,11 +60,11 @@ func buildApp(args []string) { } if err := os.RemoveAll(destPath); err != nil && !os.IsNotExist(err) { - revel.ERROR.Fatalln(err) + revel.RevelLog.Fatal("Remove all error","error", err) } if err := os.MkdirAll(destPath, 0777); err != nil { - revel.ERROR.Fatalln(err) + revel.RevelLog.Fatal("makedir error","error",err) } app, reverr := harness.Build() @@ -101,7 +101,7 @@ func buildApp(args []string) { } modulePath, err := revel.ResolveImportPath(moduleImportPath) if err != nil { - revel.ERROR.Fatalln("Failed to load module %s: %s", key[len("module."):], err) + revel.RevelLog.Fatalf("Failed to load module %s: %s", key[len("module."):], err) } modulePaths[moduleImportPath] = modulePath } diff --git a/cmd/leanote_revel/clean.go b/cmd/leanote_revel/clean.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/new.go b/cmd/leanote_revel/new.go old mode 100755 new mode 100644 index c893fbd15..2875e05a0 --- a/cmd/leanote_revel/new.go +++ b/cmd/leanote_revel/new.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "go/build" - "log" "math/rand" "os" "os/exec" @@ -67,8 +66,6 @@ func newApp(args []string) { errorf("Too many arguments provided.\nRun 'revel help new' for usage.\n") } - revel.ERROR.SetFlags(log.LstdFlags) - // checking and setting go paths initGoPaths() @@ -129,7 +126,7 @@ func initGoPaths() { } if len(srcRoot) == 0 { - revel.ERROR.Fatalln("Abort: could not create a Revel application outside of GOPATH.") + revel.RevelLog.Fatal("Abort: could not create a Revel application outside of GOPATH.") } // set go src path @@ -148,8 +145,10 @@ func setApplicationPath(args []string) { importPath) } + appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath)) + _, err = build.Import(importPath, "", build.FindOnly) - if err == nil { + if err == nil && !empty(appPath) { errorf("Abort: Import path %s already exists.\n", importPath) } @@ -158,7 +157,6 @@ func setApplicationPath(args []string) { errorf("Abort: Could not find Revel source code: %s\n", err) } - appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath)) appName = filepath.Base(appPath) basePath = filepath.ToSlash(filepath.Dir(importPath)) diff --git a/cmd/leanote_revel/package.go b/cmd/leanote_revel/package.go old mode 100755 new mode 100644 index 31b5ff35d..33db250dd --- a/cmd/leanote_revel/package.go +++ b/cmd/leanote_revel/package.go @@ -53,7 +53,7 @@ func packageApp(args []string) { // Remove the archive if it already exists. destFile := filepath.Base(revel.BasePath) + ".tar.gz" if err := os.Remove(destFile); err != nil && !os.IsNotExist(err) { - revel.ERROR.Fatal(err) + revel.RevelLog.Fatal("Unable to remove target file","error",err,"file",destFile) } // Collect stuff in a temp directory. diff --git a/cmd/leanote_revel/package_run.bat.template b/cmd/leanote_revel/package_run.bat.template old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/package_run.sh.template b/cmd/leanote_revel/package_run.sh.template old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/rev.go b/cmd/leanote_revel/rev.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/run.go b/cmd/leanote_revel/run.go old mode 100755 new mode 100644 index 00759c567..0178d9c52 --- a/cmd/leanote_revel/run.go +++ b/cmd/leanote_revel/run.go @@ -10,9 +10,6 @@ import ( "github.com/leanote/leanote/cmd/harness" "github.com/revel/revel" - // "fmt" - - "path/filepath" ) var cmdRun = &Command{ @@ -54,7 +51,7 @@ func parseRunArgs(args []string) *RunArgs { } switch len(args) { case 3: - // Possibile combinations + // Possible combinations // revel run [import-path] [run-mode] [port] port, err := strconv.Atoi(args[2]) if err != nil { @@ -64,7 +61,7 @@ func parseRunArgs(args []string) *RunArgs { inputArgs.Mode = args[1] inputArgs.Port = port case 2: - // Possibile combinations + // Possible combinations // 1. revel run [import-path] [run-mode] // 2. revel run [import-path] [port] // 3. revel run [run-mode] [port] @@ -88,11 +85,16 @@ func parseRunArgs(args []string) *RunArgs { inputArgs.Port = port } case 1: - // Possibile combinations + // Possible combinations // 1. revel run [import-path] // 2. revel run [port] // 3. revel run [run-mode] - if _, err := build.Import(args[0], "", build.FindOnly); err == nil { + _, err := build.Import(args[0], "", build.FindOnly) + if err != nil { + revel.RevelLog.Warn("Unable to run using an import path, assuming import path is working directory %s %s", "Argument", args[0], "error", err.Error()) + } + println("Trying to build with", args[0], err) + if err == nil { // 1st arg is the import path inputArgs.ImportPath = args[0] } else if port, err := strconv.Atoi(args[0]); err == nil { @@ -107,43 +109,11 @@ func parseRunArgs(args []string) *RunArgs { return &inputArgs } - -// findSrcPaths uses the "go/build" package to find the source root for Revel -// and the app. -func findSrcPaths(importPath string) (appSourcePath string) { - var ( - gopaths = filepath.SplitList(build.Default.GOPATH) - goroot = build.Default.GOROOT - ) - - if len(gopaths) == 0 { - revel.ERROR.Fatalln("GOPATH environment variable is not set. ", - "Please refer to http://golang.org/doc/code.html to configure your Go environment.") - } - - if revel.ContainsString(gopaths, goroot) { - revel.ERROR.Fatalf("GOPATH (%s) must not include your GOROOT (%s). "+ - "Please refer to http://golang.org/doc/code.html to configure your Go environment.", - gopaths, goroot) - } - - appPkg, err := build.Import(importPath, "", build.FindOnly) - if err != nil { - revel.ERROR.Fatalln("Failed to import", importPath, "with error:", err) - } - - return appPkg.SrcRoot -} - func runApp(args []string) { runArgs := parseRunArgs(args) // Find and parse app.conf - // fmt.Println(runArgs.ImportPath + "/vendor") - // revel.Init(runArgs.Mode, runArgs.ImportPath, runArgs.ImportPath + "/vendor") - srcPath := findSrcPaths(runArgs.ImportPath) - srcPath = "" - revel.Init(runArgs.Mode, runArgs.ImportPath, srcPath) + revel.Init(runArgs.Mode, runArgs.ImportPath, "") revel.LoadMimeConfig() // fallback to default port @@ -151,18 +121,18 @@ func runApp(args []string) { runArgs.Port = revel.HTTPPort } - revel.INFO.Printf("Running %s (%s) in %s mode\n", revel.AppName, revel.ImportPath, runArgs.Mode) - revel.TRACE.Println("Base path:", revel.BasePath) + revel.RevelLog.Infof("Running %s (%s) in %s mode\n", revel.AppName, revel.ImportPath, runArgs.Mode) + revel.RevelLog.Debug("Base path:", "path", revel.BasePath) // If the app is run in "watched" mode, use the harness to run it. if revel.Config.BoolDefault("watch", true) && revel.Config.BoolDefault("watch.code", true) { - revel.TRACE.Println("Running in watched mode.") + revel.RevelLog.Debug("Running in watched mode.") revel.HTTPPort = runArgs.Port harness.NewHarness().Run() // Never returns. } // Else, just build and run the app. - revel.TRACE.Println("Running in live build mode.") + revel.RevelLog.Debug("Running in live build mode.") app, err := harness.Build() if err != nil { errorf("Failed to build app: %s", err) diff --git a/cmd/leanote_revel/skeleton/.gitignore b/cmd/leanote_revel/skeleton/.gitignore old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/README.md b/cmd/leanote_revel/skeleton/README.md old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/controllers/app.go b/cmd/leanote_revel/skeleton/app/controllers/app.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/init.go b/cmd/leanote_revel/skeleton/app/init.go old mode 100755 new mode 100644 index 74767e99a..b4e614f34 --- a/cmd/leanote_revel/skeleton/app/init.go +++ b/cmd/leanote_revel/skeleton/app/init.go @@ -29,8 +29,7 @@ func init() { revel.ActionInvoker, // Invoke the action. } - - // register startup functions with OnAppStart + // Register startup functions with OnAppStart // revel.DevMode and revel.RunMode only work inside of OnAppStart. See Example Startup Script // ( order dependent ) // revel.OnAppStart(ExampleStartupScript) @@ -39,9 +38,8 @@ func init() { } // HeaderFilter adds common security headers -// TODO turn this into revel.HeaderFilter -// should probably also have a filter for CSRF -// not sure if it can go in the same filter or not +// There is a full implementation of a CSRF filter in +// https://github.com/revel/modules/tree/master/csrf var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) { c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN") c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block") diff --git a/cmd/leanote_revel/skeleton/app/views/App/Index.html b/cmd/leanote_revel/skeleton/app/views/App/Index.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/debug.html b/cmd/leanote_revel/skeleton/app/views/debug.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/errors/404.html b/cmd/leanote_revel/skeleton/app/views/errors/404.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/errors/500.html b/cmd/leanote_revel/skeleton/app/views/errors/500.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/flash.html b/cmd/leanote_revel/skeleton/app/views/flash.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/footer.html b/cmd/leanote_revel/skeleton/app/views/footer.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/app/views/header.html b/cmd/leanote_revel/skeleton/app/views/header.html old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/conf/app.conf.template b/cmd/leanote_revel/skeleton/conf/app.conf.template old mode 100755 new mode 100644 index 7debe6bf5..2b57895b9 --- a/cmd/leanote_revel/skeleton/conf/app.conf.template +++ b/cmd/leanote_revel/skeleton/conf/app.conf.template @@ -84,15 +84,6 @@ format.datetime = 2006-01-02 15:04 results.chunked = false -# Prefixes for each log message line. -# User can override these prefix values within any section -# For e.g: [dev], [prod], etc -log.trace.prefix = "TRACE " -log.info.prefix = "INFO " -log.warn.prefix = "WARN " -log.error.prefix = "ERROR " - - # The default language of this application. i18n.default_language = en @@ -104,7 +95,7 @@ i18n.default_language = en # Module to serve static content such as CSS, JavaScript and Media files # Allows Routes like this: # `Static.ServeModule("modulename","public")` -module.static=github.com/revel/modules/static +module.static = github.com/revel/modules/static @@ -179,37 +170,14 @@ module.testrunner = github.com/revel/modules/testrunner # Log to Os's standard error output. Default value. # "relative/path/to/log" # Log to file. -log.trace.output = off -log.info.output = stderr -log.warn.output = stderr -log.error.output = stderr - - -# Revel log flags. Possible flags defined by the Go `log` package. Go log is -# "Bits OR'ed together to control what's printed -# See: -# https://golang.org/pkg/log/#pkg-constants -# Values: -# "0" -# Just log the message, turn off the flags. -# "3" -# log.LstdFlags (log.Ldate|log.Ltime) -# "19" -# log.Ldate|log.Ltime|log.Lshortfile -# "23" -# log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile -log.trace.flags = 19 -log.info.flags = 19 -log.warn.flags = 19 -log.error.flags = 19 - +log.all.filter.module.app = stdout # Log all loggers for the application to the stdout +log.error.nfilter.module.app = stderr # Everything else that logs an error to stderr +log.crit.output = stderr # Everything that logs something as critical goes to this # Revel request access log # Access log line format: -# RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath -# Sample format: -# 2016/05/25 17:46:37.112 127.0.0.1 200 270.157µs GET / -log.request.output = stderr +# INFO 21:53:55 static server-engine.go:169: Request Stats ip=127.0.0.1 path=/public/vendors/datatables.net-buttons/js/buttons.html5.min.js method=GET start=2017/08/31 21:53:55 status=200 duration_seconds=0.0002583 section=requestlog +log.request.output = stdout @@ -229,30 +197,11 @@ watch = false module.testrunner = -log.trace.output = off -log.info.output = off -log.warn.output = log/%(app.name)s.log -log.error.output = log/%(app.name)s.log - -# Revel log flags. Possible flags defined by the Go `log` package, -# please refer https://golang.org/pkg/log/#pkg-constants -# Go log is "Bits or'ed together to control what's printed" -# Examples: -# 0 => just log the message, turn off the flags -# 3 => log.LstdFlags (log.Ldate|log.Ltime) -# 19 => log.Ldate|log.Ltime|log.Lshortfile -# 23 => log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile -log.trace.flags = 3 -log.info.flags = 3 -log.warn.flags = 3 -log.error.flags = 3 - +log.warn.output = log/%(app.name)-warn.json # Log all warn messages to file +log.error.output = log/%(app.name)-error.json # Log all errors to file +log.crit.output = log/%(app.name)-critical.json # Log all critical to file -# Revel request access log -# Access log line format: -# RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath -# Sample format: -# 2016/05/25 17:46:37.112 127.0.0.1 200 270.157µs GET / +# Revel request access log (json format) # Example: -# log.request.output = %(app.name)s-request.log -log.request.output = off +# log.request.output = %(app.name)s-request.json +log.request.output = log/%(app.name)s-requests.json diff --git a/cmd/leanote_revel/skeleton/conf/routes b/cmd/leanote_revel/skeleton/conf/routes old mode 100755 new mode 100644 index 35e99fa96..ba93d6139 --- a/cmd/leanote_revel/skeleton/conf/routes +++ b/cmd/leanote_revel/skeleton/conf/routes @@ -15,5 +15,12 @@ GET /favicon.ico 404 # Map static resources from the /app/public folder to the /public path GET /public/*filepath Static.Serve("public") -# Catch all -* /:controller/:action :controller.:action +# Catch all, this will route any request into the controller path +# +# **** WARNING **** +# Enabling this exposes any controller and function to the web. +# ** This is a serious security issue if used online ** +# +# For rapid development uncomment the following to add new controller.action endpoints +# without having to add them to the routes table. +# * /:controller/:action :controller.:action diff --git a/cmd/leanote_revel/skeleton/messages/sample.en b/cmd/leanote_revel/skeleton/messages/sample.en old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/css/bootstrap-3.3.6.min.css b/cmd/leanote_revel/skeleton/public/css/bootstrap-3.3.6.min.css old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.ttf b/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.ttf old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.woff b/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.woff old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.woff2 b/cmd/leanote_revel/skeleton/public/fonts/glyphicons-halflings-regular.woff2 old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/img/favicon.png b/cmd/leanote_revel/skeleton/public/img/favicon.png old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/js/bootstrap-3.3.6.min.js b/cmd/leanote_revel/skeleton/public/js/bootstrap-3.3.6.min.js old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/public/js/jquery-2.2.4.min.js b/cmd/leanote_revel/skeleton/public/js/jquery-2.2.4.min.js old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/skeleton/tests/apptest.go b/cmd/leanote_revel/skeleton/tests/apptest.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/test.go b/cmd/leanote_revel/test.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/util.go b/cmd/leanote_revel/util.go old mode 100755 new mode 100644 diff --git a/cmd/leanote_revel/version.go b/cmd/leanote_revel/version.go old mode 100755 new mode 100644