go fmt + script.
This commit is contained in:
parent
24be86ef5f
commit
716835d67b
|
|
@ -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
|
||||||
|
|
||||||
18
main.go
18
main.go
|
|
@ -1,14 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/database"
|
||||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/models/temperature"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
"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/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"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
@ -57,23 +57,19 @@ func main() {
|
||||||
if !user.IsUserExist("admin") {
|
if !user.IsUserExist("admin") {
|
||||||
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
go xmpp_manager.Run()
|
|
||||||
go watchlog.Run()
|
|
||||||
*/
|
|
||||||
go reborn()
|
go reborn()
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
// models.ChanRuns <- xmpp_manager.EndRun
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
models.ChanRuns <- watchlog.EndRun
|
models.ChanRuns <- watchlog.EndRun
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
// models.ChanRuns <- xmpp_manager.EndRun
|
||||||
|
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func reborn() {
|
func reborn() {
|
||||||
for {
|
for {
|
||||||
action := <- models.ChanRuns
|
action := <-models.ChanRuns
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case xmpp_manager.EndRun:
|
case xmpp_manager.EndRun:
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ var (
|
||||||
ListWebSocket = list.New()
|
ListWebSocket = list.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
t, _ := tail.TailFile(variables.LogFilePath, tail.Config{Follow: true})
|
||||||
for line := range t.Lines {
|
for line := range t.Lines {
|
||||||
|
|
@ -29,7 +28,6 @@ func Run() {
|
||||||
models.ChanRuns <- EndRun
|
models.ChanRuns <- EndRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func broadcastWebSocket(message string) {
|
func broadcastWebSocket(message string) {
|
||||||
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
for sub := ListWebSocket.Front(); sub != nil; sub = sub.Next() {
|
||||||
// Immediately send event to WebSocket users.
|
// Immediately send event to WebSocket users.
|
||||||
|
|
|
||||||
16
xmpp/xmpp.go
16
xmpp/xmpp.go
|
|
@ -1,17 +1,15 @@
|
||||||
package xmpp_manager
|
package xmpp_manager
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/logs"
|
"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"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Status_online = ""
|
Status_online = ""
|
||||||
Status_offline = ""
|
Status_offline = ""
|
||||||
|
|
@ -50,7 +48,6 @@ func init() {
|
||||||
log.SetLogger(variables.LogType, variables.LogParams)
|
log.SetLogger(variables.LogType, variables.LogParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func must(v interface{}, err error) interface{} {
|
func must(v interface{}, err error) interface{} {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Must error : ", err)
|
log.Error("Must error : ", err)
|
||||||
|
|
@ -70,7 +67,6 @@ func Run() {
|
||||||
models.ChanRuns <- EndRun
|
models.ChanRuns <- EndRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func mainXMPP() {
|
func mainXMPP() {
|
||||||
SendPresence(Status_online, Type_available, "")
|
SendPresence(Status_online, Type_available, "")
|
||||||
|
|
||||||
|
|
@ -96,12 +92,10 @@ func mainXMPP() {
|
||||||
log.Debug("mainXMPP Ended")
|
log.Debug("mainXMPP Ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func SendPresence(status, tpye, message string) {
|
func SendPresence(status, tpye, message string) {
|
||||||
client.Out <- xmpp.Presence{From: jid.Domain, Show: status, Type: tpye, Status: message}
|
client.Out <- xmpp.Presence{From: jid.Domain, Show: status, Type: tpye, Status: message}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func execDiscoCommand(iq *xmpp.Iq) {
|
func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
log.Info("Discovery item iq received")
|
log.Info("Discovery item iq received")
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
|
|
@ -110,7 +104,7 @@ func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
relays := relay.GetAllRelay()
|
relays := relay.GetAllRelay()
|
||||||
for _, r := range relays {
|
for _, r := range relays {
|
||||||
discoI := &xmpp.DiscoItem{JID: client.JID.Full(), Node: r.Mac, Name: "Relay : "}
|
discoI := &xmpp.DiscoItem{JID: client.JID.Full(), Node: r.Mac, Name: "Relay : "}
|
||||||
if (r.Description == "") {
|
if r.Description == "" {
|
||||||
discoI.Name += r.Mac
|
discoI.Name += r.Mac
|
||||||
} else {
|
} else {
|
||||||
discoI.Name += r.Description
|
discoI.Name += r.Description
|
||||||
|
|
@ -137,9 +131,9 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
// First step in the command
|
// First step in the command
|
||||||
if relais.Id != 0 {
|
if relais.Id != 0 {
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
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"}
|
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
||||||
fieldOption := &xmpp.AdHocFieldOption{Value: "toggle"}
|
fieldOption := &xmpp.AdHocFieldOption{Value: "toggle"}
|
||||||
field.Options = append(field.Options, *fieldOption)
|
field.Options = append(field.Options, *fieldOption)
|
||||||
|
|
@ -159,7 +153,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID}
|
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
|
cmd.XForm = *cmdXForm
|
||||||
|
|
||||||
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue