30 lines
742 B
Go
30 lines
742 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func main() {
|
|
r := gin.Default()
|
|
r.POST("/plc", Plc)
|
|
r.Run()
|
|
}
|
|
|
|
func Plc(c *gin.Context) {
|
|
var json struct {
|
|
Key1 *int `json:"key1" binding:"required"`
|
|
Speed1 *int `json:"speed1" binding:"required_if=Key1 2"` // 喷雾量(百分比): 0-100
|
|
Speed2 *int `json:"speed2" binding:"required_if=Key1 2"` // 喷雾量(百分比): 0-100
|
|
YV1 *int `json:"yv1" binding:"required_if=Key1 2"` // 电磁阀1 状态
|
|
YV2 *int `json:"yv2" binding:"required_if=Key1 2"` // 电磁阀2 状态
|
|
}
|
|
if err := c.ShouldBindJSON(&json); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "ok"})
|
|
}
|