• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang models.NewInternalError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/upmio/APIServer/models.NewInternalError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewInternalError函数的具体用法?Golang NewInternalError怎么用?Golang NewInternalError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewInternalError函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Put

// @Title update
// @Description update the node
// @Param	nodeID		path 	string	true		"The node id you want to update"
// @Param	body		body 	models.Node	true		"body for node content"
// @Success 200
// @Failure 400 invalid request message
// @router /:nid [put]
func (self *NodeController) Put() {
	nid := self.GetString(":nid")
	var body models.Node
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}
	if node, ok := objects.Get(nid).(*models.Node); ok {
		clone := *node
		if clone.Status != body.Status && body.Status != 0 {
			clone.Status = body.Status
		}
		if clone.MaxInstance != body.MaxInstance && body.MaxInstance != 0 {
			clone.MaxInstance = body.MaxInstance
		}
		objects.Set(clone.ID, &clone)
	} else {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:32,代码来源:node.go


示例2: Post

// @Title create
// @Description create users
// @Param	body		body 	models.PostNode	true		"body for node content"
// @Success 200 {object} models.ResponsePostNode
// @Failure 400 invalid request message
// @router / [post]
func (self *NodeController) Post() {
	var body []models.PostNode
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	resp := make([]models.ResponsePostNode, len(body))
	for i := range body {
		node := models.Node{
			ID:          "node_" + utils.Generate32UUID(),
			ClusterID:   body[i].ClusterID,
			SoftwareID:  body[i].SoftwareID,
			Status:      models.Enable,
			Runtime:     "running",
			MaxInstance: body[i].MaxInstance,
			IPAddress:   "12.168.1.1",
			NCPU:        24,
			Mem_MB:      102400,
		}

		objects.Set(node.ID, &node)

		resp[i].ID = node.ID
		resp[i].TaskID = utils.Generate32UUID()
		resp[i].NodeID = body[i].NodeID
	}

	self.Data["json"] = resp
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:40,代码来源:node.go


示例3: Get

// @Title Get
// @Description find network by networkID
// @Param	netwrokID		path 	string	true		"The networkID you want to get"
// @Success 200 {object} models.IPtable
// @Failure 403 :networkID is empty
// @router /:id [get]
func (self *NetworkController) Get() {
	id := self.GetString(":id")
	if strings.TrimSpace(id) != "" {
		if ob, ok := objects.Get(id).(*models.IPtable); ok {
			self.Data["json"] = ob
		} else {
			self.Data["json"] = models.NewInternalError(403, ErrNotFound)
			self.Ctx.Output.SetStatus(403)
		}
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:22,代码来源:network.go


示例4: Post

// @Title create
// @Description create cluster
// @Param	body		body 	models.Cluster  	true		"body for cluste content"
// @Success 200 {string} models.ClusterInfo.ID
// @Failure 400 invalid request message
// @router / [post]
func (self *ClusterController) Post() {
	var body models.PostCluster
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	cluster := models.ClusterInfo{
		ID:                "cluster_" + utils.Generate32UUID(),
		Name:              body.Name,
		Type:              body.Type,
		Status:            models.Enable,
		MaxNodeUsageLimit: body.MaxNodeUsageLimit,
		Storage: models.Storage{
			Type: body.StorageType,
			ID:   body.StorageSystemID,
		},
	}
	objects.Set(cluster.ID, &cluster)

	self.Data["json"] = map[string]string{"id": cluster.ID}
	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:33,代码来源:cluster.go


示例5: List

// @Title List
// @Description find node by node_ID
// @Param	body		body 	models.CommonRequestBody	true		"the nodes you want to get"
// @Success 200 {object} models.ResponseNode
// @Failure 400 invalid request message
// @router /list [post]
func (self *NodeController) List() {
	var body models.CommonRequestBody
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}
	m := objects.Items()
	if body.All {
		list := make([]models.ResponseNode, 0, 100)
		for k, v := range m {
			if id, ok := k.(string); ok && strings.HasPrefix(id, "node_") {
				if object, ok := v.(*models.Node); ok {
					list = append(list, models.ResponseNode{
						ID:        object.ID,
						IPAddress: object.IPAddress,
						NCPU:      object.NCPU,
						Mem_MB:    object.Mem_MB,
						Status:    object.Status,
						Runtime:   object.Runtime,
					})
				}
			}
		}
		self.Data["json"] = list
		self.ServeJSON()
		return
	}

	list := make([]models.ResponseNode, len(body.ID))
	for i, id := range body.ID {
		if strings.TrimSpace(id) == "" {
			continue
		}
		if object, ok := m[id].(*models.Node); ok {
			list[i] = models.ResponseNode{
				ID:        object.ID,
				IPAddress: object.IPAddress,
				NCPU:      object.NCPU,
				Mem_MB:    object.Mem_MB,
				Status:    object.Status,
				Runtime:   object.Runtime,
			}
		} else {
			list[i] = models.ResponseNode{
				ID:    id,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:61,代码来源:node.go


示例6: Disable

// @Title disable
// @Description update the object
// @Param	RaidGroupID		path 	string	true		"The RaidGroup you want to update"
// @Success 200
// @Failure 403 :id not exist
// @router /san/rg/:ID/disable [put]
func (self *StorageController) Disable() {
	id := self.GetString(":ID")

	if rg, ok := objects.Get(id).(*models.RaidGroup); ok {
		clone := *rg
		clone.Status = models.Disable
		objects.Set(clone.ID, &clone)
	} else {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:19,代码来源:storage.go


示例7: Enable

// @Title enable
// @Description update the object
// @Param	networkID		path 	string	true		"The network you want to update"
// @Success 200
// @Failure 403 :networkID not exist
// @router /:id/enable [put]
func (self *NetworkController) Enable() {
	id := self.GetString(":id")

	if table, ok := objects.Get(id).(*models.IPtable); ok {
		clone := *table
		clone.Status = models.Enable
		objects.Set(clone.ID, &clone)
	} else {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:19,代码来源:network.go


示例8: Disable

// @Title disable
// @Description update the object
// @Param	clusterID		path 	string	true		"The clusterID you want to update"
// @Success 200
// @Failure 403 :clusterID is empty
// @router /:clusterID/disable [put]
func (self *ClusterController) Disable() {
	cid := self.GetString(":clusterID")

	if cluster, ok := objects.Get(cid).(*models.ClusterInfo); ok {
		clone := *cluster
		clone.Status = models.Disable
		objects.Set(clone.ID, &clone)
	} else {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:19,代码来源:cluster.go


示例9: Disable

// @Title disable
// @Description update the object
// @Param	serviceID		path 	string	true		"The serviceID you want to update"
// @Success 200
// @Failure 403 :serviceID is empty
// @router /:id/disable [put]
func (self *ServiceController) Disable() {
	id := self.GetString(":id")

	if svc, ok := objects.Get(id).(*models.Service); ok {
		clone := *svc
		clone.Status = models.Disable
		objects.Set(clone.ID, &clone)
	} else {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:19,代码来源:service.go


示例10: Get

// @Title Get
// @Description find node by nodeID
// @Param	nodeID		path 	string	true		"The nodeID you want to get"
// @Success 200 {object} models.ResponseNode
// @Failure 403 :nodeID is empty
// @router /:id [get]
func (self *NodeController) Get() {
	id := self.GetString(":id")
	if strings.TrimSpace(id) != "" {
		if object, ok := objects.Get(id).(*models.Node); ok {
			self.Data["json"] = models.ResponseNode{
				ID:        object.ID,
				IPAddress: object.IPAddress,
				NCPU:      object.NCPU,
				Mem_MB:    object.Mem_MB,
				Status:    object.Status,
				Runtime:   object.Runtime,
			}
		} else {
			self.Data["json"] = models.NewInternalError(403, ErrNotFound)
			self.Ctx.Output.SetStatus(403)
		}
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:29,代码来源:node.go


示例11: PostNAS

// @Title create
// @Description create cluster
// @Param	body		body 	models.Cluster  	true		"body for cluste content"
// @Success 200 {string} models.ClusterInfo.ID
// @Failure 403 body is empty
// @router /nas [post]
func (self *StorageController) PostNAS() {
	var body models.NAS
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(403)
		self.ServeJSON()
		return
	}

	objects.Set(body.ID, &body)

	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:21,代码来源:storage.go


示例12: GetNAS

// @Title Get
// @Description find  SANs by condition
// @Param	body		body 	models.CommonRequestBody	true		"the cluster_IDs you want to get"
// @Success 200 {object} models.SAN
// @router /nas/:id [get]
func (self *StorageController) GetNAS() {
	id := self.GetString(":ID")

	if nas, ok := objects.Get(id).(*models.NAS); ok {
		self.Data["json"] = models.ResponseNAS{
			ID:      nas.ID,
			TotalMB: 1024000,
			FreeMB:  100000,
		}
	} else {
		self.Data["json"] = models.NewInternalError(403, ErrNotFound)
	}

	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:20,代码来源:storage.go


示例13: Post

// @Title add
// @Description add software
// @Param	body		body 	models.Software  	true		"body for software content"
// @Success 200 {string} taskID
// @Failure 400 invalid request message
// @router / [post]
func (self *SoftwareController) Post() {
	var body models.Software
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	objects.Set(body.ID, &body)

	self.Data["json"] = map[string]string{"task_id": "task_" + utils.Generate32UUID()}
	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:22,代码来源:software.go


示例14: Post

// @Title create
// @Description create network
// @Param	body		body 	models.IPtable  	true		"body for network content"
// @Success 200 {string} models.IPtable.ID
// @Failure 400 invalid request message
// @router / [post]
func (self *NetworkController) Post() {
	var body models.IPtable
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	body.ID = "network_" + utils.Generate32UUID()
	body.Status = models.Enable
	objects.Set(body.ID, &body)

	self.Data["json"] = map[string]string{"id": body.ID}
	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:24,代码来源:network.go


示例15: List

// @Title List
// @Description find networks by condition
// @Param	body		body 	models.CommonRequestBody	true		"the networks you want to get"
// @Success 200 {object} models.IPtable
// @Failure 400 invalid request message
// @router /list [post]
func (self *NetworkController) List() {
	var body models.CommonRequestBody
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(403)
		self.ServeJSON()
		return
	}

	m := objects.Items()
	if body.All {
		list := make([]*models.IPtable, 0, 100)
		for k, v := range m {
			if id, ok := k.(string); ok && strings.HasPrefix(id, "network_") {
				if ob, ok := v.(*models.IPtable); ok {
					list = append(list, ob)
				}
			}
		}
		self.Data["json"] = list
		self.ServeJSON()
		return
	}

	list := make([]*models.IPtable, len(body.ID))
	for i, id := range body.ID {
		if strings.TrimSpace(id) == "" {
			continue
		}
		if ob, ok := m[id].(*models.IPtable); ok {
			list[i] = ob
		} else {
			list[i] = &models.IPtable{
				ID:    id,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:48,代码来源:network.go


示例16: Post

// @Title create
// @Description create service
// @Param	body		body 	models.PostService  	true		"body for service content"
// @Success 200 {object} models.TaskResponse
// @Failure 400 invalid request message
// @router / [post]
func (self *ServiceController) Post() {
	var body models.PostService
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	var service = models.Service{
		ID:     "service_" + utils.Generate32UUID(),
		Status: models.StandBy,
	}
	objects.Set(service.ID, &service)

	self.Data["json"] = models.NewTaskResponse(service.ID, "task"+utils.Generate32UUID())

	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:27,代码来源:service.go


示例17: PostRaidGroup

// @Title add RaidGroup
// @Description add RaidGroup
// @Param	body		body 	models.PostRaidGroup  	true		"body for RaidGroup content"
// @Success 200 {string} models.RaidGroup.ID
// @Failure 400 invalid request message
// @router /san/rg [post]
func (self *StorageController) PostRaidGroup() {
	var body models.PostRaidGroup
	err := json.Unmarshal(self.Ctx.Input.RequestBody, &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	rg := models.RaidGroup{
		ID:     "raidgroup_" + utils.Generate32UUID(),
		SANID:  body.SANID,
		Number: body.Number,
		Status: models.Enable,
	}

	objects.Set(rg.ID, &rg)

	self.Data["json"] = map[string]string{"id": rg.ID}
	//self.Ctx.Output.SetStatus(201)
	self.ServeJSON()
}
开发者ID:upmio,项目名称:APIServer,代码行数:29,代码来源:storage.go



注:本文中的github.com/upmio/APIServer/models.NewInternalError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang aws.Bool函数代码示例发布时间:2022-05-28
下一篇:
Golang thrift.TProtocol类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap