Commits

Liam Staskawicz  committed e7979b4

updated go fmt - doesn't compile against go 1 at the moment.

  • Participants
  • Parent commits 2863e5d

Comments (0)

Files changed (3)

File src/compilation.go

 func SourceModifiedMoreRecentlyThan(root string, modtime time.Time) bool {
 	mostRecentModTime := modtime
 	filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
-	    thistime := info.ModTime()
-	    if mostRecentModTime.After(modtime) {
-    		return filepath.SkipDir // don't bother
-    	}
-    	if thistime.After(modtime) {
-    	    ext := filepath.Ext(info.Name())
-    	    // TODO - make extensions configurable
-    	    if ext == ".go" || ext == ".html" || ext == ".tmpl" {
-    	        mostRecentModTime = thistime
-    	    }
-    	}
-	    return nil
-    });
+		thistime := info.ModTime()
+		if mostRecentModTime.After(modtime) {
+			return filepath.SkipDir // don't bother
+		}
+		if thistime.After(modtime) {
+			ext := filepath.Ext(info.Name())
+			// TODO - make extensions configurable
+			if ext == ".go" || ext == ".html" || ext == ".tmpl" {
+				mostRecentModTime = thistime
+			}
+		}
+		return nil
+	})
 	return mostRecentModTime.After(modtime)
 }

File src/config.go

 func LoadConfig(configpath string) *Config {
 	b, err := ioutil.ReadFile(path.Join(configpath, "app.json"))
 	if err != nil {
-        log.Fatal(err.Error())
+		log.Fatal(err.Error())
 	}
 
 	// config file defaults, overwritten by anything in the real file
 	conf := &Config{
-		"127.0.0.1:8080",   // DevServerAddress
-		"127.0.0.1:8081",   // AppAddress
-		"",                 // App
-		100000000,          // CrashTimeout
-		time.Second / 2,    // StartupTime
-		"",                 // LogFile
+		"127.0.0.1:8080", // DevServerAddress
+		"127.0.0.1:8081", // AppAddress
+		"",               // App
+		100000000,        // CrashTimeout
+		time.Second / 2,  // StartupTime
+		"",               // LogFile
 	}
 
 	if err = json.Unmarshal(b, &conf); err != nil {
-        log.Fatal("ReadFile: ", err.Error())
+		log.Fatal("ReadFile: ", err.Error())
 	}
 
 	if conf.App == "" {
 import (
 	"bytes"
 	"flag"
-	"log"
 	"io"
+	"log"
 	"net/http"
 	"net/http/httputil"
 	"net/url"
 	"os"
 	"os/exec"
 	"path/filepath"
-    "time"
+	"time"
 )
 
 type Reloader struct {
-	reverseProxy    *httputil.ReverseProxy
-	config          *Config
-	appRoot         string
-	appCmd          *exec.Cmd
-	appOutBuf       bytes.Buffer
+	reverseProxy *httputil.ReverseProxy
+	config       *Config
+	appRoot      string
+	appCmd       *exec.Cmd
+	appOutBuf    bytes.Buffer
 }
 
 func main() {
 	conf := LoadConfig(approot)
 
 	// fire up the app under development
-	proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: conf.AppAddress, Path: "/"})
-	reloader := &Reloader{config: conf, reverseProxy: proxy, appRoot: approot}
+	proxy := httputil.NewSingleHostReverseProxy(
+		&url.URL{
+			Scheme: "http",
+			Host:   conf.AppAddress,
+			Path:   "/",
+		},
+	)
+	reloader := &Reloader{
+		config:       conf,
+		reverseProxy: proxy,
+		appRoot:      approot,
+	}
 
 	// and start proxying requests to it
 	http.Handle("/", reloader)
-	println("serving", conf.DevServerAddress)
+	log.Println("serving", conf.DevServerAddress)
 	if err := http.ListenAndServe(conf.DevServerAddress, nil); err != nil {
 		log.Fatal("ListenAndServe: ", err.Error())
 	}
 		}
 	}
 	r.ensureTargetIsRunning(appPath)
-    if !r.checkForTargetErrors(w) {
-        r.reverseProxy.ServeHTTP(w, req)
-    }
-    
-    // TODO - figure out how to write errors back to browser
-    // after app fails while serving request. currently, fails because the content-length
-    // header gets set somewhere, and we cann't write any more bytes to the connection.
-    // r.checkForTargetErrors(w)
-    // r.appOutBuf.Reset()
+	if !r.checkForTargetErrors(w) {
+		r.reverseProxy.ServeHTTP(w, req)
+	}
+
+	// TODO - figure out how to write errors back to browser
+	// after app fails while serving request. currently, fails because the content-length
+	// header gets set somewhere, and we cann't write any more bytes to the connection.
+	// r.checkForTargetErrors(w)
+	// r.appOutBuf.Reset()
 }
 
 // build a project
 	if err := r.appCmd.Start(); err != nil {
 		log.Fatal("couldn't start app:", err.Error())
 	}
-    time.Sleep(r.config.StartupTime) // give it a moment to start up...surely there's a better way?
+	time.Sleep(r.config.StartupTime) // give it a moment to start up...surely there's a better way?
 }
 
 func (r *Reloader) checkForTargetErrors(errDest io.Writer) bool {
-    // check for error
-    waitmsg, err := r.appCmd.Process.Wait(os.WNOHANG)
-    // TODO - on darwin, even if WaitStatus is 256, Stopped() returns false...
-    // just check directly for now, but it's not nice
-    if err != nil || waitmsg.WaitStatus != 0 { //}.Stopped()
-        errDest.Write([]byte("so sorry, not running anymore:\n\n"))
-        // NOTE: write outbuf bytes, but leave them in the buffer so we still
-        // keep the same error message in case we see subsequent reloads before
-        // the error is resolved
-        errDest.Write(r.appOutBuf.Bytes())
-        return true;
-    }
-    r.appOutBuf.Reset()
-    return false
+	// check for error
+	waitmsg, err := r.appCmd.Process.Wait(os.WNOHANG)
+	// TODO - on darwin, even if WaitStatus is 256, Stopped() returns false...
+	// just check directly for now, but it's not nice
+	if err != nil || waitmsg.WaitStatus != 0 { //}.Stopped()
+		errDest.Write([]byte("so sorry, not running anymore:\n\n"))
+		// NOTE: write outbuf bytes, but leave them in the buffer so we still
+		// keep the same error message in case we see subsequent reloads before
+		// the error is resolved
+		errDest.Write(r.appOutBuf.Bytes())
+		return true
+	}
+	r.appOutBuf.Reset()
+	return false
 }