本文整理匯總了Golang中github.com/coduno/api/model.Company.Save方法的典型用法代碼示例。如果您正苦於以下問題:Golang Company.Save方法的具體用法?Golang Company.Save怎麽用?Golang Company.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coduno/api/model.Company
的用法示例。
在下文中一共展示了Company.Save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PostCompany
// PostCompany creates a new company after validating by key.
func PostCompany(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
if r.Method != "POST" {
return http.StatusMethodNotAllowed, nil
}
var company model.Company
if err = json.NewDecoder(r.Body).Decode(&company); err != nil {
return http.StatusBadRequest, err
}
var companies model.Companys
_, err = model.NewQueryForCompany().
Filter("Address = ", company.Address.Address).
Limit(1).
GetAll(ctx, &companies)
if err != nil {
return http.StatusInternalServerError, err
}
if len(companies) > 0 {
return http.StatusConflict, errors.New("Already registered.")
}
var key *datastore.Key
if key, err = company.Save(ctx); err != nil {
return http.StatusInternalServerError, err
}
// TODO(flowlo): Respond with HTTP 201 and include a
// location header and caching information.
json.NewEncoder(w).Encode(company.Key(key))
return http.StatusOK, nil
}