Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created March 12, 2015 11:29
Show Gist options
  • Select an option

  • Save kaneshin/db022b28faa31cb0b974 to your computer and use it in GitHub Desktop.

Select an option

Save kaneshin/db022b28faa31cb0b974 to your computer and use it in GitHub Desktop.
diff --git a/revel/run.go b/revel/run.go
index 0edc673..289349b 100644
--- a/revel/run.go
+++ b/revel/run.go
@@ -3,7 +3,9 @@ package main
import (
"github.com/revel/revel"
"github.com/revel/revel/harness"
+ "os/exec"
"strconv"
+ "time"
)
var cmdRun = &Command{
@@ -47,13 +49,20 @@ func runApp(args []string) {
// Determine the override port, if any.
port := revel.HttpPort
- if len(args) == 3 {
+ if len(args) >= 3 {
var err error
if port, err = strconv.Atoi(args[2]); err != nil {
errorf("Failed to parse port as integer: %s", args[2])
}
}
+ custom := true
+ if len(args) >= 4 {
+ if args[3] == "false" {
+ custom = false
+ }
+ }
+
revel.INFO.Printf("Running %s (%s) in %s mode\n", revel.AppName, revel.ImportPath, mode)
revel.TRACE.Println("Base path:", revel.BasePath)
@@ -64,10 +73,30 @@ func runApp(args []string) {
}
// Else, just build and run the app.
- app, err := harness.Build()
+ app, err := harness.CustomBuild(custom)
if err != nil {
errorf("Failed to build app: %s", err)
}
+
+ timeout := make(chan bool, 1)
+ go func() {
+ for {
+ select {
+ case <-timeout:
+ pstr := strconv.Itoa(port)
+ cmd := exec.Command("curl", "localhost:"+pstr)
+ if err := cmd.Run(); err != nil {
+ errorf("Failed to curl localhost:%s %s", port, err)
+ }
+ revel.INFO.Println("curl localhost:", pstr)
+ }
+ }
+ }()
+ go func() {
+ time.Sleep(1 * time.Second)
+ timeout <- true
+ }()
+
app.Port = port
app.Cmd().Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment