暂时能用了
This commit is contained in:
parent
39071c1550
commit
1292175126
|
@ -11,7 +11,7 @@ import (
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Send_start(mac string, ws **websocket.Conn) {
|
func Send_start(mac string, ws **websocket.Conn, uuid string) {
|
||||||
allNetworkInterfaces, err := net.Interfaces()
|
allNetworkInterfaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err)
|
println(err)
|
||||||
|
@ -29,30 +29,23 @@ func Send_start(mac string, ws **websocket.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = websocket.Message.Send(*ws, res.Get_res_string(200, "已经向地址发送 mac: "+mac, "", ""))
|
err = websocket.Message.Send(*ws, res.Get_res_string(200, "已经向地址发送 mac: "+mac, uuid, ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// c.Logger().Error(err)
|
// c.Logger().Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func Getall(ws **websocket.Conn) {
|
func Getall(ws **websocket.Conn, uuid string) {
|
||||||
wolarray := make([]database.Wol, 0)
|
wolarray := make([]database.Wol, 0)
|
||||||
// wol_item := new(wol)
|
database.Getallwol(&wolarray)
|
||||||
// wol_item.ID = 1
|
|
||||||
// wol_item.Name = "电脑"
|
|
||||||
// wol_item.Address = "10:7B:44:80:F4:6A"
|
|
||||||
// wol_item2 := new(wol)
|
|
||||||
// wol_item2.ID = 2
|
|
||||||
// wol_item2.Name = "aa"
|
|
||||||
// wol_item2.Address = "10:7B:44:80:F4:6A"
|
|
||||||
// wolarray = append(wolarray, *wol_item, *wol_item2)
|
|
||||||
v, err := json.Marshal(wolarray)
|
v, err := json.Marshal(wolarray)
|
||||||
|
println(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("marshal failed!", err)
|
fmt.Println("marshal failed!", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = websocket.Message.Send(*ws, res.Get_res_string(200, "", "", string(v)))
|
err = websocket.Message.Send(*ws, res.Get_res_string(200, "", uuid, wolarray))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// c.Logger().Error(err)
|
// c.Logger().Error(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -18,7 +18,7 @@ func init() {
|
||||||
file := "./wol.db"
|
file := "./wol.db"
|
||||||
engine, err = xorm.NewEngine("sqlite3", file)
|
engine, err = xorm.NewEngine("sqlite3", file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
println(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,14 +26,31 @@ func init() {
|
||||||
func CreateTable() int {
|
func CreateTable() int {
|
||||||
err := engine.Sync2(new(Wol))
|
err := engine.Sync2(new(Wol))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
println(err)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
func Getallwol(everyone *[]Wol) {
|
func Getallwol(everyone *[]Wol) {
|
||||||
// everyone := make([]wol, 0)
|
// everyone := make([]wol, 0)
|
||||||
|
err := engine.Find(&(*everyone))
|
||||||
|
if err != nil {
|
||||||
|
println("Getallwol err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Getallwoltext() {
|
||||||
|
everyone := make([]Wol, 0)
|
||||||
err := engine.Find(&everyone)
|
err := engine.Find(&everyone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
println("Getallwoltext", err)
|
||||||
}
|
}
|
||||||
|
println(len(everyone))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Insert(wol *Wol) {
|
||||||
|
affected, err := engine.Insert(&wol)
|
||||||
|
if err != nil {
|
||||||
|
println(err)
|
||||||
|
}
|
||||||
|
println(affected)
|
||||||
}
|
}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
||||||
github.com/cli/safeexec v1.0.1 // indirect
|
github.com/cli/safeexec v1.0.1 // indirect
|
||||||
github.com/cosmtrek/air v1.45.0 // indirect
|
github.com/cosmtrek/air v1.45.0 // indirect
|
||||||
github.com/creack/pty v1.1.18 // indirect
|
github.com/creack/pty v1.1.18 // indirect
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/fatih/color v1.15.0 // indirect
|
github.com/fatih/color v1.15.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -104,6 +104,7 @@ github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
|
|
5
main.go
5
main.go
|
@ -69,6 +69,7 @@ func hello(c echo.Context) error {
|
||||||
type TooLTT struct {
|
type TooLTT struct {
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
Data Data `json:"data"`
|
Data Data `json:"data"`
|
||||||
|
Uuid string `json:"uuid"`
|
||||||
}
|
}
|
||||||
websocket.Handler(func(ws *websocket.Conn) {
|
websocket.Handler(func(ws *websocket.Conn) {
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
@ -93,9 +94,9 @@ func hello(c echo.Context) error {
|
||||||
json.Unmarshal([]byte(msg), &wsValue)
|
json.Unmarshal([]byte(msg), &wsValue)
|
||||||
switch {
|
switch {
|
||||||
case wsValue.Method == "start":
|
case wsValue.Method == "start":
|
||||||
controller.Send_start(wsValue.Data.Mac, &ws)
|
controller.Send_start(wsValue.Data.Mac, &ws, wsValue.Uuid)
|
||||||
case wsValue.Method == "getall":
|
case wsValue.Method == "getall":
|
||||||
controller.Getall(&ws)
|
controller.Getall(&ws, wsValue.Uuid)
|
||||||
default:
|
default:
|
||||||
fmt.Printf("error")
|
fmt.Printf("error")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,15 @@ import "encoding/json"
|
||||||
type response struct {
|
type response struct {
|
||||||
Code int
|
Code int
|
||||||
Message string
|
Message string
|
||||||
Error string
|
Uuid string
|
||||||
Data string
|
Data interface{} `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get_res_string(Code int, Message string, Error string, Data string) string {
|
func Get_res_string(Code int, Message string, Uuid string, Data ...interface{}) string {
|
||||||
var res = new(response)
|
var res = new(response)
|
||||||
res.Code = Code
|
res.Code = Code
|
||||||
res.Message = Message
|
res.Message = Message
|
||||||
res.Error = Error
|
res.Uuid = Uuid
|
||||||
res.Data = Data
|
res.Data = Data
|
||||||
res_str, err := json.Marshal(res)
|
res_str, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue