本文整理匯總了Golang中github.com/ninnemana/API/models/customer.Customer.GetCustomerIdFromKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang Customer.GetCustomerIdFromKey方法的具體用法?Golang Customer.GetCustomerIdFromKey怎麽用?Golang Customer.GetCustomerIdFromKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ninnemana/API/models/customer.Customer
的用法示例。
在下文中一共展示了Customer.GetCustomerIdFromKey方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetCustomer
func GetCustomer(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
var err error
var c customer.Customer
if err = c.GetCustomerIdFromKey(dtx.APIKey); err != nil {
apierror.GenerateError("Trouble getting customer ID", err, rw, r)
return ""
}
if err = c.GetCustomer(dtx.APIKey); err != nil {
apierror.GenerateError("Trouble getting customer", err, rw, r, http.StatusServiceUnavailable)
return ""
}
lowerKey := strings.ToLower(dtx.APIKey)
for i, u := range c.Users {
for _, k := range u.Keys {
if strings.ToLower(k.Key) == lowerKey {
c.Users[i].Current = true
}
}
}
return encoding.Must(enc.Encode(c))
}
示例2: approveuser
func approveuser(r *http.Request) bool {
api := r.URL.Query().Get("key")
if api == "" {
return false
}
c := customer.Customer{}
err := c.GetCustomerIdFromKey(api)
if err != nil || c.Id == 0 {
return false
}
return true
}
示例3: GetByPrivateKey
func GetByPrivateKey(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
var err error
var webProperties webProperty_model.WebProperties
privateKey := r.FormValue("key")
cust := customer.Customer{}
if err = cust.GetCustomerIdFromKey(privateKey); err != nil {
apierror.GenerateError("Trouble getting customer", err, rw, r)
return ""
}
if webProperties, err = webProperty_model.GetByCustomer(cust.Id, dtx); err != nil {
apierror.GenerateError("Trouble getting web property", err, rw, r)
return ""
}
return encoding.Must(enc.Encode(webProperties))
}
示例4: CreateUpdateWebProperty
func CreateUpdateWebProperty(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
var w webProperty_model.WebProperty
var err error
cust := customer.Customer{}
if err = cust.GetCustomerIdFromKey(dtx.APIKey); err != nil {
apierror.GenerateError("Trouble getting customer ID from API Key", err, rw, r)
return ""
}
w.CustID = cust.Id
//determine content type
contType := r.Header.Get("Content-Type")
if contType == "application/json" {
//json
requestBody, err := ioutil.ReadAll(r.Body)
if err != nil {
apierror.GenerateError("Trouble reading request body while saving web property", err, rw, r)
return ""
}
if err = json.Unmarshal(requestBody, &w); err != nil {
apierror.GenerateError("Trouble unmarshalling request body while saving web property", err, rw, r)
return ""
}
} else {
if r.FormValue("id") != "" || params["id"] != "" {
idStr := r.FormValue("id")
if idStr == "" {
idStr = params["id"]
}
if w.ID, err = strconv.Atoi(idStr); err != nil {
apierror.GenerateError("Trouble getting web property ID", err, rw, r)
return ""
}
if err = w.Get(dtx); err != nil {
apierror.GenerateError("Trouble getting web property", err, rw, r)
return ""
}
}
name := r.FormValue("name")
url := r.FormValue("url")
isEnabled := r.FormValue("isEnabled")
sellerID := r.FormValue("sellerID")
webPropertyTypeID := r.FormValue("webPropertyTypeID")
isFinalApproved := r.FormValue("isApproved")
enabledDate := r.FormValue("enabledDate")
isDenied := r.FormValue("isDenied")
requestedDate := r.FormValue("requestedDate")
typeID := r.FormValue("typeID")
if name != "" {
w.Name = name
}
if url != "" {
w.Url = url
}
if isEnabled != "" {
if w.IsEnabled, err = strconv.ParseBool(isEnabled); err != nil {
apierror.GenerateError("Trouble parsing boolean value for webproperty.isEnabled", err, rw, r)
return ""
}
}
if sellerID != "" {
w.SellerID = sellerID
}
if webPropertyTypeID != "" {
if w.WebPropertyType.ID, err = strconv.Atoi(webPropertyTypeID); err != nil {
apierror.GenerateError("Trouble getting web property type ID", err, rw, r)
return ""
}
}
if isFinalApproved != "" {
if w.IsFinalApproved, err = strconv.ParseBool(isFinalApproved); err != nil {
apierror.GenerateError("Trouble parsing boolean value for webproperty.isApproved", err, rw, r)
return ""
}
}
if enabledDate != "" {
en, err := time.Parse(timeFormat, enabledDate)
if err != nil {
apierror.GenerateError("Trouble parsing date for webproperty.enabledDate", err, rw, r)
return ""
}
w.IsEnabledDate = &en
}
if isDenied != "" {
if w.IsDenied, err = strconv.ParseBool(isDenied); err != nil {
apierror.GenerateError("Trouble parsing boolean value for webproperty.isDenied", err, rw, r)
return ""
}
}
if requestedDate != "" {
req, err := time.Parse(timeFormat, requestedDate)
if err != nil {
//.........這裏部分代碼省略.........