本文整理匯總了Golang中github.com/ninnemana/API/models/cart.Customer.DefaultAddress方法的典型用法代碼示例。如果您正苦於以下問題:Golang Customer.DefaultAddress方法的具體用法?Golang Customer.DefaultAddress怎麽用?Golang Customer.DefaultAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ninnemana/API/models/cart.Customer
的用法示例。
在下文中一共展示了Customer.DefaultAddress方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetDefaultAddress
func SetDefaultAddress(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string {
var c cart.Customer
customerId := params["id"]
if !bson.IsObjectIdHex(customerId) {
apierror.GenerateError("invalid customer reference", nil, w, req)
return ""
}
c.Id = bson.ObjectIdHex(customerId)
c.ShopId = shop.Id
if err := c.Get(); err != nil {
apierror.GenerateError("", err, w, req)
return ""
}
addressId := params["address"]
if !bson.IsObjectIdHex(addressId) {
apierror.GenerateError("invalid address reference", nil, w, req)
return ""
}
found := false
for _, addr := range c.Addresses {
if addr.Id.Hex() == addressId {
c.DefaultAddress = &addr
found = true
break
}
}
if !found {
apierror.GenerateError("invalid address reference", nil, w, req)
return ""
}
if err := c.Update(); err != nil {
apierror.GenerateError(err.Error(), err, w, req)
return ""
}
return encoding.Must(enc.Encode(c))
}