本文整理匯總了Golang中models.Product.SetName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Product.SetName方法的具體用法?Golang Product.SetName怎麽用?Golang Product.SetName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Product
的用法示例。
在下文中一共展示了Product.SetName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Test_ConvertsProductToViewModel
func Test_ConvertsProductToViewModel(t *testing.T) {
product := models.Product{}
product.SetName("the name")
product.SetDescriptionShort("the short description")
product.SetDescriptionLong("the long description")
product.SetPricePerLitre(42.127)
product.SetPricePer10Litre(27.314)
product.SetOrigin("the origin")
product.SetIsOrganic(true)
product.SetImageUrl("the image URL")
product.SetId(42)
result := ConvertProductToViewModel(product)
if product.Name() != result.Name {
t.Fail()
}
if product.DescriptionShort() != result.DescriptionShort {
t.Fail()
}
if product.DescriptionLong() != result.DescriptionLong {
t.Fail()
}
if product.PricePerLitre() != result.PricePerLitre {
t.Fail()
}
if product.PricePer10Litre() != result.PricePer10Litre {
t.Fail()
}
if product.Origin() != result.Origin {
t.Fail()
}
if product.IsOrganic() != result.IsOrganic {
t.Fail()
}
if product.ImageUrl() != result.ImageUrl {
t.Fail()
}
if product.Id() != result.Id {
t.Fail()
}
}
示例2: get
func (this *profileController) get(w http.ResponseWriter, req *http.Request) {
vm := viewmodels.GetProfile()
responseWriter := util.GetResponseWriter(w, req)
ck, err := req.Cookie("goSessionId")
if err == nil {
vm.LoggedIn = true
userId, _ := strconv.Atoi(ck.Value)
modelMember, _ := models.GetMemberById(userId)
vm.Member = converter.ConvertMemberlToViewModel(modelMember)
if req.Method == "GET" {
var listOfProductIds []int
listOfProductIds, _ = models.GetMembersOrder(userId)
var listOfProducts []viewmodels.Product
for _, val := range listOfProductIds {
pr, _ := models.GetProduct(val)
listOfProducts = append(listOfProducts, converter.ConvertProductsToViewModel(pr))
}
vm.Products = listOfProducts
vm.LoggedIn = true
} else {
remButton := req.FormValue("remove")
remId, _ := strconv.Atoi(remButton)
if remButton == "" {
productName := req.FormValue("name")
productType := req.FormValue("type")
productDescription := req.FormValue("description")
productPrice := req.FormValue("price")
productImgUrl := req.FormValue("imageurl")
_, fileErr := models.GetProductByName(productName)
if fileErr != nil {
inputProduct := models.Product{}
inputProduct.SetName(productName)
inputProduct.SetDescription(productDescription)
inputProduct.SetImageUrl(productImgUrl)
typ, _ := strconv.Atoi(productType)
inputProduct.SetTyp(typ)
price64, _ := strconv.ParseFloat(productPrice, 2)
price := float32(price64)
inputProduct.SetPrice(price)
insertErr := models.InsertProduct(inputProduct)
if insertErr == nil {
http.Redirect(w, req, "/profile", http.StatusFound)
} else {
log.Fatal(insertErr.Error())
}
} else {
http.Redirect(w, req, "/home", http.StatusFound)
}
} else {
deleteErr := models.RemoveOrder(userId, remId)
if deleteErr == nil {
http.Redirect(w, req, "/profile", http.StatusFound)
}
}
}
} else {
http.Redirect(w, req, "/login", http.StatusFound)
}
w.Header().Add("Content-Type", "text/html")
this.template.Execute(responseWriter, vm)
defer responseWriter.Close()
}