本文整理汇总了Golang中github.com/coduno/api/model.Company类的典型用法代码示例。如果您正苦于以下问题:Golang Company类的具体用法?Golang Company怎么用?Golang Company使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Company类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetCompanyByUser
func GetCompanyByUser(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != "GET" {
return http.StatusMethodNotAllowed, nil
}
p, ok := passenger.FromContext(ctx)
if !ok {
return http.StatusUnauthorized, nil
}
var u model.User
if err := datastore.Get(ctx, p.User, &u); err != nil {
return http.StatusInternalServerError, nil
}
if u.Company == nil {
return http.StatusUnauthorized, nil
}
// The account is associated with a company, so we return it.
var company model.Company
if err := datastore.Get(ctx, u.Company, &company); err != nil {
return http.StatusInternalServerError, err
}
json.NewEncoder(w).Encode(company.Key(u.Company))
return http.StatusOK, nil
}
开发者ID:pbochis,项目名称:api,代码行数:28,代码来源:user.go
示例2: 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.Put(ctx, nil); 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
}
开发者ID:pbochis,项目名称:api,代码行数:36,代码来源:company.go
示例3: GetCompanyByUser
func GetCompanyByUser(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
if !util.CheckMethod(r, "GET") {
return http.StatusMethodNotAllowed, nil
}
p, ok := passenger.FromContext(ctx)
if !ok {
return http.StatusUnauthorized, nil
}
key := p.UserKey.Parent()
if key == nil {
return http.StatusUnauthorized, nil
}
// The account is associated with a company, so we return it.
var company model.Company
if err := datastore.Get(ctx, key, &company); err != nil {
return http.StatusInternalServerError, err
}
json.NewEncoder(w).Encode(company.Key(key))
return http.StatusOK, nil
}
开发者ID:tudorgergely,项目名称:api,代码行数:21,代码来源:user.go
示例4: CreateAndSaveCompany
// CreateAndSaveCompany creates a new Company and saves it to datastore using the provided context
func CreateAndSaveCompany(t *testing.T, ctx context.Context, name, email string) (model.Company, *datastore.Key) {
if name == "" {
name = "Example Company"
}
if email == "" {
email = "[email protected]"
}
company := model.Company{
Address: mail.Address{
Name: name,
Address: email,
},
}
var err error
var key *datastore.Key
key, err = company.Put(ctx, nil)
if err != nil {
t.Fatal(err)
}
return company, key
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:23,代码来源:controllers_test.go
注:本文中的github.com/coduno/api/model.Company类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论