完成编辑的接口
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
300ac78672
commit
f96286cde8
|
@ -0,0 +1 @@
|
|||
[![Build Status](https://drone.shagain.club/api/badges/lingling/go_echo_wol/status.svg)](https://drone.shagain.club/lingling/go_echo_wol)
|
|
@ -71,3 +71,15 @@ func Add(ws **websocket.Conn, uuid string, name string, mac string) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func Edi(ws **websocket.Conn, uuid string, id int64, name string, mac string) {
|
||||
wol := new(database.Wol)
|
||||
wol.Mac = mac
|
||||
wol.Name = name
|
||||
database.Edi(wol, id)
|
||||
err := websocket.Message.Send(*ws, res.Get_res_string(200, "", uuid, ""))
|
||||
if err != nil {
|
||||
// c.Logger().Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@ type AddData struct {
|
|||
Nmae string `json:"name"`
|
||||
Mac string `json:"mac"`
|
||||
}
|
||||
type EdiData struct {
|
||||
ID int64 `json:"id"`
|
||||
Nmae string `json:"name"`
|
||||
Mac string `json:"mac"`
|
||||
}
|
||||
type TooLTT struct {
|
||||
Method string `json:"method"`
|
||||
Data interface{} `json:"data"`
|
||||
|
@ -72,6 +77,13 @@ func Hello(c echo.Context) error {
|
|||
return
|
||||
}
|
||||
Add(&ws, wsValue.Uuid, AddData.Nmae, AddData.Mac)
|
||||
case "edi":
|
||||
var EdiData EdiData
|
||||
if err := json.Unmarshal(json_data, &EdiData); err != nil {
|
||||
c.Logger().Error(err.Error())
|
||||
return
|
||||
}
|
||||
Edi(&ws, wsValue.Uuid, EdiData.ID, EdiData.Nmae, EdiData.Mac)
|
||||
default:
|
||||
c.Logger().Error("没有找到方法")
|
||||
|
||||
|
|
|
@ -54,17 +54,31 @@ func Getallwoltext() {
|
|||
println(len(everyone))
|
||||
}
|
||||
|
||||
// 返回插入的数量
|
||||
func Insert(wol *Wol) {
|
||||
affected, err := engine.Insert(wol)
|
||||
_, err := engine.Insert(wol)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
println(affected)
|
||||
|
||||
}
|
||||
func Del(id int64) {
|
||||
affected, err := engine.Where("i_d = ?", id).Delete(&Wol{})
|
||||
_, err := engine.Where("i_d = ?", id).Delete(&Wol{})
|
||||
if err != nil {
|
||||
println(err)
|
||||
println(err.Error())
|
||||
}
|
||||
}
|
||||
func Edi(wol *Wol, id int64) {
|
||||
_, err := engine.Where("i_d = ?", id).Update(wol)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 根据id查找
|
||||
func GetWolById(id int64, wol *Wol) {
|
||||
_, err := engine.Where("i_d = ?", id).Get(wol)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
println(affected, "ok")
|
||||
}
|
||||
|
|
27
main_test.go
27
main_test.go
|
@ -28,3 +28,30 @@ func TestAdd_Delwol(t *testing.T) {
|
|||
}
|
||||
t.Errorf("并没有找到")
|
||||
}
|
||||
|
||||
func TestEdi_wol(t *testing.T) {
|
||||
wol := new(database.Wol)
|
||||
wol.Mac = "8F:26:58:C1:85:83"
|
||||
wol.Name = "text1"
|
||||
database.Insert(wol)
|
||||
wolarray := make([]database.Wol, 0)
|
||||
database.Getallwol(&wolarray)
|
||||
var idReturnedOnInsertion int64 = -1
|
||||
for _, item := range wolarray {
|
||||
if item.Mac == wol.Mac && item.Name == wol.Name {
|
||||
idReturnedOnInsertion = item.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
wol2 := new(database.Wol)
|
||||
wol2.Name = "testchang"
|
||||
wol2.Mac = "97:88:90:99:8D:93"
|
||||
database.Edi(wol2, idReturnedOnInsertion)
|
||||
changwoled := new(database.Wol)
|
||||
database.GetWolById(idReturnedOnInsertion, changwoled)
|
||||
if changwoled.Mac == wol2.Mac && changwoled.Name == wol2.Name {
|
||||
database.Del(idReturnedOnInsertion)
|
||||
return
|
||||
}
|
||||
t.Errorf("并没有找到,或者失败")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue