Skip to content

Commit

Permalink
cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
lealife committed Nov 30, 2017
1 parent bba9030 commit 6cbb82a
Show file tree
Hide file tree
Showing 34 changed files with 51 additions and 126 deletions.
7 changes: 5 additions & 2 deletions Vendor.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/leanote_revel/build.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
Empty file modified cmd/leanote_revel/clean.go
100755 → 100644
Empty file.
10 changes: 4 additions & 6 deletions cmd/leanote_revel/new.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"go/build"
"log"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion cmd/leanote_revel/package.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file modified cmd/leanote_revel/package_run.bat.template
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/package_run.sh.template
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/rev.go
100755 → 100644
Empty file.
58 changes: 14 additions & 44 deletions cmd/leanote_revel/run.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (

"github.com/leanote/leanote/cmd/harness"
"github.com/revel/revel"
// "fmt"

"path/filepath"
)

var cmdRun = &Command{
Expand Down Expand Up @@ -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 {
Expand All @@ -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]
Expand All @@ -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 {
Expand All @@ -107,62 +109,30 @@ 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
if runArgs.Port == 0 {
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)
Expand Down
Empty file modified cmd/leanote_revel/skeleton/.gitignore
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/README.md
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/controllers/app.go
100755 → 100644
Empty file.
8 changes: 3 additions & 5 deletions cmd/leanote_revel/skeleton/app/init.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
Empty file modified cmd/leanote_revel/skeleton/app/views/App/Index.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/debug.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/errors/404.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/errors/500.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/flash.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/footer.html
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/app/views/header.html
100755 → 100644
Empty file.
75 changes: 12 additions & 63 deletions cmd/leanote_revel/skeleton/conf/app.conf.template
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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



Expand Down Expand Up @@ -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



Expand All @@ -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
11 changes: 9 additions & 2 deletions cmd/leanote_revel/skeleton/conf/routes
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file modified cmd/leanote_revel/skeleton/messages/sample.en
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/public/css/bootstrap-3.3.6.min.css
100755 → 100644
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified cmd/leanote_revel/skeleton/public/img/favicon.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified cmd/leanote_revel/skeleton/public/js/bootstrap-3.3.6.min.js
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/public/js/jquery-2.2.4.min.js
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/skeleton/tests/apptest.go
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/test.go
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/util.go
100755 → 100644
Empty file.
Empty file modified cmd/leanote_revel/version.go
100755 → 100644
Empty file.

0 comments on commit 6cbb82a

Please sign in to comment.