cloud-archive.go 2.19 KB
/**********************************************
 * Copyright(c) 2017 IceSimba
 * All rights reserved.
 *
 * FileName: icesimba.cloud.go
 * Author:  dsl
 * Version: 1.0
 * Date:  2017/08/03
 * Description: 云存档接口Api
 * Others:
 * Function List:
     1.…………
     2.…………
 * History:
     1.Date:
       Author:
       Modification:
**********************************************/
package apis

import (
	//"common"
	"fmt"
	"net/http"

	. "client/icesimba.cloud/models"
	"github.com/gin-gonic/gin"
)

var (
	code string
	data string
)

/*
 *	测试网络连接接口
 */
func IndexApi(c *gin.Context) {
	c.String(http.StatusOK, "It works")
}

/*
 *	创建或者更新云存档
 */
func CreateCloudArchiveApi(c *gin.Context) {
	fmt.Println(c.Request.URL.String())
	userId := c.Request.FormValue("user_id")
	gameId := c.Request.FormValue("game_id")
	dataPacket := c.Request.FormValue("data_packet")
	if userId == "" || gameId == "" || dataPacket == "" {
		code = "102000"
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  "missing parameter",
		})
		return
	}

	cloud := CloudArchive{
		UserId:     userId,
		GameId:     gameId,
		DataPacket: dataPacket,
	}

	ca, err := cloud.PostCloudArchive()
	if err != nil {
		code = "102002"
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  err.Error(),
		})
		return
	}
	code = "0"
	c.JSON(http.StatusOK, gin.H{
		"code": code,
		"obj":  ca,
	})
	return
}

/*
 *	查询云存档
 */
func QueryCloudArchiveApi(c *gin.Context) {
	//	fmt.Println(c.Request.URL.String())
	//	fmt.Println(common.GetUrlSign(
	//		c.Request.URL.String(),
	//		c.Request.FormValue("deviceId"),
	//		c.Request.FormValue("timestamp"),
	//	))
	userId := c.Request.FormValue("user_id")
	gameId := c.Request.FormValue("game_id")

	if userId == "" || gameId == "" {
		code = "102000"
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  "missing parameter",
		})
		return
	}

	cloud := CloudArchive{
		UserId: userId,
		GameId: gameId,
	}
	data, err := cloud.GetCloudArchive()
	if err != nil {
		code = "102001"
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  err.Error(),
		})
		return
	}
	code = "0"
	c.JSON(http.StatusOK, gin.H{
		"code": code,
		"obj":  data,
	})
	return
}