當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CustomerUser.NotCustomer方法代碼示例

本文整理匯總了Golang中github.com/ninnemana/API/models/customer.CustomerUser.NotCustomer方法的典型用法代碼示例。如果您正苦於以下問題:Golang CustomerUser.NotCustomer方法的具體用法?Golang CustomerUser.NotCustomer怎麽用?Golang CustomerUser.NotCustomer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ninnemana/API/models/customer.CustomerUser的用法示例。


在下文中一共展示了CustomerUser.NotCustomer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UpdateCustomerUser

func UpdateCustomerUser(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params) string {
	var err error
	var cu customer.CustomerUser

	qs := r.URL.Query()
	key := qs.Get("key")

	if params["id"] != "" {
		cu.Id = params["id"]
	} else if r.FormValue("id") != "" {
		cu.Id = r.FormValue("id")
	} else {
		err = errors.New("Trouble getting customer user ID")
		apierror.GenerateError("Trouble getting customer user ID", err, rw, r)
		return ""
	}

	if err = cu.Get(key); err != nil {
		apierror.GenerateError("Trouble getting customer user", err, rw, r)
		return ""
	}

	if strings.ToLower(r.Header.Get("Content-Type")) == "application/json" {
		var data []byte
		if data, err = ioutil.ReadAll(r.Body); err != nil {
			apierror.GenerateError("Trouble reading request body while updating customer user", err, rw, r)
			return ""
		}
		if err = json.Unmarshal(data, &cu); err != nil {
			apierror.GenerateError("Trouble unmarshalling json request body while updating customer user", err, rw, r)
			return ""
		}
	} else {
		name := r.FormValue("name")
		email := r.FormValue("email")
		isActive := r.FormValue("isActive")
		locationID := r.FormValue("locationID")
		isSudo := r.FormValue("isSudo")
		notCustomer := r.FormValue("notCustomer")
		if name != "" {
			cu.Name = name
		}
		if email != "" {
			cu.Email = email
		}
		if isActive != "" {
			if cu.Active, err = strconv.ParseBool(isActive); err != nil {
				cu.Active = false
			}
		}
		if locationID != "" {
			if cu.Location.Id, err = strconv.Atoi(locationID); err != nil {
				apierror.GenerateError("Trouble getting location ID", err, rw, r)
				return ""
			}
		}
		if isSudo != "" {
			if cu.Sudo, err = strconv.ParseBool(isSudo); err != nil {
				cu.Sudo = false
			}
		}
		if notCustomer != "" {
			if cu.NotCustomer, err = strconv.ParseBool(notCustomer); err != nil {
				cu.NotCustomer = false
			}
		}
	}

	if err = cu.UpdateCustomerUser(); err != nil {
		apierror.GenerateError("Trouble updating customer user", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(cu))
}
開發者ID:ninnemana,項目名稱:API,代碼行數:75,代碼來源:user.go


注:本文中的github.com/ninnemana/API/models/customer.CustomerUser.NotCustomer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。