当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.BadRequest函数代码示例

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


在下文中一共展示了BadRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: DefRoutes

func DefRoutes() *router.Router {
	r := router.NewRouter()
	r.Handle("/api/discovery", router.GET, func(w http.ResponseWriter, r *http.Request) errors.Http {
		fmt.Fprint(w, "NOTIFICATION MODULE - TODO")
		return nil
	}, []router.Interceptor{})

	r.Handle("/api/mailTest", router.GET, func(w http.ResponseWriter, r *http.Request) errors.Http {
		m := mailer.Mail{
			To:      []string{"[email protected]"},
			Subject: "Está na hora de tomar sua medicação!",
			Body:    mailer.TemplatePackTime,
		}

		b, err := json.Marshal(&m)
		if err != nil {
			return errors.BadRequest(err.Error())
		}

		producer.Publish("send_mail", b)
		fmt.Fprintf(w, "[INFO] Email sent")
		return nil
	}, []router.Interceptor{})

	return r
}
开发者ID:asvins,项目名称:notification,代码行数:26,代码来源:routes.go

示例3: validateRecipe

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

	rcpt := models.FetchReceipt(pres_id, db)
	if r.ParseForm() != nil {
		return errors.BadRequest("Invalid input")
	}
	if rcpt.UpdateStatus(models.RecipeStringToStatus(r.Form.Get("status")), db) != nil {
		return errors.NotFound("Not found")
	}
	rend.JSON(w, 200, "{}")
	return nil
}
开发者ID:asvins,项目名称:core,代码行数:16,代码来源:receipt_controller.go

示例4: retreiveOpenOrder

func retreiveOpenOrder(w http.ResponseWriter, r *http.Request) errors.Http {
	order, err := models.GetOpenOrder(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

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

示例5: updateProduct

func updateProduct(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 := FillProductIdWithUrlValue(&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,项目名称:warehouse,代码行数:18,代码来源:productController.go

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: retreiveMedication

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

	m.Base.Query = r.URL.Query()

	medications, err := m.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

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

	return nil
}
开发者ID:asvins,项目名称:core,代码行数:20,代码来源:medicationController.go

示例12: retrievePacks

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

	p.Base.Query = r.URL.Query()

	packs, err := p.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

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

	return nil
}
开发者ID:asvins,项目名称:operations,代码行数:20,代码来源:packController.go

示例13: retrieveBoxes

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

	b.Base.Query = r.URL.Query()

	boxes, err := b.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

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

	return nil
}
开发者ID:asvins,项目名称:operations,代码行数:20,代码来源:boxController.go

示例14: retreiveTreatments

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

	t.Base.Query = r.URL.Query()

	treatments, err := t.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

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

	return nil
}
开发者ID:asvins,项目名称:core,代码行数:20,代码来源:treatment_controller.go

示例15: 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


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