From 0fd5bcfcbaa045cc8419303a0e61f3141380ac92 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Fri, 31 Oct 2014 16:10:22 +0100 Subject: [PATCH 01/21] Add environment mode to package. --- revel/build.go | 5 +++-- revel/package.go | 18 +++++++++++++++--- revel/package_run.bat.template | 2 +- revel/package_run.sh.template | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/revel/build.go b/revel/build.go index 47423db..bf6f2ba 100644 --- a/revel/build.go +++ b/revel/build.go @@ -31,12 +31,12 @@ func init() { } func buildApp(args []string) { - if len(args) != 2 { + if len(args) != 3 { fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long) return } - appImportPath, destPath := args[0], args[1] + appImportPath, destPath, mode := args[0], args[1], args[2] if !revel.Initialized { revel.Init("", appImportPath, "") } @@ -96,6 +96,7 @@ func buildApp(args []string) { tmplData, runShPath := map[string]interface{}{ "BinName": filepath.Base(app.BinaryPath), "ImportPath": appImportPath, + "Mode": mode, }, path.Join(destPath, "run.sh") mustRenderTemplate( diff --git a/revel/package.go b/revel/package.go index b909901..a4c62fe 100644 --- a/revel/package.go +++ b/revel/package.go @@ -2,19 +2,25 @@ package main import ( "fmt" - "github.com/revel/revel" "io/ioutil" "os" "path/filepath" + + "github.com/revel/revel" ) var cmdPackage = &Command{ - UsageLine: "package [import path]", + UsageLine: "package [import path] [run mode]", Short: "package a Revel application (e.g. for deployment)", Long: ` Package the Revel web application named by the given import path. This allows it to be deployed and run on a machine that lacks a Go installation. +The run mode is used to select which set of app.conf configuration should +apply and may be used to determine logic in the application itself. + +Run mode defaults to "prod". + For example: revel package github.com/revel/revel/samples/chat @@ -31,6 +37,12 @@ func packageApp(args []string) { return } + // Determine the run mode. + mode := "prod" + if len(args) >= 2 { + mode = args[1] + } + appImportPath := args[0] revel.Init("", appImportPath, "") @@ -42,7 +54,7 @@ func packageApp(args []string) { tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath)) panicOnError(err, "Failed to get temp dir") - buildApp([]string{args[0], tmpDir}) + buildApp([]string{args[0], tmpDir, mode}) // Create the zip file. archiveName := mustTarGzDir(destFile, tmpDir) diff --git a/revel/package_run.bat.template b/revel/package_run.bat.template index e73399b..f101d80 100644 --- a/revel/package_run.bat.template +++ b/revel/package_run.bat.template @@ -1,2 +1,2 @@ @echo off -{{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode prod +{{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode {{.Mode}} diff --git a/revel/package_run.sh.template b/revel/package_run.sh.template index ac0e12a..69bcaa6 100644 --- a/revel/package_run.sh.template +++ b/revel/package_run.sh.template @@ -1,3 +1,3 @@ #!/bin/sh SCRIPTPATH=$(cd "$(dirname "$0")"; pwd) -"$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode prod +"$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode {{.Mode}} From 3eccd6ae009a2d067d64a6559ffa5f2417d86287 Mon Sep 17 00:00:00 2001 From: Michael Eisendle Date: Thu, 5 Feb 2015 12:31:05 +0100 Subject: [PATCH 02/21] Switch to revel.Walk, the symlink-aware filepath.Walk helper --- revel/util.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/revel/util.go b/revel/util.go index 4240565..a3328f9 100644 --- a/revel/util.go +++ b/revel/util.go @@ -66,22 +66,10 @@ func mustChmod(filename string, mode os.FileMode) { // Additionally, the trailing ".template" is stripped from the file name. // Also, dot files and dot directories are skipped. func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error { - var fullSrcDir string - // Handle symlinked directories. - f, err := os.Lstat(srcDir) - if err == nil && f.Mode()&os.ModeSymlink == os.ModeSymlink { - fullSrcDir, err = os.Readlink(srcDir) - if err != nil { - panic(err) - } - } else { - fullSrcDir = srcDir - } - - return filepath.Walk(fullSrcDir, func(srcPath string, info os.FileInfo, err error) error { + return revel.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error { // Get the relative path from the source base, and the corresponding path in // the dest directory. - relSrcPath := strings.TrimLeft(srcPath[len(fullSrcDir):], string(os.PathSeparator)) + relSrcPath := strings.TrimLeft(srcPath[len(srcDir):], string(os.PathSeparator)) destPath := path.Join(destDir, relSrcPath) // Skip dot files and dot directories. @@ -124,7 +112,7 @@ func mustTarGzDir(destFilename, srcDir string) string { tarWriter := tar.NewWriter(gzipWriter) defer tarWriter.Close() - filepath.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error { + revel.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error { if info.IsDir() { return nil } From 95d62c1bbd402aa38b4db7446dd872619b536c3d Mon Sep 17 00:00:00 2001 From: Robert Lillack Date: Wed, 4 Mar 2015 22:09:53 +0100 Subject: [PATCH 03/21] Improve warning message when unable to generate route for action. --- harness/reflect.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/harness/reflect.go b/harness/reflect.go index f4ff4e6..dffcc94 100644 --- a/harness/reflect.go +++ b/harness/reflect.go @@ -433,7 +433,8 @@ func appendAction(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgImportPat var importPath string typeExpr := NewTypeExpr(pkgName, field.Type) if !typeExpr.Valid { - return // We didn't understand one of the args. Ignore this action. (Already logged) + log.Printf("Didn't understand argument '%s' of action %s. Ignoring.\n", name, getFuncName(funcDecl)) + return // We didn't understand one of the args. Ignore this action. } if typeExpr.PkgName != "" { var ok bool From 7792db37e2531549561540c85718db89d3e064ac Mon Sep 17 00:00:00 2001 From: Robert Nubel Date: Mon, 6 Jul 2015 23:22:34 -0500 Subject: [PATCH 04/21] Ignore missing temporary directories when booting. Otherwise, removing your `app/tmp` and `app/routes` folders prior to booting (e.g., if you add them to your .gitignore and use Travis) will cause unnecessary FATAL error messages. Addresses revel/revel#908. --- harness/build.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/harness/build.go b/harness/build.go index 31241e7..e7e51e5 100755 --- a/harness/build.go +++ b/harness/build.go @@ -173,7 +173,9 @@ func cleanDir(dir string) { tmpPath := path.Join(revel.AppPath, dir) f, err := os.Open(tmpPath) if err != nil { - revel.ERROR.Println("Failed to clean dir:", err) + if !os.IsNotExist(err) { + revel.ERROR.Println("Failed to clean dir:", err) + } } else { defer f.Close() infos, err := f.Readdir(0) From f122160a111500bce9e52c9337a9e208c049b7b0 Mon Sep 17 00:00:00 2001 From: Matthew Baird Date: Tue, 11 Aug 2015 14:45:02 -0700 Subject: [PATCH 05/21] fix issue where websockets don't work with SSL in dev mode. As the comment says, it's ok to skip the verify on the cert since this proxy is only used in dev mode. --- harness/harness.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/harness/harness.go b/harness/harness.go index df9f740..622c82d 100644 --- a/harness/harness.go +++ b/harness/harness.go @@ -204,7 +204,15 @@ func getFreePort() (port int) { // proxyWebsocket copies data between websocket client and server until one side // closes the connection. (ReverseProxy doesn't work with websocket requests.) func proxyWebsocket(w http.ResponseWriter, r *http.Request, host string) { - d, err := net.Dial("tcp", host) + var d net.Conn + var err error + if revel.HttpSsl { + // since this proxy isn't used in production, it's OK to set InsecureSkipVerify to true + // no need to add another configuration option. + d, err = tls.Dial("tcp", host, &tls.Config{InsecureSkipVerify: true}) + } else { + d, err = net.Dial("tcp", host) + } if err != nil { http.Error(w, "Error contacting backend server.", 500) revel.ERROR.Printf("Error dialing websocket backend %s: %v", host, err) From b2ec002b4de41422482014765534393fb6eb65c5 Mon Sep 17 00:00:00 2001 From: yuki2006 Date: Mon, 23 Nov 2015 02:46:03 +0900 Subject: [PATCH 06/21] fix : Failed to request test list when excepting status code 200 --- revel/test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/revel/test.go b/revel/test.go index 3128cd6..aa9d7fa 100644 --- a/revel/test.go +++ b/revel/test.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" "fmt" - "github.com/revel/revel" "github.com/revel/cmd/harness" "github.com/revel/modules/testrunner/app/controllers" + "github.com/revel/revel" "io" "io/ioutil" "net/http" @@ -117,13 +117,19 @@ You can add it to a run mode configuration with the following line: ) for i := 0; ; i++ { if resp, err = http.Get(baseUrl + "/@tests.list"); err == nil { - break + if resp.StatusCode == 200 { + break + } } if i < 3 { time.Sleep(3 * time.Second) continue } - errorf("Failed to request test list: %s", err) + if err != nil { + errorf("Failed to request test list: %s", err) + } else { + errorf("Failed to request test list: Not status code 200") + } } defer resp.Body.Close() json.NewDecoder(resp.Body).Decode(&testSuites) From eaf28d397fc01476f008d41672425d7121a70e54 Mon Sep 17 00:00:00 2001 From: Otto Bretz Date: Fri, 29 Apr 2016 09:23:21 +0200 Subject: [PATCH 07/21] Install package dependencies when building This speeds up recurring compiles a lot. --- harness/build.go | 1 + 1 file changed, 1 insertion(+) diff --git a/harness/build.go b/harness/build.go index e7e51e5..a3464d9 100755 --- a/harness/build.go +++ b/harness/build.go @@ -80,6 +80,7 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { versionLinkerFlags := fmt.Sprintf("-X %s/app.APP_VERSION \"%s\"", revel.ImportPath, appVersion) flags := []string{ "build", + "-i", "-ldflags", versionLinkerFlags, "-tags", buildTags, "-o", binName} From 4d8dbe0fe1b779d6e548dd3b0f1762da9e92dcc0 Mon Sep 17 00:00:00 2001 From: yyoshiki41 Date: Sun, 22 May 2016 11:35:42 +0900 Subject: [PATCH 08/21] Format go code --- harness/build.go | 1 - revel/build.go | 2 +- revel/run.go | 4 ++-- revel/test.go | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/harness/build.go b/harness/build.go index e7e51e5..46ea8c1 100755 --- a/harness/build.go +++ b/harness/build.go @@ -200,7 +200,6 @@ func cleanDir(dir string) { } } - // genSource renders the given template to produce source code, which it writes // to the given directory and file. func genSource(dir, filename, templateSource string, args map[string]interface{}) { diff --git a/revel/build.go b/revel/build.go index 45e7d07..151478b 100644 --- a/revel/build.go +++ b/revel/build.go @@ -7,8 +7,8 @@ import ( "path/filepath" "strings" - "github.com/revel/revel" "github.com/revel/cmd/harness" + "github.com/revel/revel" ) var cmdBuild = &Command{ diff --git a/revel/run.go b/revel/run.go index 891415b..7b477df 100644 --- a/revel/run.go +++ b/revel/run.go @@ -1,8 +1,8 @@ package main import ( - "github.com/revel/revel" "github.com/revel/cmd/harness" + "github.com/revel/revel" "strconv" ) @@ -65,7 +65,7 @@ func runApp(args []string) { } // Else, just build and run the app. - revel.TRACE.Println("Running in live build mode.") + revel.TRACE.Println("Running in live build mode.") app, err := harness.Build() if err != nil { errorf("Failed to build app: %s", err) diff --git a/revel/test.go b/revel/test.go index 3128cd6..b20e6ad 100644 --- a/revel/test.go +++ b/revel/test.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" "fmt" - "github.com/revel/revel" "github.com/revel/cmd/harness" "github.com/revel/modules/testrunner/app/controllers" + "github.com/revel/revel" "io" "io/ioutil" "net/http" From f9ba83270b6d172d20917cb177f36f34457988a1 Mon Sep 17 00:00:00 2001 From: Erik Selin Date: Mon, 26 May 2014 01:50:41 -0400 Subject: [PATCH 09/21] during cleanup we can also remove the routes folder. --- revel/clean.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/revel/clean.go b/revel/clean.go index 1af29bf..c957551 100644 --- a/revel/clean.go +++ b/revel/clean.go @@ -17,7 +17,7 @@ For example: revel clean github.com/revel/samples/chat -It removes the app/tmp directory. +It removes the app/tmp and app/routes directory. `, } @@ -37,12 +37,17 @@ func cleanApp(args []string) { return } - // Remove the app/tmp directory. - tmpDir := path.Join(appPkg.Dir, "app", "tmp") - fmt.Println("Removing:", tmpDir) - err = os.RemoveAll(tmpDir) - if err != nil { - fmt.Fprintln(os.Stderr, "Abort:", err) - return + dirs := []string{ + path.Join(appPkg.Dir, "app", "tmp"), + path.Join(appPkg.Dir, "app", "routes"), + } + + for _, dir := range dirs { + fmt.Println("Removing:", dir) + err = os.RemoveAll(dir) + if err != nil { + fmt.Fprintln(os.Stderr, "Abort:", err) + return + } } } From 63b4fbe6d98df17fd781735865d237b64f1c3159 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 21 May 2016 22:58:02 -0700 Subject: [PATCH 10/21] Updated variable name --- revel/clean.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/revel/clean.go b/revel/clean.go index c957551..06b26f8 100644 --- a/revel/clean.go +++ b/revel/clean.go @@ -37,12 +37,12 @@ func cleanApp(args []string) { return } - dirs := []string{ + purgeDirs := []string{ path.Join(appPkg.Dir, "app", "tmp"), path.Join(appPkg.Dir, "app", "routes"), } - for _, dir := range dirs { + for _, dir := range purgeDirs { fmt.Println("Removing:", dir) err = os.RemoveAll(dir) if err != nil { From 4f0489d0e633281a634652fa5597404718a0d174 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 21 May 2016 23:14:42 -0700 Subject: [PATCH 11/21] print only valid error msg --- harness/build.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/harness/build.go b/harness/build.go index 33cf26d..13b2fd9 100755 --- a/harness/build.go +++ b/harness/build.go @@ -181,7 +181,9 @@ func cleanDir(dir string) { defer f.Close() infos, err := f.Readdir(0) if err != nil { - revel.ERROR.Println("Failed to clean dir:", err) + if !os.IsNotExist(err) { + revel.ERROR.Println("Failed to clean dir:", err) + } } else { for _, info := range infos { path := path.Join(tmpPath, info.Name()) From e75cbc42cb5d8fcc13d4dbad86dcfe27650fbaec Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sun, 22 May 2016 13:49:19 -0700 Subject: [PATCH 12/21] updated msg and condition check --- revel/test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/revel/test.go b/revel/test.go index aa9d7fa..68f92d3 100644 --- a/revel/test.go +++ b/revel/test.go @@ -3,9 +3,6 @@ package main import ( "encoding/json" "fmt" - "github.com/revel/cmd/harness" - "github.com/revel/modules/testrunner/app/controllers" - "github.com/revel/revel" "io" "io/ioutil" "net/http" @@ -13,6 +10,10 @@ import ( "path" "strings" "time" + + "github.com/revel/cmd/harness" + "github.com/revel/modules/testrunner/app/controllers" + "github.com/revel/revel" ) var cmdTest = &Command{ @@ -117,7 +118,7 @@ You can add it to a run mode configuration with the following line: ) for i := 0; ; i++ { if resp, err = http.Get(baseUrl + "/@tests.list"); err == nil { - if resp.StatusCode == 200 { + if resp.StatusCode == http.StatusOK { break } } @@ -128,7 +129,7 @@ You can add it to a run mode configuration with the following line: if err != nil { errorf("Failed to request test list: %s", err) } else { - errorf("Failed to request test list: Not status code 200") + errorf("Failed to request test list: non-200 response") } } defer resp.Body.Close() From 6d12b806d3d0da51e958a1c0384c1709b07dbbd3 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sun, 22 May 2016 20:40:13 -0700 Subject: [PATCH 13/21] Validated PR #14 and fixed issues for the PR --- revel/build.go | 19 +++++++++++++++---- revel/package.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/revel/build.go b/revel/build.go index 95dbf47..33b9174 100644 --- a/revel/build.go +++ b/revel/build.go @@ -12,12 +12,17 @@ import ( ) var cmdBuild = &Command{ - UsageLine: "build [import path] [target path]", + UsageLine: "build [import path] [target path] [run mode]", Short: "build a Revel application (e.g. for deployment)", Long: ` Build the Revel web application named by the given import path. This allows it to be deployed and run on a machine that lacks a Go installation. +The run mode is used to select which set of app.conf configuration should +apply and may be used to determine logic in the application itself. + +Run mode defaults to "prod". + WARNING: The target path will be completely deleted, if it already exists! For example: @@ -31,14 +36,20 @@ func init() { } func buildApp(args []string) { - if len(args) != 3 { + if len(args) < 2 { fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long) return } - appImportPath, destPath, mode := args[0], args[1], args[2] + appImportPath, destPath, mode := args[0], args[1], "prod" + if len(args) >= 3 { + mode = args[2] + } + + fmt.Println("mode:", mode) + if !revel.Initialized { - revel.Init("", appImportPath, "") + revel.Init(mode, appImportPath, "") } // First, verify that it is either already empty or looks like a previous diff --git a/revel/package.go b/revel/package.go index f18161b..9c8272b 100644 --- a/revel/package.go +++ b/revel/package.go @@ -44,7 +44,7 @@ func packageApp(args []string) { } appImportPath := args[0] - revel.Init("", appImportPath, "") + revel.Init(mode, appImportPath, "") // Remove the archive if it already exists. destFile := filepath.Base(revel.BasePath) + ".tar.gz" From 2e0697adf22dbd37bf8030e9feb48ba1c4bc35f7 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Mon, 23 May 2016 22:31:35 -0700 Subject: [PATCH 14/21] Removed print statement --- revel/build.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/revel/build.go b/revel/build.go index 33b9174..e4231ab 100644 --- a/revel/build.go +++ b/revel/build.go @@ -46,8 +46,6 @@ func buildApp(args []string) { mode = args[2] } - fmt.Println("mode:", mode) - if !revel.Initialized { revel.Init(mode, appImportPath, "") } From 6ebd22021e9edad5273436af0e2813631f7cf01b Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Mon, 23 May 2016 22:54:44 -0700 Subject: [PATCH 15/21] #32 PR merge and code improvements --- harness/harness.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/harness/harness.go b/harness/harness.go index 622c82d..a6ae1cc 100644 --- a/harness/harness.go +++ b/harness/harness.go @@ -13,7 +13,6 @@ package harness import ( "crypto/tls" "fmt" - "github.com/revel/revel" "go/build" "io" "net" @@ -22,10 +21,11 @@ import ( "net/url" "os" "os/signal" - "path" "path/filepath" "strings" "sync/atomic" + + "github.com/revel/revel" ) var ( @@ -52,7 +52,7 @@ func renderError(w http.ResponseWriter, r *http.Request, err error) { // ServeHTTP handles all requests. // It checks for changes to app, rebuilds if necessary, and forwards the request. -func (hp *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func (h *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Don't rebuild the app for favicon requests. if lastRequestHadError > 0 && r.URL.Path == "/favicon.ico" { return @@ -71,18 +71,19 @@ func (hp *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Reverse proxy the request. // (Need special code for websockets, courtesy of bradfitz) if strings.EqualFold(r.Header.Get("Upgrade"), "websocket") { - proxyWebsocket(w, r, hp.serverHost) + proxyWebsocket(w, r, h.serverHost) } else { - hp.proxy.ServeHTTP(w, r) + h.proxy.ServeHTTP(w, r) } } -// Return a reverse proxy that forwards requests to the given port. +// NewHarness method returns a reverse proxy that forwards requests +// to the given port. func NewHarness() *Harness { // Get a template loader to render errors. // Prefer the app's views/errors directory, and fall back to the stock error pages. revel.MainTemplateLoader = revel.NewTemplateLoader( - []string{path.Join(revel.RevelPath, "templates")}) + []string{filepath.Join(revel.RevelPath, "templates")}) revel.MainTemplateLoader.Refresh() addr := revel.HttpAddr @@ -101,12 +102,12 @@ func NewHarness() *Harness { port = getFreePort() } - serverUrl, _ := url.ParseRequestURI(fmt.Sprintf(scheme+"://%s:%d", addr, port)) + serverURL, _ := url.ParseRequestURI(fmt.Sprintf(scheme+"://%s:%d", addr, port)) harness := &Harness{ port: port, - serverHost: serverUrl.String()[len(scheme+"://"):], - proxy: httputil.NewSingleHostReverseProxy(serverUrl), + serverHost: serverURL.String()[len(scheme+"://"):], + proxy: httputil.NewSingleHostReverseProxy(serverURL), } if revel.HttpSsl { @@ -117,7 +118,7 @@ func NewHarness() *Harness { return harness } -// Rebuild the Revel application and run it on the given port. +// Refresh method rebuilds the Revel application and run it on the given port. func (h *Harness) Refresh() (err *revel.Error) { if h.app != nil { h.app.Kill() @@ -140,10 +141,14 @@ func (h *Harness) Refresh() (err *revel.Error) { return } +// WatchDir method returns false to file matches with doNotWatch +// otheriwse true func (h *Harness) WatchDir(info os.FileInfo) bool { return !revel.ContainsString(doNotWatch, info.Name()) } +// WatchFile method returns true given filename HasSuffix of ".go" +// otheriwse false func (h *Harness) WatchFile(filename string) bool { return strings.HasSuffix(filename, ".go") } @@ -204,10 +209,13 @@ func getFreePort() (port int) { // proxyWebsocket copies data between websocket client and server until one side // closes the connection. (ReverseProxy doesn't work with websocket requests.) func proxyWebsocket(w http.ResponseWriter, r *http.Request, host string) { - var d net.Conn - var err error + var ( + d net.Conn + err error + ) if revel.HttpSsl { - // since this proxy isn't used in production, it's OK to set InsecureSkipVerify to true + // since this proxy isn't used in production, + // it's OK to set InsecureSkipVerify to true // no need to add another configuration option. d, err = tls.Dial("tcp", host, &tls.Config{InsecureSkipVerify: true}) } else { From 5282ce262bd595ae25032f1fb70b41547c8d2c2c Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Wed, 25 May 2016 22:49:11 -0700 Subject: [PATCH 16/21] revel/revel#1014 added check for path like ../dir & ./dir for new command --- revel/new.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/revel/new.go b/revel/new.go index 7252226..fadf268 100644 --- a/revel/new.go +++ b/revel/new.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/revel/revel" ) @@ -111,7 +112,11 @@ func initGoPaths() { func setApplicationPath(args []string) { var err error importPath = args[0] - if filepath.IsAbs(importPath) { + + // revel/revel#1014 validate relative path, we cannot use built-in functions + // since Go import path is valid relative path too. + // so check basic part of the path, which is "." + if filepath.IsAbs(importPath) || strings.HasPrefix(importPath, ".") { errorf("Abort: '%s' looks like a directory. Please provide a Go import path instead.", importPath) } From b00267450ee4fe1bc3ea4f1ada2c60e83355ae01 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Thu, 26 May 2016 17:14:53 -0700 Subject: [PATCH 17/21] default run mode value updated dev --- revel/build.go | 4 ++-- revel/package.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/revel/build.go b/revel/build.go index e4231ab..315ec70 100644 --- a/revel/build.go +++ b/revel/build.go @@ -21,7 +21,7 @@ This allows it to be deployed and run on a machine that lacks a Go installation. The run mode is used to select which set of app.conf configuration should apply and may be used to determine logic in the application itself. -Run mode defaults to "prod". +Run mode defaults to "dev". WARNING: The target path will be completely deleted, if it already exists! @@ -41,7 +41,7 @@ func buildApp(args []string) { return } - appImportPath, destPath, mode := args[0], args[1], "prod" + appImportPath, destPath, mode := args[0], args[1], "dev" if len(args) >= 3 { mode = args[2] } diff --git a/revel/package.go b/revel/package.go index 9c8272b..41ea785 100644 --- a/revel/package.go +++ b/revel/package.go @@ -19,7 +19,7 @@ This allows it to be deployed and run on a machine that lacks a Go installation. The run mode is used to select which set of app.conf configuration should apply and may be used to determine logic in the application itself. -Run mode defaults to "prod". +Run mode defaults to "dev". For example: @@ -38,7 +38,7 @@ func packageApp(args []string) { } // Determine the run mode. - mode := "prod" + mode := "dev" if len(args) >= 2 { mode = args[1] } From b85dd76b3efb094a382bffac8bae1c1e9d49ec90 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Thu, 26 May 2016 17:23:52 -0700 Subject: [PATCH 18/21] revel/revel#1004 choose go path relative to current working directory --- revel/new.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/revel/new.go b/revel/new.go index fadf268..c874898 100644 --- a/revel/new.go +++ b/revel/new.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "go/build" + "log" "math/rand" "os" "os/exec" @@ -61,6 +62,8 @@ 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() @@ -97,9 +100,6 @@ func initGoPaths() { "Please refer to http://golang.org/doc/code.html to configure your Go environment.") } - // set go src path - srcRoot = filepath.Join(filepath.SplitList(gopath)[0], "src") - // check for go executable var err error gocmd, err = exec.LookPath("go") @@ -107,6 +107,28 @@ func initGoPaths() { errorf("Go executable not found in PATH.") } + // revel/revel#1004 choose go path relative to current working directory + workingDir, _ := os.Getwd() + goPathList := filepath.SplitList(gopath) + for _, path := range goPathList { + if strings.HasPrefix(strings.ToLower(workingDir), strings.ToLower(path)) { + srcRoot = path + break + } + + path, _ = filepath.EvalSymlinks(path) + if len(path) > 0 && strings.HasPrefix(strings.ToLower(workingDir), strings.ToLower(path)) { + srcRoot = path + break + } + } + + if len(srcRoot) == 0 { + revel.ERROR.Fatalln("Abort: could not create a Revel application outside of GOPATH.") + } + + // set go src path + srcRoot = filepath.Join(srcRoot, "src") } func setApplicationPath(args []string) { From 1f8f1065730430f80669d1d62fe9c03b436124a9 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Fri, 27 May 2016 23:30:14 -0700 Subject: [PATCH 19/21] Related changes by #20 for Walk method --- harness/reflect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harness/reflect.go b/harness/reflect.go index dffcc94..4c7df99 100644 --- a/harness/reflect.go +++ b/harness/reflect.go @@ -96,7 +96,7 @@ func ProcessSource(roots []string) (*SourceInfo, *revel.Error) { } // Start walking the directory tree. - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + _ = revel.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { log.Println("Error scanning app source:", err) return nil From ced303ede6f6bfc6bb710ede5998bccbb060f46c Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 28 May 2016 11:07:43 -0700 Subject: [PATCH 20/21] #19 Revel version command added --- revel/rev.go | 6 ++++-- revel/version.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 revel/version.go diff --git a/revel/rev.go b/revel/rev.go index f793d8f..6c234b8 100644 --- a/revel/rev.go +++ b/revel/rev.go @@ -4,7 +4,6 @@ package main import ( "flag" "fmt" - "github.com/agtorre/gocolorize" "io" "math/rand" "os" @@ -12,9 +11,11 @@ import ( "strings" "text/template" "time" + + "github.com/agtorre/gocolorize" ) -// Cribbed from the genius organization of the "go" command. +// Command structure cribbed from the genius organization of the "go" command. type Command struct { Run func(args []string) UsageLine, Short, Long string @@ -36,6 +37,7 @@ var commands = []*Command{ cmdPackage, cmdClean, cmdTest, + cmdVersion, } func main() { diff --git a/revel/version.go b/revel/version.go new file mode 100644 index 0000000..b81abb7 --- /dev/null +++ b/revel/version.go @@ -0,0 +1,34 @@ +// 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 main + +import ( + "fmt" + "runtime" + + "github.com/revel/revel" +) + +var cmdVersion = &Command{ + UsageLine: "version", + Short: "displays the Revel Framework and Go version", + Long: ` +Displays the Revel Framework and Go version. + +For example: + + revel version +`, +} + +func init() { + cmdVersion.Run = versionApp +} + +func versionApp(args []string) { + fmt.Printf("Version(s):") + fmt.Printf("\n Revel v%v (%v)", revel.VERSION, revel.BUILD_DATE) + fmt.Printf("\n %s %s/%s\n\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) +} From e3f469739c6a42c28ea42353dba3fdb334d282ea Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Tue, 31 May 2016 22:58:56 -0700 Subject: [PATCH 21/21] golint taken care for version name --- revel/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revel/version.go b/revel/version.go index b81abb7..7343b1c 100644 --- a/revel/version.go +++ b/revel/version.go @@ -29,6 +29,6 @@ func init() { func versionApp(args []string) { fmt.Printf("Version(s):") - fmt.Printf("\n Revel v%v (%v)", revel.VERSION, revel.BUILD_DATE) + fmt.Printf("\n Revel v%v (%v)", revel.Version, revel.BuildDate) fmt.Printf("\n %s %s/%s\n\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) }