什么也没
This commit is contained in:
parent
fc78b25f38
commit
39071c1550
|
@ -3,6 +3,7 @@ package controller
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"goweb/database"
|
||||
"goweb/res"
|
||||
"goweb/wol"
|
||||
"net"
|
||||
|
@ -36,21 +37,16 @@ func Send_start(mac string, ws **websocket.Conn) {
|
|||
|
||||
}
|
||||
func Getall(ws **websocket.Conn) {
|
||||
type wol struct {
|
||||
ID int
|
||||
Name string
|
||||
Address string
|
||||
}
|
||||
var wolarray []wol
|
||||
wol_item := new(wol)
|
||||
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)
|
||||
wolarray := make([]database.Wol, 0)
|
||||
// wol_item := new(wol)
|
||||
// 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)
|
||||
if err != nil {
|
||||
fmt.Println("marshal failed!", err)
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
_ "modernc.org/sqlite"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
var engine *xorm.Engine
|
||||
|
||||
type Wol struct {
|
||||
ID int
|
||||
Name string `xorm:"varchar(64)"`
|
||||
Mac string `xorm:"varchar(64)"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
file := "./wol.db"
|
||||
|
@ -15,4 +21,19 @@ func init() {
|
|||
panic(err)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
func CreateTable() int {
|
||||
err := engine.Sync2(new(Wol))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func Getallwol(everyone *[]Wol) {
|
||||
// everyone := make([]wol, 0)
|
||||
err := engine.Find(&everyone)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"goweb/database"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
if ans := database.CreateTable(); ans == 0 {
|
||||
t.Errorf("1 + 2 expected be 3, but %d got", ans)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue