From cfa24b91f5ad81cae789673e7b0a0258da40d0d1 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 1 Nov 2015 17:50:46 +0100 Subject: [PATCH] Fix bug on refresh and add relay --- controllers/relay.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/controllers/relay.go b/controllers/relay.go index cc6f565..acd3ac1 100644 --- a/controllers/relay.go +++ b/controllers/relay.go @@ -7,6 +7,7 @@ import ( "datahouse/models/variables" "datahouse/models/relay" "strings" + "time" ) @@ -60,7 +61,7 @@ func (c *ViewRelayController) Post() { if r.Id != 0 { ret += r.Mac+"/" if r.IpAddress != "" { - getRep, err := httplib.Get("http://"+r.IpAddress+"/status").String() + getRep, err := httplib.Get("http://"+r.IpAddress+"/status").SetTimeout(3 * time.Second, 3 * time.Second).String() if err == nil { ret += getRep } else { @@ -82,12 +83,6 @@ type AddRelayController struct { beego.Controller } -func (c *AddRelayController) Prepare() { - sess := c.GetSession(variables.SessionName) - if sess == nil { - c.Redirect(variables.LoginRoute, 302) - } -} func (c *AddRelayController) Get() { ip := strings.Split(c.Ctx.Request.RemoteAddr, ":")[0] @@ -119,7 +114,7 @@ func (c *CommandRelayController) Post() { mac := c.Ctx.Input.Param(":sensor") r := relay.GetRelayByMac(mac) if r.Id != 0 { - httplib.Get("http://"+r.IpAddress+"/toggle").String() + httplib.Get("http://"+r.IpAddress+"/toggle").SetTimeout(3 * time.Second, 3 * time.Second).String() } c.Ctx.Output.Body([]byte(""))