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

Golang models.Result类代码示例

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

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



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

示例1: GetErrPercent

// @Title Get Error Time Percent
// @Description get rangetime to caculate errtime percent
// @Param       starttime    query   string    "service starttime"
// @Param       endtime      query   string    "service endtime"
// @Param       ns           query   string    "ns name"
// @Success 200 {object} models.FaultData
// @Failure 403 body  is empty
// @router /
func (c *DownController) GetErrPercent() {
	var starttime int64
	var endtime int64
	var ns string
	var err error
	var result models.Result

	ns = c.GetString("ns")
	nslist := strings.Split(ns, ".")
	if nslist[len(nslist)-1] != "com" {
		result.Success = false
		result.Data = "ns is not correct"
		c.Data["json"] = result
		c.Abort("400")
	}

	now := time.Now()
	days := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC).Day()
	next_time := now.AddDate(0, 0, days)

	start_month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
	end_month := time.Date(next_time.Year(), next_time.Month(), 1, 0, 0, 0, 0, time.Local)

	starttime, err = c.GetInt64("starttime")
	if err != nil {
		starttime = start_month.Unix()
	}

	endtime, err = c.GetInt64("endtime")
	if err != nil {
		endtime = end_month.Unix()
	}

	detail, err := models.GetErrTimeDetail(starttime, endtime, ns)
	c.Ctx.Output.Header("Content-Disposition", "attachment;filename=myfilename.csv")
	c.Ctx.Output.Header("Content-Type", "application/CSV")
	result2 := bytes.NewBufferString("")
	csvResult := csv.NewWriter(result2)

	csvResult.Write([]string{"影响业务", "发生时间", "事故内容", "影响面", "影响时长(min)", "事故原因", "对应方案", "未来对策", "定级"})
	for _, oneDetail := range detail {
		csvResult.Write(oneDetail.GenCsv())
	}
	csvResult.Flush()

	enc := mahonia.NewEncoder("gbk")
	output := enc.ConvertString(result2.String())

	c.Ctx.Output.Body([]byte(output))
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:59,代码来源:down.go


示例2: Post

// @Title Post
// @Description create FaultData
// @Param	body		body 	models.FaultData	true		"body for FaultData content"
// @Success 200 {int} models.FaultData.Id
// @Failure 403 body is empty
// @router / [post]
func (c *FaultDataController) Post() {
	var result models.Result
	var v models.FaultData
	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
	if id, err := models.AddFaultData(&v); err == nil {
		result.Success = true
		result.Data = map[string]int64{"id": id}
		c.Data["json"] = result
	} else {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:22,代码来源:fault_data.go


示例3: GetOne

// @Title Get
// @Description get FaultData by id
// @Param	id		path 	string	true		"The key for staticblock"
// @Success 200 {object} models.FaultData
// @Failure 403 :id is empty
// @router /:id [get]
func (c *FaultDataController) GetOne() {
	var result models.Result
	idStr := c.Ctx.Input.Params[":id"]
	id, _ := strconv.Atoi(idStr)
	v, err := models.GetFaultDataById(id)
	if err != nil {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	} else {
		result.Success = true
		result.Data = v
		c.Data["json"] = result
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:23,代码来源:fault_data.go


示例4: Delete

// @Title Delete
// @Description delete the FaultData
// @Param	id		path 	string	true		"The id you want to delete"
// @Success 200 {string} delete success!
// @Failure 403 id is empty
// @router /:id [delete]
func (c *FaultDataController) Delete() {

	var result models.Result
	idStr := c.Ctx.Input.Params[":id"]
	id, _ := strconv.Atoi(idStr)
	if err := models.DeleteFaultData(id); err == nil {
		result.Success = true
		result.Data = "ok"
		c.Data["json"] = result
	} else {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:23,代码来源:fault_data.go


示例5: Put

// @Title Update
// @Description update the FaultData
// @Param	id		path 	string	true		"The id you want to update"
// @Param	body		body 	models.FaultData	true		"body for FaultData content"
// @Success 200 {object} models.FaultData
// @Failure 403 :id is not int
// @router /:id [put]
func (c *FaultDataController) Put() {

	var result models.Result
	idStr := c.Ctx.Input.Params[":id"]
	id, _ := strconv.Atoi(idStr)
	v := models.FaultData{Id: id}
	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
	if err := models.UpdateFaultDataById(&v); err == nil {
		result.Success = true
		result.Data = "ok"
		c.Data["json"] = result
	} else {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:26,代码来源:fault_data.go


示例6: GetAll

// @Title Get All
// @Description get FaultData
// @Param	query	query	string	false	"Filter. e.g. col1:v1,col2:v2 ..."
// @Param	fields	query	string	false	"Fields returned. e.g. col1,col2 ..."
// @Param	sortby	query	string	false	"Sorted-by fields. e.g. col1,col2 ..."
// @Param	order	query	string	false	"Order corresponding to each sortby field, if single value, apply to all sortby fields. e.g. desc,asc ..."
// @Param	limit	query	string	false	"Limit the size of result set. Must be an integer"
// @Param	offset	query	string	false	"Start position of result set. Must be an integer"
// @Success 200 {object} models.FaultData
// @Failure 403
// @router / [get]
func (c *FaultDataController) GetAll() {
	var fields []string
	var sortby []string
	var order []string
	var query map[string]string = make(map[string]string)
	var limit int64 = 10
	var offset int64 = 0
	var result models.Result

	// fields: col1,col2,entity.col3
	if v := c.GetString("fields"); v != "" {
		fields = strings.Split(v, ",")
	}
	// limit: 10 (default is 10)
	if v, err := c.GetInt64("limit"); err == nil {
		limit = v
	}
	// offset: 0 (default is 0)
	if v, err := c.GetInt64("offset"); err == nil {
		offset = v
	}
	// sortby: col1,col2
	if v := c.GetString("sortby"); v != "" {
		sortby = strings.Split(v, ",")
	}
	// order: desc,asc
	if v := c.GetString("order"); v != "" {
		order = strings.Split(v, ",")
	}
	// query: k:v,k:v
	if v := c.GetString("query"); v != "" {
		for _, cond := range strings.Split(v, ",") {
			kv := strings.Split(cond, ":")
			if len(kv) != 2 {
				result.Success = false
				result.Data = errors.New("Error: invalid query key/value pair")
				c.Data["json"] = result
				c.Abort("400")
			}
			k, v := kv[0], kv[1]
			query[k] = v
		}
	}

	l, err := models.GetAllFaultData(query, fields, sortby, order, offset, limit)
	if err != nil {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	} else {
		result.Success = true
		result.Data = l
		c.Data["json"] = result
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:68,代码来源:fault_data.go


示例7: GetErrDetail

// @Title Get Error Time detail
// @Description get a period of time error detail
// @Param       starttime    query   string    "service starttime"
// @Param       endtime      query   string    "service endtime"
// @Param       ns           query   string    "ns name"
// @Success 200 {object} models.FaultData
// @Failure 403 body  is empty
// @router /errtime/detail/
func (c *FaultDataController) GetErrDetail() {

	var starttime int64
	var endtime int64
	var ns string
	var detail interface{}
	var err error
	var result models.Result

	//获取ns
	ns = c.GetString("ns")

	nslist := strings.Split(ns, ".")
	if nslist[len(nslist)-1] != "com" {
		result.Success = false
		result.Data = "ns is not correct! len is too short or .com should be at the end of ns"
		c.Data["json"] = result
		c.Abort("400")
	}

	now := time.Now()
	days := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC).Day()
	next_time := now.AddDate(0, 0, days)

	start_month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
	end_month := time.Date(next_time.Year(), next_time.Month(), 1, 0, 0, 0, 0, time.Local)

	//获取starttime
	starttime, err = c.GetInt64("starttime")
	if err != nil {
		//如果为空,设置初始值为当月第一天
		starttime = start_month.Unix()
	}

	//获取endtime
	endtime, err = c.GetInt64("endtime")
	if err != nil {
		//如果为空,设置截止时间为当前时间
		endtime = end_month.Unix()
	}

	//获取故障详情
	detail, err = models.GetErrTimeDetail(starttime, endtime, ns)
	if err != nil {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Abort("400")
	} else {
		result.Success = true
		result.Data = detail
		c.Data["json"] = result
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:63,代码来源:fault_data.go


示例8: GetErrPercent

// @Title Get Error Time Percent
// @Description get rangetime to caculate errtime percent
// @Param       starttime    query   string    "service starttime"
// @Param       endtime      query   string    "service endtime"
// @Param       ns           query   string    "ns name"
// @Success 200 {object} models.FaultData
// @Failure 403 body  is empty
// @router /availability
func (c *FaultDataController) GetErrPercent() {

	var starttime int64
	var endtime int64
	var ns string
	var percent float64
	var err error
	var result models.Result

	//获取ns
	ns = c.GetString("ns")
	if ns == "" {
		result.Success = true
		result.Data = "100.00%"
		c.Data["json"] = result
		c.ServeJson()
		return
	}

	nslist := strings.Split(ns, ".")
	if nslist[len(nslist)-1] != "com" {
		result.Success = false
		result.Data = "ns is not correct! len is too short or .com should be at the end of ns"
		c.Data["json"] = result
		c.Ctx.Output.SetStatus(400)
		c.Abort("400")
	}

	now := time.Now()
	days := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC).Day()
	next_time := now.AddDate(0, 0, days)

	start_month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
	end_month := time.Date(next_time.Year(), next_time.Month(), 1, 0, 0, 0, 0, time.Local)

	//获取starttime
	starttime, err = c.GetInt64("starttime")
	if err != nil {
		//如果为空,设置初始值为当月第一天
		starttime = start_month.Unix()
	}

	//获取endtime
	endtime, err = c.GetInt64("endtime")
	if err != nil {
		//如果为空,设置截止时间为当前时间
		endtime = end_month.Unix()
	}

	//获取故障时间百分比
	percent, err = models.GetErrTimePercent(starttime, endtime, ns)
	if err != nil {
		result.Success = false
		result.Data = err.Error()
		c.Data["json"] = result
		c.Ctx.Output.SetStatus(400)
	} else {
		result.Success = true
		result.Data = fmt.Sprintf("%.5f%%", (1-percent)*100)
		c.Data["json"] = result
	}
	c.ServeJson()
}
开发者ID:guaiguaihw,项目名称:fault,代码行数:71,代码来源:fault_data.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang log.Debug函数代码示例发布时间:2022-05-24
下一篇:
Golang fancy.Reader类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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