什么也没

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 ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"goweb/database"
"goweb/res" "goweb/res"
"goweb/wol" "goweb/wol"
"net" "net"
@ -36,21 +37,16 @@ func Send_start(mac string, ws **websocket.Conn) {
} }
func Getall(ws **websocket.Conn) { func Getall(ws **websocket.Conn) {
type wol struct { wolarray := make([]database.Wol, 0)
ID int // wol_item := new(wol)
Name string // wol_item.ID = 1
Address string // wol_item.Name = "电脑"
} // wol_item.Address = "10:7B:44:80:F4:6A"
var wolarray []wol // wol_item2 := new(wol)
wol_item := new(wol) // wol_item2.ID = 2
wol_item.ID = 1 // wol_item2.Name = "aa"
wol_item.Name = "电脑" // wol_item2.Address = "10:7B:44:80:F4:6A"
wol_item.Address = "10:7B:44:80:F4:6A" // wolarray = append(wolarray, *wol_item, *wol_item2)
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)
if err != nil { if err != nil {
fmt.Println("marshal failed!", err) fmt.Println("marshal failed!", err)

View File

@ -1,12 +1,18 @@
package database package database
import ( import (
_ "modernc.org/sqlite" _ "github.com/mattn/go-sqlite3"
"xorm.io/xorm" "xorm.io/xorm"
) )
var engine *xorm.Engine var engine *xorm.Engine
type Wol struct {
ID int
Name string `xorm:"varchar(64)"`
Mac string `xorm:"varchar(64)"`
}
func init() { func init() {
var err error var err error
file := "./wol.db" file := "./wol.db"
@ -15,4 +21,19 @@ func init() {
panic(err) 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.