示例#1
0
func GetDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var device tf.Device
	device.Device_name = device_name
	if device, err := device.GetDevice(); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to get device %s", device_name))
	} else {
		c.JSON(http.StatusOK, device)
	}
}
示例#2
0
func DeleteDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var device tf.Device
	device.Device_name = device_name
	fmt.Println(device_name)
	if err := device.DeleteDevice(); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to delete device %s.  Error: %s", device_name, err))
	} else {
		c.String(http.StatusOK, fmt.Sprintf("Device %s has been deleted successfully", device_name))
	}
}
示例#3
0
func UpdateDevice(c *gin.Context) {
	device_name := c.Params.ByName("device_name")
	var payload tf.Device
	c.Bind(&payload)
	var device tf.Device
	device.Device_name = device_name
	if err := device.UpdateDevice(payload); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("Failed to update device %s.  Error: ", device_name, err))
	} else {
		c.String(http.StatusOK, fmt.Sprintf("Device %s has been updated successfully", device_name))
	}
}