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(""))