本文整理匯總了Golang中github.com/ninnemana/API/helpers/encoding.Must函數的典型用法代碼示例。如果您正苦於以下問題:Golang Must函數的具體用法?Golang Must怎麽用?Golang Must使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Must函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PlatinumEtailers
func PlatinumEtailers(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
cust, err := customer.GetWhereToBuyDealers(dtx)
if err != nil {
apierror.GenerateError("Error retrieving platinum etailers.", err, w, r)
}
return encoding.Must(enc.Encode(cust))
}
示例2: GetAllSalesReps
func GetAllSalesReps(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder) string {
reps, err := salesrep.GetAllSalesReps()
if err != nil {
apierror.GenerateError("Trouble getting all sales reps", err, rw, req)
}
return encoding.Must(enc.Encode(reps))
}
示例3: Search
func Search(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
var err error
title := r.FormValue("title")
slug := r.FormValue("slug")
text := r.FormValue("text")
createdDate := r.FormValue("createdDate")
publishedDate := r.FormValue("publishedDate")
lastModified := r.FormValue("lastModified")
userID := r.FormValue("userID")
metaTitle := r.FormValue("metaTitle")
metaDescription := r.FormValue("metaDescription")
keywords := r.FormValue("keywords")
active := r.FormValue("active")
page := r.FormValue("page")
results := r.FormValue("results")
l, err := blog_model.Search(title, slug, text, publishedDate, createdDate, lastModified, userID, metaTitle, metaDescription, keywords, active, page, results, dtx)
if err != nil {
apierror.GenerateError("Trouble searching for blog", err, rw, r)
}
return encoding.Must(enc.Encode(l))
}
示例4: GetAllMenus
func GetAllMenus(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
m, err := site.GetAllMenus(dtx)
if err != nil {
apierror.GenerateError("Trouble getting all site menus", err, rw, req)
}
return encoding.Must(enc.Encode(m))
}
示例5: SaveMenu
func SaveMenu(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
var m site.Menu
var err error
idStr := params["id"]
if idStr != "" {
m.Id, err = strconv.Atoi(idStr)
err = m.Get(dtx)
if err != nil {
apierror.GenerateError("Trouble getting site menu ID", err, rw, req)
}
}
//json
requestBody, err := ioutil.ReadAll(req.Body)
if err != nil {
apierror.GenerateError("Trouble reading request body for saving site menu", err, rw, req)
}
err = json.Unmarshal(requestBody, &m)
if err != nil {
apierror.GenerateError("Trouble unmarshalling request body for saving site menu", err, rw, req)
}
//create or update
if m.Id > 0 {
err = m.Update()
} else {
err = m.Create()
}
if err != nil {
apierror.GenerateError("Trouble saving site menu", err, rw, req)
}
return encoding.Must(enc.Encode(m))
}
示例6: AddAccount
// Create a customer for a
// given shop.
func AddAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string {
var c cart.Customer
defer req.Body.Close()
data, err := ioutil.ReadAll(req.Body)
if err != nil {
apierror.GenerateError(err.Error(), err, w, req)
return ""
}
if err = json.Unmarshal(data, &c); err != nil {
apierror.GenerateError(err.Error(), err, w, req)
return ""
}
c.ShopId = shop.Id
if err = c.Insert(req.Referer()); err != nil {
apierror.GenerateError(err.Error(), err, w, req)
return ""
}
return encoding.Must(enc.Encode(c))
}
示例7: GetAllGroups
func GetAllGroups(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
groups, err := forum.GetAllGroups(dtx)
if err != nil {
apierror.GenerateError("Trouble getting all forum groups", err, rw, req)
}
return encoding.Must(enc.Encode(groups))
}
示例8: GetCategory
// GetCategory
func GetCategory(rw http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
var c category.Category
var err error
c.CategoryID, err = strconv.Atoi(params["id"])
if err != nil || c.CategoryID == 0 {
apierror.GenerateError("Trouble getting category identifier", err, rw, r)
return ""
}
qs := r.URL.Query()
page := 1
count := 50
if pg := qs.Get("page"); pg != "" {
page, _ = strconv.Atoi(pg)
}
if ct := qs.Get("count"); ct != "" {
count, _ = strconv.Atoi(ct)
}
err = c.Get(page, count)
if err != nil || c.CategoryID == 0 {
apierror.GenerateError("Trouble getting category", err, rw, r)
return ""
}
return encoding.Must(enc.Encode(c))
}
示例9: GetCategoryParts
func GetCategoryParts(rw http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
catIdStr := params["id"]
catId, err := strconv.Atoi(catIdStr)
if err != nil {
apierror.GenerateError("Trouble getting category Id", err, rw, r)
return ""
}
qs := r.URL.Query()
page := 1
count := 50
if pg := qs.Get("page"); pg != "" {
page, _ = strconv.Atoi(pg)
}
if ct := qs.Get("count"); ct != "" {
count, _ = strconv.Atoi(ct)
}
parts, err := category.GetCategoryParts(catId, page, count)
if err != nil {
apierror.GenerateError("Trouble getting parts", err, rw, r)
return ""
}
return encoding.Must(enc.Encode(parts))
}
示例10: CreateApplication
func CreateApplication(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext, params martini.Params) string {
var app products.NoSqlVehicle
collection := params["collection"]
if collection == "" {
apierror.GenerateError("No Collection in URL", nil, w, r)
return ""
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
apierror.GenerateError("Error reading request body", nil, w, r)
return ""
}
if err = json.Unmarshal(body, &app); err != nil {
apierror.GenerateError("Error decoding vehicle application", nil, w, r)
return ""
}
if err = app.Create(collection); err != nil {
apierror.GenerateError("Error updating vehicle", nil, w, r)
return ""
}
return encoding.Must(enc.Encode(app))
}
示例11: AddTopic
func AddTopic(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
var err error
var topic forum.Topic
if topic.GroupID, err = strconv.Atoi(req.FormValue("groupID")); err != nil {
apierror.GenerateError("Trouble getting forum group ID for new topic", err, rw, req)
}
if req.FormValue("closed") != "" {
if topic.Closed, err = strconv.ParseBool(req.FormValue("closed")); err != nil {
apierror.GenerateError("Trouble adding forum topic -- boolean closed parameter is invalid", err, rw, req)
}
}
topic.Name = req.FormValue("name")
topic.Description = req.FormValue("description")
topic.Image = req.FormValue("image")
topic.Active = true
if err = topic.Add(); err != nil {
apierror.GenerateError("Trouble adding forum topic", err, rw, req)
}
return encoding.Must(enc.Encode(topic))
}
示例12: UpdateBrand
func UpdateBrand(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
var err error
var br brand.Brand
if br.ID, err = strconv.Atoi(params["id"]); err != nil {
apierror.GenerateError("Trouble getting brand ID", err, rw, req)
}
if err = br.Get(); err != nil {
apierror.GenerateError("Trouble getting brand", err, rw, req)
}
if req.FormValue("name") != "" {
br.Name = req.FormValue("name")
}
if req.FormValue("code") != "" {
br.Code = req.FormValue("code")
}
if err := br.Update(); err != nil {
apierror.GenerateError("Trouble updating brand", err, rw, req)
}
return encoding.Must(enc.Encode(br))
}
示例13: GetAllBrands
func GetAllBrands(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder) string {
brands, err := brand.GetAllBrands()
if err != nil {
apierror.GenerateError("Trouble getting all brands", err, rw, req)
}
return encoding.Must(enc.Encode(brands))
}
示例14: GetContent
func GetContent(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
var c site.Content
var err error
idStr := params["id"]
id, err := strconv.Atoi(idStr)
if err == nil {
//Thar be an Id int
c.Id = id
err = c.Get(dtx)
if err != nil {
apierror.GenerateError("Trouble getting site content by Id.", err, rw, req)
return ""
}
}
//Thar be a slug
c.Slug = idStr
err = c.GetBySlug(dtx)
if err != nil {
apierror.GenerateError("Trouble getting site content by slug.", err, rw, req)
return ""
}
return encoding.Must(enc.Encode(c))
}
示例15: Create
func Create(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
var n news_model.News
var err error
n.Title = r.FormValue("title")
n.Lead = r.FormValue("lead")
n.Content = r.FormValue("content")
start := r.FormValue("start")
end := r.FormValue("end")
active := r.FormValue("active")
n.Slug = r.FormValue("slug")
if start != "" {
n.PublishStart, err = time.Parse(timeFormat, start)
}
if end != "" {
n.PublishEnd, err = time.Parse(timeFormat, end)
}
if active != "" {
n.Active, err = strconv.ParseBool(active)
}
err = n.Create(dtx)
if err != nil {
apierror.GenerateError("Trouble creating news", err, rw, r)
return ""
}
return encoding.Must(enc.Encode(n))
}