44 lines
992 B
Go
44 lines
992 B
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"skapp/pkg/server/services/wol"
|
||
|
"skapp/pkg/utils/errorx"
|
||
|
"skapp/pkg/utils/response"
|
||
|
)
|
||
|
|
||
|
type WakeupDTO struct {
|
||
|
// mac 地址
|
||
|
Mac string `json:"mac" example:"FF-FF-FF-FF-FF-FF-FF"`
|
||
|
// 端口
|
||
|
Port int `json:"port" example:"9"`
|
||
|
}
|
||
|
|
||
|
// PostWolWakeUP
|
||
|
// @Summary wol 唤醒
|
||
|
// @Description wol 唤醒
|
||
|
// @Tags Wol
|
||
|
// @Accept json
|
||
|
// @Produce json
|
||
|
// @Param vo body WakeupDTO true "局域网唤醒"
|
||
|
// @Success 200 {object} response.Response{data=string}
|
||
|
// @Failure default {object} errorx.CodeErrorResponse
|
||
|
// @Router /wol/wakeup [post]
|
||
|
func PostWolWakeUP(ctx *gin.Context) {
|
||
|
dto := &WakeupDTO{
|
||
|
Mac: "FF:FF:FF:FF:FF:FF",
|
||
|
Port: 9,
|
||
|
}
|
||
|
|
||
|
_ = ctx.BindJSON(dto)
|
||
|
|
||
|
err := wol.Services.WakeUp(dto.Mac, dto.Port)
|
||
|
if err = errorx.ParseError(err); err != nil {
|
||
|
ctx.JSON(200, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx.JSON(200, response.NewResponse(fmt.Sprintf("%s 唤醒包发送成功", dto.Mac)))
|
||
|
}
|