Make it go getable
This commit is contained in:
parent
d33e5f312f
commit
c363e309c1
|
|
@ -6,10 +6,10 @@ import (
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/sensor"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||||
"datahouse/models/temperature"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
temperatureTmp "datahouse/models/temperature/temp"
|
temperatureTmp "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature/temp"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddTempController struct {
|
type AddTempController struct {
|
||||||
|
|
@ -21,7 +21,7 @@ func (c *AddTempController) Prepare() {
|
||||||
if sess != nil {
|
if sess != nil {
|
||||||
c.Data["IsAuthentificated"] = true
|
c.Data["IsAuthentificated"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["version"] = variables.Version
|
c.Data["version"] = variables.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/sensor"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||||
temperatureTmp "datahouse/models/temperature/temp"
|
temperatureTmp "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature/temp"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/user"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoginController struct {
|
type LoginController struct {
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,16 @@ import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/httplib"
|
"github.com/astaxie/beego/httplib"
|
||||||
|
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||||
"datahouse/models/relay"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
type ViewRelayController struct {
|
type ViewRelayController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +26,7 @@ func (c *ViewRelayController) Prepare() {
|
||||||
c.Data["IsAuthentificated"] = true
|
c.Data["IsAuthentificated"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["IsViewRelay"] = true;
|
c.Data["IsViewRelay"] = true
|
||||||
c.Data["version"] = variables.Version
|
c.Data["version"] = variables.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,15 +48,14 @@ func (c *ViewRelayController) Get() {
|
||||||
c.TplNames = "relay.tpl"
|
c.TplNames = "relay.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *ViewRelayController) Post() {
|
func (c *ViewRelayController) Post() {
|
||||||
mac := c.Ctx.Input.Param(":sensor")
|
mac := c.Ctx.Input.Param(":sensor")
|
||||||
r := relay.GetRelayByMac(mac)
|
r := relay.GetRelayByMac(mac)
|
||||||
ret := ""
|
ret := ""
|
||||||
if r.Id != 0 {
|
if r.Id != 0 {
|
||||||
ret += r.Mac+"/"
|
ret += r.Mac + "/"
|
||||||
if r.IpAddress != "" {
|
if r.IpAddress != "" {
|
||||||
getRep, err := httplib.Get("http://"+r.IpAddress+"/status").SetTimeout(3 * time.Second, 3 * time.Second).String()
|
getRep, err := httplib.Get("http://"+r.IpAddress+"/status").SetTimeout(3*time.Second, 3*time.Second).String()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret += getRep
|
ret += getRep
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -72,9 +66,6 @@ func (c *ViewRelayController) Post() {
|
||||||
c.Ctx.Output.Body([]byte(ret))
|
c.Ctx.Output.Body([]byte(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
@ -83,7 +74,6 @@ type AddRelayController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *AddRelayController) Get() {
|
func (c *AddRelayController) Get() {
|
||||||
ip := strings.Split(c.Ctx.Request.RemoteAddr, ":")[0]
|
ip := strings.Split(c.Ctx.Request.RemoteAddr, ":")[0]
|
||||||
mac := c.Ctx.Input.Param(":sensor")
|
mac := c.Ctx.Input.Param(":sensor")
|
||||||
|
|
@ -92,9 +82,6 @@ func (c *AddRelayController) Get() {
|
||||||
c.Ctx.Output.Body([]byte("OK"))
|
c.Ctx.Output.Body([]byte("OK"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
@ -114,7 +101,7 @@ func (c *CommandRelayController) Post() {
|
||||||
mac := c.Ctx.Input.Param(":sensor")
|
mac := c.Ctx.Input.Param(":sensor")
|
||||||
r := relay.GetRelayByMac(mac)
|
r := relay.GetRelayByMac(mac)
|
||||||
if r.Id != 0 {
|
if r.Id != 0 {
|
||||||
httplib.Get("http://"+r.IpAddress+"/toggle").SetTimeout(3 * time.Second, 3 * time.Second).String()
|
httplib.Get("http://"+r.IpAddress+"/toggle").SetTimeout(3*time.Second, 3*time.Second).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Ctx.Output.Body([]byte(""))
|
c.Ctx.Output.Body([]byte(""))
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/relay"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||||
"datahouse/models/sensor"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||||
"datahouse/models/temperature"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -48,8 +48,6 @@ func (c *SensorsController) Post() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (c *SensorsController) PostTempSensors() {
|
func (c *SensorsController) PostTempSensors() {
|
||||||
description := c.Input().Get("description")
|
description := c.Input().Get("description")
|
||||||
mac := c.Input().Get("mac")
|
mac := c.Input().Get("mac")
|
||||||
|
|
@ -73,8 +71,6 @@ func (c *SensorsController) PostTempSensors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (c *SensorsController) PostRelay() {
|
func (c *SensorsController) PostRelay() {
|
||||||
description := c.Input().Get("description")
|
description := c.Input().Get("description")
|
||||||
mac := c.Input().Get("mac")
|
mac := c.Input().Get("mac")
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/user"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserController struct {
|
type UserController struct {
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
||||||
"datahouse/models/sensor"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/sensor"
|
||||||
"datahouse/models/temperature"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -20,7 +20,7 @@ func (c *ViewTempController) Prepare() {
|
||||||
if sess != nil {
|
if sess != nil {
|
||||||
c.Data["IsAuthentificated"] = true
|
c.Data["IsAuthentificated"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["IsViewTemp"] = true
|
c.Data["IsViewTemp"] = true
|
||||||
c.Data["version"] = variables.Version
|
c.Data["version"] = variables.Version
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -1,10 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
_ "datahouse/models/temperature"
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"datahouse/models/user"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||||
_ "datahouse/routers"
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,21 @@ package relay
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
"datahouse/models/utils"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type RelayTable struct {
|
type RelayTable struct {
|
||||||
Id int64
|
Id int64
|
||||||
Mac string
|
Mac string
|
||||||
Description string
|
Description string
|
||||||
IpAddress string
|
IpAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
orm.RegisterModel(new(RelayTable))
|
orm.RegisterModel(new(RelayTable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func GetRelayByMac(relayMac string) *RelayTable {
|
func GetRelayByMac(relayMac string) *RelayTable {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
o.Using(database.Alias)
|
o.Using(database.Alias)
|
||||||
|
|
@ -52,7 +48,7 @@ func GetAllRelay() []RelayTable {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, m := range maps {
|
for _, m := range maps {
|
||||||
r := new(RelayTable)
|
r := new(RelayTable)
|
||||||
r.Id = utils.GetInt(m, "Id")
|
r.Id = utils.GetInt(m, "Id")
|
||||||
r.Mac = utils.GetString(m, "Mac")
|
r.Mac = utils.GetString(m, "Mac")
|
||||||
r.Description = utils.GetString(m, "Description")
|
r.Description = utils.GetString(m, "Description")
|
||||||
r.IpAddress = utils.GetString(m, "IpAddress")
|
r.IpAddress = utils.GetString(m, "IpAddress")
|
||||||
|
|
@ -72,7 +68,7 @@ func GetRelay(id int64) *RelayTable {
|
||||||
_, err := o.QueryTable(new(RelayTable)).Filter("Id", id).Values(&maps)
|
_, err := o.QueryTable(new(RelayTable)).Filter("Id", id).Values(&maps)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, m := range maps {
|
for _, m := range maps {
|
||||||
ret.Id = utils.GetInt(m, "Id")
|
ret.Id = utils.GetInt(m, "Id")
|
||||||
ret.Mac = utils.GetString(m, "Mac")
|
ret.Mac = utils.GetString(m, "Mac")
|
||||||
ret.Description = utils.GetString(m, "Description")
|
ret.Description = utils.GetString(m, "Description")
|
||||||
ret.IpAddress = utils.GetString(m, "IpAddress")
|
ret.IpAddress = utils.GetString(m, "IpAddress")
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package sensor
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
"datahouse/models/utils"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SensorTable struct {
|
type SensorTable struct {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package temp
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
"datahouse/models/utils"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package temperature
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
"datahouse/models/utils"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
"datahouse/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
"datahouse/models/utils"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,18 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
RootRoute = "/"
|
RootRoute = "/"
|
||||||
|
|
||||||
AddTempRoute = "/add/temp/"+sensorMacRegex+"/:val([0-9]+)"
|
AddTempRoute = "/add/temp/" + sensorMacRegex + "/:val([0-9]+)"
|
||||||
AddRelayRoute = "/add/relay/"+sensorMacRegex
|
AddRelayRoute = "/add/relay/" + sensorMacRegex
|
||||||
|
|
||||||
ViewTempRoute = "/view/temp"
|
ViewTempRoute = "/view/temp"
|
||||||
ViewRelaysRoute = "/view/relay"
|
ViewRelaysRoute = "/view/relay"
|
||||||
ViewRelayRoute = "/view/relay/"+sensorMacRegex
|
ViewRelayRoute = "/view/relay/" + sensorMacRegex
|
||||||
|
|
||||||
CommandRelayRoute = "/command/relay/"+sensorMacRegex
|
CommandRelayRoute = "/command/relay/" + sensorMacRegex
|
||||||
|
|
||||||
SensorsRoute = "/sensors"
|
SensorsRoute = "/sensors"
|
||||||
LoginRoute = "/login"
|
LoginRoute = "/login"
|
||||||
UserRoute = "/user"
|
UserRoute = "/user"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"datahouse/controllers"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/controllers"
|
||||||
"datahouse/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ $("#toggleButton").click(function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/command/relay/"+$(".jumbotron img").attr("id"),
|
url: "/command/relay/"+$(".jumbotron img").attr("id"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
timeout: 1000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue