Browse Source

fix autoupdate to work with the new API, go fmt

Alan Shreve 12 years ago
parent
commit
055ca06302

+ 1 - 1
src/ngrok/client/controller.go

@@ -168,7 +168,7 @@ func (ctl *Controller) Run(opts *Options) {
 		}
 	}
 
-	ctl.Go(func() { autoUpdate(ctl, opts.authtoken) })
+	ctl.Go(func() { autoUpdate(state, opts.authtoken) })
 
 	reg := &msg.RegMsg{
 		Protocol:  opts.protocol,

+ 2 - 0
src/ngrok/client/model.go

@@ -106,6 +106,8 @@ func (c ClientModel) GetBytesInMetrics() (metrics.Counter, metrics.Histogram) {
 func (c ClientModel) GetBytesOutMetrics() (metrics.Counter, metrics.Histogram) {
 	return c.metrics.bytesOutCount, c.metrics.bytesOut
 }
+func (c ClientModel) SetUpdateStatus(updateStatus mvc.UpdateStatus) { c.updateStatus = updateStatus; c.update() }
+
 
 // mvc.Model interface
 func (c *ClientModel) PlayRequest(tunnel mvc.Tunnel, payload []byte) {

+ 1 - 0
src/ngrok/client/mvc/state.go

@@ -43,4 +43,5 @@ type State interface {
 	GetConnectionMetrics() (metrics.Meter, metrics.Timer)
 	GetBytesInMetrics() (metrics.Counter, metrics.Histogram)
 	GetBytesOutMetrics() (metrics.Counter, metrics.Histogram)
+	SetUpdateStatus(UpdateStatus)
 }

+ 1 - 1
src/ngrok/client/update_debug.go

@@ -7,5 +7,5 @@ import (
 )
 
 // no auto-updating in debug mode
-func autoUpdate(ctl mvc.Controller, token string) {
+func autoUpdate(state mvc.State, token string) {
 }

+ 9 - 11
src/ngrok/client/update_release.go

@@ -18,7 +18,7 @@ const (
 	checkEndpoint  = "https://dl.ngrok.com/update/check"
 )
 
-func progressWatcher(s *State, ctl *ui.Controller, progress chan int, complete chan int) {
+func progressWatcher(s mvc.State, progress chan int, complete chan int) {
 	for {
 		select {
 		case pct, ok := <-progress:
@@ -26,22 +26,21 @@ func progressWatcher(s *State, ctl *ui.Controller, progress chan int, complete c
 				close(complete)
 				return
 			} else if pct == 100 {
-				s.update = ui.UpdateInstalling
-				ctl.Update(s)
+				s.SetUpdateStatus(mvc.UpdateInstalling)
 				close(complete)
 				return
 			} else {
 				if pct%25 == 0 {
 					log.Info("Downloading update %d%% complete", pct)
 				}
-				s.update = ui.UpdateStatus(pct)
-				ctl.Update(s)
+				s.SetUpdateStatus(mvc.UpdateStatus(pct))
 			}
 		}
 	}
 }
 
-func autoUpdate(s *State, ctl *ui.Controller, token string) {
+func autoUpdate(s mvc.State, token string) {
+		log.Info("autoUpdate running")
 	tryAgain := true
 
 	params := make(url.Values)
@@ -75,7 +74,7 @@ func autoUpdate(s *State, ctl *ui.Controller, token string) {
 		download := update.NewDownload(updateUrl)
 		downloadComplete := make(chan int)
 
-		go progressWatcher(s, ctl, download.Progress, downloadComplete)
+		go progressWatcher(s, download.Progress, downloadComplete)
 
 		log.Info("Trying to update . . .")
 		err, errRecover := download.GetAndUpdate()
@@ -98,20 +97,19 @@ func autoUpdate(s *State, ctl *ui.Controller, token string) {
 			resp.Body.Close()
 
 			// tell the user to update manually
-			s.update = ui.UpdateAvailable
+			s.SetUpdateStatus(mvc.UpdateAvailable)
 		} else {
 			if !download.Available {
 				// this is the way the server tells us to update manually
 				log.Info("Server wants us to update manually")
-				s.update = ui.UpdateAvailable
+				s.SetUpdateStatus(mvc.UpdateAvailable)
 			} else {
 				// tell the user the update is ready
 				log.Info("Update ready!")
-				s.update = ui.UpdateReady
+				s.SetUpdateStatus(mvc.UpdateReady)
 			}
 		}
 
-		ctl.Update(s)
 		return
 	}
 

+ 2 - 2
src/ngrok/conn/conn.go

@@ -45,8 +45,8 @@ func Listen(addr, typ string, tlsCfg *tls.Config) (l *Listener, err error) {
 	}
 
 	l = &Listener{
-		Addr: listener.Addr(),
-		Conns:   make(chan Conn),
+		Addr:  listener.Addr(),
+		Conns: make(chan Conn),
 	}
 
 	go func() {

+ 1 - 4
src/ngrok/server/cli.go

@@ -17,10 +17,7 @@ func parseArgs() *Options {
 	httpsAddr := flag.String("httpsAddr", ":443", "Public address listening for HTTPS connections, emptry string to disable")
 	tunnelAddr := flag.String("tunnelAddr", ":4443", "Public address listening for ngrok client")
 	domain := flag.String("domain", "ngrok.com", "Domain where the tunnels are hosted")
-	logto := flag.String(
-		"log",
-		"stdout",
-		"Write log messages to this file. 'stdout' and 'none' have special meanings")
+	logto := flag.String("log", "stdout", "Write log messages to this file. 'stdout' and 'none' have special meanings")
 
 	flag.Parse()