|
|
@ -129,6 +129,20 @@ func GetDevice(c *gin.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func DelDevice(c *gin.Context) { |
|
|
|
id,err := strconv.Atoi(c.Param("id")) |
|
|
|
if err != nil{ |
|
|
|
log.Println("param error",err) |
|
|
|
c.JSON(http.StatusOK,gin.H{"code":-1,"msg": err.Error()}) |
|
|
|
} |
|
|
|
if err = db.Delete(&DeviceInfo{},"id = ?", id).Error;err != nil { |
|
|
|
log.Println("del id error",err) |
|
|
|
c.JSON(http.StatusOK,gin.H{"code":-1,"msg": err.Error()}) |
|
|
|
} else { |
|
|
|
c.JSON(http.StatusOK,gin.H{"code":0,"msg": "OK"}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|
err := loadConfig("./config.json",&conf) |
|
|
|
if err != nil { |
|
|
@ -139,6 +153,7 @@ func main() { |
|
|
|
engine := gin.Default() |
|
|
|
engine.GET("/device/info", GetDevice) |
|
|
|
engine.POST("/device/info", PostDevice) |
|
|
|
engine.DELETE("/device/:id",DelDevice) |
|
|
|
log.Println("start deviceIDServer port " + conf.Server.Port) |
|
|
|
err = engine.Run(":" + conf.Server.Port) |
|
|
|
if err != nil { |
|
|
|