go fmt + script.
This commit is contained in:
parent
24be86ef5f
commit
716835d67b
|
|
@ -3,7 +3,7 @@ package controllers
|
|||
import (
|
||||
"github.com/astaxie/beego"
|
||||
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/soilMoisture"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/soilMoisture"
|
||||
)
|
||||
|
||||
type AddSoilMoistController struct {
|
||||
|
|
@ -11,11 +11,11 @@ type AddSoilMoistController struct {
|
|||
}
|
||||
|
||||
func (c *AddSoilMoistController) Get() {
|
||||
macArduino := c.GetString(soilMoisture.MacModuleWifiArduino)
|
||||
pinArduino := c.GetString(soilMoisture.PinArduino)
|
||||
valeurCapteur, _ := c.GetInt(soilMoisture.ValeurCapteur)
|
||||
macArduino := c.GetString(soilMoisture.MacModuleWifiArduino)
|
||||
pinArduino := c.GetString(soilMoisture.PinArduino)
|
||||
valeurCapteur, _ := c.GetInt(soilMoisture.ValeurCapteur)
|
||||
|
||||
soilMoisture.AddData(pinArduino, macArduino, int64(valeurCapteur))
|
||||
soilMoisture.AddData(pinArduino, macArduino, int64(valeurCapteur))
|
||||
|
||||
cpt := soilMoisture.GetCapteurByAdresse(macArduino, pinArduino)
|
||||
if cpt == nil || cpt.Id == 0 {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func (c *ViewTeleinfoController) Prepare() {
|
|||
if sess != nil {
|
||||
c.Data["IsAuthentificated"] = true
|
||||
}
|
||||
|
||||
|
||||
c.Data["IsViewTeleinfo"] = true
|
||||
c.Data["version"] = variables.Version
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
cd controllers
|
||||
go fmt
|
||||
cd ../models
|
||||
go fmt
|
||||
cd ../routers
|
||||
go fmt
|
||||
cd ../watchlog
|
||||
go fmt
|
||||
cd ../xmpp
|
||||
go fmt
|
||||
|
||||
20
main.go
20
main.go
|
|
@ -1,14 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
|
|
@ -26,7 +26,7 @@ var (
|
|||
func init() {
|
||||
log.SetLogger(variables.LogType, variables.LogParams)
|
||||
url := ""
|
||||
db := ""
|
||||
db := ""
|
||||
if database.DatabaseInstance == database.MySQL {
|
||||
// MySQL
|
||||
orm.RegisterDriver(database.MySQL, orm.DRMySQL)
|
||||
|
|
@ -57,23 +57,19 @@ func main() {
|
|||
if !user.IsUserExist("admin") {
|
||||
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
||||
}
|
||||
/*
|
||||
go xmpp_manager.Run()
|
||||
go watchlog.Run()
|
||||
*/
|
||||
go reborn()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
// models.ChanRuns <- xmpp_manager.EndRun
|
||||
time.Sleep(1 * time.Second)
|
||||
models.ChanRuns <- watchlog.EndRun
|
||||
time.Sleep(1 * time.Second)
|
||||
// models.ChanRuns <- xmpp_manager.EndRun
|
||||
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
func reborn() {
|
||||
for {
|
||||
action := <- models.ChanRuns
|
||||
action := <-models.ChanRuns
|
||||
|
||||
switch action {
|
||||
case xmpp_manager.EndRun:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package models
|
||||
|
||||
var (
|
||||
ChanRuns = make(chan string)
|
||||
ChanRuns = make(chan string)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,45 +1,43 @@
|
|||
package watchlog
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/hpcloud/tail"
|
||||
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
|
||||
"container/list"
|
||||
"time"
|
||||
"container/list"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
EndRun = "EndRunWatchlog"
|
||||
EndRun = "EndRunWatchlog"
|
||||
)
|
||||
|
||||
var (
|
||||
ListWebSocket = list.New()
|
||||
ListWebSocket = list.New()
|
||||
)
|
||||
|
||||
|
||||
func Run() {
|
||||
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
||||
for line := range t.Lines {
|
||||
broadcastWebSocket(line.Text)
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
models.ChanRuns <- EndRun
|
||||
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
||||
for line := range t.Lines {
|
||||
broadcastWebSocket(line.Text)
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
models.ChanRuns <- EndRun
|
||||
}
|
||||
|
||||
|
||||
func broadcastWebSocket(message string) {
|
||||
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
||||
// Immediately send event to WebSocket users.
|
||||
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
||||
// Immediately send event to WebSocket users.
|
||||
ws := sub.Value.(*websocket.Conn)
|
||||
err := ws.WriteMessage(websocket.TextMessage, []byte(message))
|
||||
err := ws.WriteMessage(websocket.TextMessage, []byte(message))
|
||||
if err != nil {
|
||||
toRemove := sub
|
||||
sub = sub.Prev()
|
||||
ListWebSocket.Remove(toRemove)
|
||||
toRemove := sub
|
||||
sub = sub.Prev()
|
||||
ListWebSocket.Remove(toRemove)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
xmpp/xmpp.go
28
xmpp/xmpp.go
|
|
@ -1,17 +1,15 @@
|
|||
package xmpp_manager
|
||||
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
|
||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
Status_online = ""
|
||||
Status_offline = ""
|
||||
|
|
@ -37,11 +35,11 @@ var (
|
|||
|
||||
JidStr = beego.AppConfig.String("JID")
|
||||
passwdStr = beego.AppConfig.String("PWD")
|
||||
serverPort = beego.AppConfig.String("PORT")
|
||||
serverPort = beego.AppConfig.String("PORT")
|
||||
|
||||
jid xmpp.JID
|
||||
stream = new(xmpp.Stream)
|
||||
client = new(xmpp.XMPP)
|
||||
jid xmpp.JID
|
||||
stream = new(xmpp.Stream)
|
||||
client = new(xmpp.XMPP)
|
||||
|
||||
Debug = true
|
||||
)
|
||||
|
|
@ -50,7 +48,6 @@ func init() {
|
|||
log.SetLogger(variables.LogType, variables.LogParams)
|
||||
}
|
||||
|
||||
|
||||
func must(v interface{}, err error) interface{} {
|
||||
if err != nil {
|
||||
log.Error("Must error : ", err)
|
||||
|
|
@ -62,15 +59,14 @@ func Run() {
|
|||
// Create stream and configure it as a component connection.
|
||||
log.Info("XMPP Run()")
|
||||
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
||||
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
||||
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
||||
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
||||
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
||||
|
||||
mainXMPP()
|
||||
log.Debug("xmpp.Run Ended")
|
||||
models.ChanRuns <- EndRun
|
||||
}
|
||||
|
||||
|
||||
func mainXMPP() {
|
||||
SendPresence(Status_online, Type_available, "")
|
||||
|
||||
|
|
@ -96,12 +92,10 @@ func mainXMPP() {
|
|||
log.Debug("mainXMPP Ended")
|
||||
}
|
||||
|
||||
|
||||
func SendPresence(status, tpye, message string) {
|
||||
client.Out <- xmpp.Presence{From: jid.Domain, Show: status, Type: tpye, Status: message}
|
||||
}
|
||||
|
||||
|
||||
func execDiscoCommand(iq *xmpp.Iq) {
|
||||
log.Info("Discovery item iq received")
|
||||
reply := iq.Response(xmpp.IQTypeResult)
|
||||
|
|
@ -110,7 +104,7 @@ func execDiscoCommand(iq *xmpp.Iq) {
|
|||
relays := relay.GetAllRelay()
|
||||
for _, r := range relays {
|
||||
discoI := &xmpp.DiscoItem{JID: client.JID.Full(), Node: r.Mac, Name: "Relay : "}
|
||||
if (r.Description == "") {
|
||||
if r.Description == "" {
|
||||
discoI.Name += r.Mac
|
||||
} else {
|
||||
discoI.Name += r.Description
|
||||
|
|
@ -137,9 +131,9 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
// First step in the command
|
||||
if relais.Id != 0 {
|
||||
reply := iq.Response(xmpp.IQTypeResult)
|
||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID()/*+";"+relais.Mac*/}
|
||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID() /*+";"+relais.Mac*/}
|
||||
|
||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais "+descriptionRelais}
|
||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais " + descriptionRelais}
|
||||
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
||||
fieldOption := &xmpp.AdHocFieldOption{Value: "toggle"}
|
||||
field.Options = append(field.Options, *fieldOption)
|
||||
|
|
@ -159,7 +153,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
reply := iq.Response(xmpp.IQTypeResult)
|
||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID}
|
||||
|
||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais "+descriptionRelais}
|
||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais " + descriptionRelais}
|
||||
cmd.XForm = *cmdXForm
|
||||
|
||||
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
||||
|
|
|
|||
Loading…
Reference in New Issue