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

Golang errors.InternalServerError函数代码示例

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

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



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

示例1: consumeProduct

func consumeProduct(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Product{}
	params := r.URL.Query()
	if err := FillProductIdWithUrlValue(&p, params); err != nil {
		return errors.BadRequest(err.Error())
	}

	qt, err := strconv.Atoi(params.Get("quantity"))

	if err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := p.Consume(db, qt); err != nil {
		return errors.InternalServerError(err.Error())
	}

	ps, err := p.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(ps) != 1 {
		return errors.InternalServerError("[ERROR] Unexpected error occured during exeuction of /api/inventory/product/:id/consume/:quantity")
	}

	rend.JSON(w, http.StatusOK, ps[0])
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:29,代码来源:productController.go


示例2: deleteTreatment

func deleteTreatment(w http.ResponseWriter, r *http.Request) errors.Http {
	t := models.Treatment{}
	if err := FillTreatmentIdWIthUrlValue(&t, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := t.Delete(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, t.ID)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:13,代码来源:treatment_controller.go


示例3: insertProduct

func insertProduct(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Product{}
	if err := BuildStructFromReqBody(&p, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := p.Save(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, p)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:13,代码来源:productController.go


示例4: deleteMedication

func deleteMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medication{}
	if err := FillMedicationIdWIthUrlValue(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := m.Delete(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, m.ID)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:13,代码来源:medicationController.go


示例5: deleteProduct

func deleteProduct(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Product{}
	if err := FillProductIdWithUrlValue(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := p.Delete(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, p)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:13,代码来源:productController.go


示例6: validataTreatment

func validataTreatment(w http.ResponseWriter, r *http.Request) errors.Http {
	id, err := strconv.Atoi(r.URL.Query().Get("treatment_id"))
	if err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := db.Exec("UPDATE treatments SET status = 0 WHERE id = ?", id).Error; err != nil {
		return errors.InternalServerError(err.Error())
	}

	t := models.Treatment{ID: id}
	sendTreatmentApproved(&t)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:14,代码来源:treatment_controller.go


示例7: cancelOrder

func cancelOrder(w http.ResponseWriter, r *http.Request) errors.Http {
	order := models.Order{}

	if err := FillOrderIdWithUrlValue(&order, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := order.Cancel(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, order.ID)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:14,代码来源:orderController.go


示例8: insertTreatment

func insertTreatment(w http.ResponseWriter, r *http.Request) errors.Http {
	t := models.Treatment{}
	if err := BuildStructFromReqBody(&t, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := t.Save(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	sendTreatmentCreated(&t)

	rend.JSON(w, http.StatusOK, t)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:15,代码来源:treatment_controller.go


示例9: insertMedication

func insertMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	im := models.IntermediateMedication{}
	if err := BuildStructFromReqBody(&im, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	m := im.Medication()

	if err := m.Save(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	sendProductCreated(m)

	rend.JSON(w, http.StatusOK, m)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:17,代码来源:medicationController.go


示例10: updateTreatment

func updateTreatment(w http.ResponseWriter, r *http.Request) errors.Http {
	t := models.Treatment{}

	if err := BuildStructFromReqBody(&t, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := FillTreatmentIdWIthUrlValue(&t, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := t.Update(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, t)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:18,代码来源:treatment_controller.go


示例11: handleMedicUpdate

func handleMedicUpdate(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medic{}

	if err := BuildStructFromReqBody(&m, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := FillMedicIdWIthUrlValue(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := m.Update(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, m)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:18,代码来源:medic_controller.go


示例12: retreiveProduct

func retreiveProduct(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Product{}
	if err := BuildStructFromQueryString(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	products, err := p.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(products) == 0 {
		return errors.NotFound("record not found")
	}
	rend.JSON(w, http.StatusOK, products)

	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:18,代码来源:productController.go


示例13: handlePharmacistUpdate

func handlePharmacistUpdate(w http.ResponseWriter, r *http.Request) errors.Http {
	p := models.Pharmacist{}

	if err := BuildStructFromReqBody(&p, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := FillPharmacistIdWIthUrlValue(&p, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := p.Update(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, p)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:18,代码来源:pharmacist_controller.go


示例14: retreiveOrderById

func retreiveOrderById(w http.ResponseWriter, r *http.Request) errors.Http {
	o := models.Order{}

	if err := FillOrderIdWithUrlValue(&o, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	orders, err := o.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(orders) != 1 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, orders[0])
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:19,代码来源:orderController.go


示例15: updatePurchaseProductOnValue

func updatePurchaseProductOnValue(w http.ResponseWriter, r *http.Request) errors.Http {
	pp := models.PurchaseProduct{}

	if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	value, err := strconv.ParseFloat(r.URL.Query().Get("value"), 64)
	if err != nil {
		errors.BadRequest(err.Error())
	}

	if err := pp.UpdateValue(db, value); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, pp)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:19,代码来源:purchaseProductsController.go


示例16: updatePurchaseProductOnQuantity

func updatePurchaseProductOnQuantity(w http.ResponseWriter, r *http.Request) errors.Http {
	pp := models.PurchaseProduct{}

	if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	quantity, err := strconv.Atoi(r.URL.Query().Get("quantity"))
	if err != nil {
		errors.BadRequest(err.Error())
	}

	if err := pp.UpdateQuantity(db, quantity); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, pp)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:19,代码来源:purchaseProductsController.go


示例17: retreivePurchaseProductsById

func retreivePurchaseProductsById(w http.ResponseWriter, r *http.Request) errors.Http {
	pp := models.PurchaseProduct{}

	if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	pproducts, err := pp.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(pproducts) != 1 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, pproducts[0])
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:19,代码来源:purchaseProductsController.go


示例18: uploadRecipe

func uploadRecipe(w http.ResponseWriter, r *http.Request) errors.Http {
	prescriptionId := r.URL.Query().Get("prescription_id")
	file, _, err := r.FormFile("receipt")
	if err != nil {
		fmt.Println(err)
		return errors.BadRequest("Invalid file")
	}

	defer file.Close()

	pid, _ := strconv.Atoi(prescriptionId)
	rcpt := &models.Receipt{FilePath: "", Status: models.ReceiptStatusUndecided, PrescriptionId: pid}
	rcpt.Create(db)
	rcpt.FilePath = "upload/" + prescriptionId + "/" + strconv.Itoa(int(rcpt.ID))
	rcpt.Save(db) // ID incremental :'(
	prescr := models.Prescription{ID: rcpt.PrescriptionId}
	fmt.Println("[DEBUG] prescri query obj: ", prescr)
	prescrs, err := prescr.Retreive(db)
	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
	}

	fmt.Println("[DEBUG] prescrs retrieved ", prescrs)
	if prescrs != nil && len(prescrs) >= 1 {
		fmt.Println("[DEBUG] Saving rcpt.id: ", rcpt.ID, " on prescriptionId: ", prescrs[0].ID)
		prescrs[0].ReceiptId = rcpt.ID
		if err := prescrs[0].Update(db); err != nil {
			fmt.Println("[ERROR] ", err.Error())
		}
	}

	os.MkdirAll("upload/"+prescriptionId, 0777)
	out, err := os.Create("upload/" + prescriptionId + "/" + strconv.Itoa(int(rcpt.ID)))
	fmt.Println(err)
	_, err = io.Copy(out, file)
	fmt.Println(err)
	if err != nil {
		return errors.InternalServerError("Error uploading image")
	}
	rend.JSON(w, 200, rcpt)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:42,代码来源:receipt_controller.go


示例19: updateMedication

func updateMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	im := models.IntermediateMedication{}

	if err := BuildStructFromReqBody(&im, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	m := im.Medication()

	if err := FillMedicationIdWIthUrlValue(m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := m.Update(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, m)
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:20,代码来源:medicationController.go


示例20: retreiveOrder

func retreiveOrder(w http.ResponseWriter, r *http.Request) errors.Http {
	queryString := r.URL.Query()
	var o models.Order
	decoder := decoder.NewDecoder()

	if err := decoder.DecodeURLValues(&o, queryString); err != nil {
		return errors.BadRequest(err.Error())
	}

	orders, err := o.Retreive(db)
	if err != nil {
		return errors.InternalServerError(err.Error())
	}

	if len(orders) == 0 {
		return errors.NotFound("record not found")
	}

	rend.JSON(w, http.StatusOK, orders)
	return nil
}
开发者ID:asvins,项目名称:warehouse,代码行数:21,代码来源:orderController.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang models.Product类代码示例发布时间:2022-05-24
下一篇:
Golang errors.BadRequest函数代码示例发布时间: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