This commit is contained in:
lealife
2017-11-30 20:15:28 +08:00
parent bba9030f14
commit 6cbb82a927
34 changed files with 51 additions and 126 deletions

View File

@ -1,9 +1,12 @@
# Vendor # 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 ## build leanote

6
cmd/leanote_revel/build.go Executable file → Normal file
View File

@ -60,11 +60,11 @@ func buildApp(args []string) {
} }
if err := os.RemoveAll(destPath); err != nil && !os.IsNotExist(err) { 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 { if err := os.MkdirAll(destPath, 0777); err != nil {
revel.ERROR.Fatalln(err) revel.RevelLog.Fatal("makedir error","error",err)
} }
app, reverr := harness.Build() app, reverr := harness.Build()
@ -101,7 +101,7 @@ func buildApp(args []string) {
} }
modulePath, err := revel.ResolveImportPath(moduleImportPath) modulePath, err := revel.ResolveImportPath(moduleImportPath)
if err != nil { 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 modulePaths[moduleImportPath] = modulePath
} }

0
cmd/leanote_revel/clean.go Executable file → Normal file
View File

10
cmd/leanote_revel/new.go Executable file → Normal file
View File

@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/build" "go/build"
"log"
"math/rand" "math/rand"
"os" "os"
"os/exec" "os/exec"
@ -67,8 +66,6 @@ func newApp(args []string) {
errorf("Too many arguments provided.\nRun 'revel help new' for usage.\n") errorf("Too many arguments provided.\nRun 'revel help new' for usage.\n")
} }
revel.ERROR.SetFlags(log.LstdFlags)
// checking and setting go paths // checking and setting go paths
initGoPaths() initGoPaths()
@ -129,7 +126,7 @@ func initGoPaths() {
} }
if len(srcRoot) == 0 { 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 // set go src path
@ -148,8 +145,10 @@ func setApplicationPath(args []string) {
importPath) importPath)
} }
appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath))
_, err = build.Import(importPath, "", build.FindOnly) _, err = build.Import(importPath, "", build.FindOnly)
if err == nil { if err == nil && !empty(appPath) {
errorf("Abort: Import path %s already exists.\n", importPath) 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) errorf("Abort: Could not find Revel source code: %s\n", err)
} }
appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath))
appName = filepath.Base(appPath) appName = filepath.Base(appPath)
basePath = filepath.ToSlash(filepath.Dir(importPath)) basePath = filepath.ToSlash(filepath.Dir(importPath))

2
cmd/leanote_revel/package.go Executable file → Normal file
View File

@ -53,7 +53,7 @@ func packageApp(args []string) {
// Remove the archive if it already exists. // Remove the archive if it already exists.
destFile := filepath.Base(revel.BasePath) + ".tar.gz" destFile := filepath.Base(revel.BasePath) + ".tar.gz"
if err := os.Remove(destFile); err != nil && !os.IsNotExist(err) { 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. // Collect stuff in a temp directory.

0
cmd/leanote_revel/package_run.bat.template Executable file → Normal file
View File

0
cmd/leanote_revel/package_run.sh.template Executable file → Normal file
View File

0
cmd/leanote_revel/rev.go Executable file → Normal file
View File

58
cmd/leanote_revel/run.go Executable file → Normal file
View File

@ -10,9 +10,6 @@ import (
"github.com/leanote/leanote/cmd/harness" "github.com/leanote/leanote/cmd/harness"
"github.com/revel/revel" "github.com/revel/revel"
// "fmt"
"path/filepath"
) )
var cmdRun = &Command{ var cmdRun = &Command{
@ -54,7 +51,7 @@ func parseRunArgs(args []string) *RunArgs {
} }
switch len(args) { switch len(args) {
case 3: case 3:
// Possibile combinations // Possible combinations
// revel run [import-path] [run-mode] [port] // revel run [import-path] [run-mode] [port]
port, err := strconv.Atoi(args[2]) port, err := strconv.Atoi(args[2])
if err != nil { if err != nil {
@ -64,7 +61,7 @@ func parseRunArgs(args []string) *RunArgs {
inputArgs.Mode = args[1] inputArgs.Mode = args[1]
inputArgs.Port = port inputArgs.Port = port
case 2: case 2:
// Possibile combinations // Possible combinations
// 1. revel run [import-path] [run-mode] // 1. revel run [import-path] [run-mode]
// 2. revel run [import-path] [port] // 2. revel run [import-path] [port]
// 3. revel run [run-mode] [port] // 3. revel run [run-mode] [port]
@ -88,11 +85,16 @@ func parseRunArgs(args []string) *RunArgs {
inputArgs.Port = port inputArgs.Port = port
} }
case 1: case 1:
// Possibile combinations // Possible combinations
// 1. revel run [import-path] // 1. revel run [import-path]
// 2. revel run [port] // 2. revel run [port]
// 3. revel run [run-mode] // 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 // 1st arg is the import path
inputArgs.ImportPath = args[0] inputArgs.ImportPath = args[0]
} else if port, err := strconv.Atoi(args[0]); err == nil { } else if port, err := strconv.Atoi(args[0]); err == nil {
@ -107,43 +109,11 @@ func parseRunArgs(args []string) *RunArgs {
return &inputArgs 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) { func runApp(args []string) {
runArgs := parseRunArgs(args) runArgs := parseRunArgs(args)
// Find and parse app.conf // Find and parse app.conf
// fmt.Println(runArgs.ImportPath + "/vendor") revel.Init(runArgs.Mode, runArgs.ImportPath, "")
// revel.Init(runArgs.Mode, runArgs.ImportPath, runArgs.ImportPath + "/vendor")
srcPath := findSrcPaths(runArgs.ImportPath)
srcPath = ""
revel.Init(runArgs.Mode, runArgs.ImportPath, srcPath)
revel.LoadMimeConfig() revel.LoadMimeConfig()
// fallback to default port // fallback to default port
@ -151,18 +121,18 @@ func runApp(args []string) {
runArgs.Port = revel.HTTPPort runArgs.Port = revel.HTTPPort
} }
revel.INFO.Printf("Running %s (%s) in %s mode\n", revel.AppName, revel.ImportPath, runArgs.Mode) revel.RevelLog.Infof("Running %s (%s) in %s mode\n", revel.AppName, revel.ImportPath, runArgs.Mode)
revel.TRACE.Println("Base path:", revel.BasePath) revel.RevelLog.Debug("Base path:", "path", revel.BasePath)
// If the app is run in "watched" mode, use the harness to run it. // 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) { 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 revel.HTTPPort = runArgs.Port
harness.NewHarness().Run() // Never returns. harness.NewHarness().Run() // Never returns.
} }
// Else, just build and run the app. // 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() app, err := harness.Build()
if err != nil { if err != nil {
errorf("Failed to build app: %s", err) errorf("Failed to build app: %s", err)

0
cmd/leanote_revel/skeleton/.gitignore vendored Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/README.md Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/controllers/app.go Executable file → Normal file
View File

8
cmd/leanote_revel/skeleton/app/init.go Executable file → Normal file
View File

@ -29,8 +29,7 @@ func init() {
revel.ActionInvoker, // Invoke the action. 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 // revel.DevMode and revel.RunMode only work inside of OnAppStart. See Example Startup Script
// ( order dependent ) // ( order dependent )
// revel.OnAppStart(ExampleStartupScript) // revel.OnAppStart(ExampleStartupScript)
@ -39,9 +38,8 @@ func init() {
} }
// HeaderFilter adds common security headers // HeaderFilter adds common security headers
// TODO turn this into revel.HeaderFilter // There is a full implementation of a CSRF filter in
// should probably also have a filter for CSRF // https://github.com/revel/modules/tree/master/csrf
// not sure if it can go in the same filter or not
var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) { var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) {
c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN") c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN")
c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block") c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block")

0
cmd/leanote_revel/skeleton/app/views/App/Index.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/debug.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/errors/404.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/errors/500.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/flash.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/footer.html Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/app/views/header.html Executable file → Normal file
View File

75
cmd/leanote_revel/skeleton/conf/app.conf.template Executable file → Normal file
View File

@ -84,15 +84,6 @@ format.datetime = 2006-01-02 15:04
results.chunked = false 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. # The default language of this application.
i18n.default_language = en i18n.default_language = en
@ -104,7 +95,7 @@ i18n.default_language = en
# Module to serve static content such as CSS, JavaScript and Media files # Module to serve static content such as CSS, JavaScript and Media files
# Allows Routes like this: # Allows Routes like this:
# `Static.ServeModule("modulename","public")` # `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. # Log to Os's standard error output. Default value.
# "relative/path/to/log" # "relative/path/to/log"
# Log to file. # Log to file.
log.trace.output = off log.all.filter.module.app = stdout # Log all loggers for the application to the stdout
log.info.output = stderr log.error.nfilter.module.app = stderr # Everything else that logs an error to stderr
log.warn.output = stderr log.crit.output = stderr # Everything that logs something as critical goes to this
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
# Revel request access log # Revel request access log
# Access log line format: # Access log line format:
# RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath # 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
# Sample format: log.request.output = stdout
# 2016/05/25 17:46:37.112 127.0.0.1 200 270.157µs GET /
log.request.output = stderr
@ -229,30 +197,11 @@ watch = false
module.testrunner = module.testrunner =
log.trace.output = off log.warn.output = log/%(app.name)-warn.json # Log all warn messages to file
log.info.output = off log.error.output = log/%(app.name)-error.json # Log all errors to file
log.warn.output = log/%(app.name)s.log log.crit.output = log/%(app.name)-critical.json # Log all critical to file
log.error.output = log/%(app.name)s.log
# Revel log flags. Possible flags defined by the Go `log` package, # Revel request access log (json format)
# 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
# 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 /
# Example: # Example:
# log.request.output = %(app.name)s-request.log # log.request.output = %(app.name)s-request.json
log.request.output = off log.request.output = log/%(app.name)s-requests.json

11
cmd/leanote_revel/skeleton/conf/routes Executable file → Normal file
View File

@ -15,5 +15,12 @@ GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path # Map static resources from the /app/public folder to the /public path
GET /public/*filepath Static.Serve("public") GET /public/*filepath Static.Serve("public")
# Catch all # Catch all, this will route any request into the controller path
* /:controller/:action :controller.:action #
# **** 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

0
cmd/leanote_revel/skeleton/messages/sample.en Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/public/css/bootstrap-3.3.6.min.css vendored Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/public/img/favicon.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

0
cmd/leanote_revel/skeleton/public/js/bootstrap-3.3.6.min.js vendored Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/public/js/jquery-2.2.4.min.js vendored Executable file → Normal file
View File

0
cmd/leanote_revel/skeleton/tests/apptest.go Executable file → Normal file
View File

0
cmd/leanote_revel/test.go Executable file → Normal file
View File

0
cmd/leanote_revel/util.go Executable file → Normal file
View File

0
cmd/leanote_revel/version.go Executable file → Normal file
View File