Ejemplo n.º 1
0
func Edit(rend render.Render, req *http.Request, params martini.Params) {

	id := helper.Int64(params["id"])
	host, errResponse := getClientWithNoBusyOrJSONError(id)
	if host == nil {
		rend.JSON(200, errResponse)
		return
	}

	body := JSON.FormRequest(req.Body)
	c := &model.WebServer{}
	if err := JSON.ParseToStruct(JSON.Stringify(body), c); err != nil {
		rend.JSON(200, helper.Error(helper.ParamsError))
		return
	}
	keys := JSON.GetKeys(body)

	c.Id = id

	if err := client.Edit(c, keys...); err != nil {
		rend.JSON(200, helper.Error(err))
		return
	}
	rend.JSON(200, helper.Success(c))
}
Ejemplo n.º 2
0
func Update(rend render.Render, req *http.Request, params martini.Params) {
	id := helper.Int64(params["id"])
	host, errResponse := getClientWithNoBusyOrJSONError(id)
	if host == nil {
		rend.JSON(200, errResponse)
		return
	}

	//未部署列表
	unDeployFileList, err := host.GetUnDeployFiles()
	if err != nil || unDeployFileList == nil {
		rend.JSON(200, helper.Error(err))
		return
	}

	//选择要上传的文件
	body := JSON.FormRequest(req.Body)
	files := body["files"]

	upFile := rpc.UploadFileList{}
	JSON.ParseToStruct(JSON.Stringify(files), &upFile)

	uploadFiles := &rpc.UpdateArgs{
		Id:         host.Id,
		ResPath:    config.ResServer(),
		FileList:   upFile,
		DeployPath: host.DeployPath,
	}

	//上传
	completeUploadList, err := host.CallRpc("Update", uploadFiles)
	if err != nil {
		rend.JSON(200, helper.Error(err))
		return
	}

	//上传ok就删除对应路径记录
	helper.Map(completeUploadList, func(key, value interface{}) bool {
		p := key.(string)
		v := reflect.ValueOf(value)
		if v.Kind() == reflect.Bool {
			delete(unDeployFileList, p)
		}
		return false
	})

	//更新记录
	host.WebServer.UnDeployList = JSON.Stringify(unDeployFileList)

	err = client.Edit(host.WebServer, "UnDeployList")
	if err != nil {
		fmt.Println(err)
	}
	rend.JSON(200, helper.Success(completeUploadList))
}
Ejemplo n.º 3
0
func Add(rend render.Render, req *http.Request) {
	c := &model.WebServer{}
	body := JSON.FormRequest(req.Body)

	if err := JSON.ParseToStruct(JSON.Stringify(body), c); err != nil {
		rend.JSON(200, helper.Error(helper.ParamsError, err))
		return
	}

	if _, err := client.Add(c); err != nil {
		rend.JSON(200, helper.Error(err))
		return
	}

	rend.JSON(200, helper.Success(c))
}