什么也没

This commit is contained in:
giaogiao 2023-09-04 18:00:09 +08:00
parent fc78b25f38
commit 39071c1550
4 changed files with 46 additions and 16 deletions

View File

@ -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)

View File

@ -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)
}
}

13
main_test.go Normal file
View File

@ -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)
}
}

BIN
wol.db

Binary file not shown.