本文整理汇总了Golang中github.com/masom/doorbot/doorbot.NewInternalServerErrorResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang NewInternalServerErrorResponse函数的具体用法?Golang NewInternalServerErrorResponse怎么用?Golang NewInternalServerErrorResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewInternalServerErrorResponse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Put
// Put updates a device
func Put(render render.Render, r doorbot.Repositories, params martini.Params, vm DeviceViewModel) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.DeviceRepository()
device, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_id": id,
"step": "device-find",
}).Error("Api::Devices->Put database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if device == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified device does not exists"}))
return
}
device.Name = vm.Device.Name
device.DeviceID = vm.Device.DeviceID
device.Make = vm.Device.Make
device.Description = vm.Device.Description
device.IsEnabled = vm.Device.IsEnabled
_, err = repo.Update(r.DB(), device)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_id": id,
"step": "device-update",
}).Error("Api::Devices->Put database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"device_id": id,
}).Info("Api::Devices->Put device updated")
vm.Device = device
render.JSON(http.StatusOK, vm)
}
开发者ID:masom,项目名称:doorbot,代码行数:56,代码来源:devices.go
示例2: Put
// Put updates a door
func Put(render render.Render, r doorbot.Repositories, params martini.Params, vm DoorViewModel) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.DoorRepository()
door, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"door_id": id,
"step": "door-find",
}).Error("Api::Doors->Put database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if door == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists"}))
return
}
door.Name = vm.Door.Name
_, err = repo.Update(r.DB(), door)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"door_id": id,
"step": "door-update",
}).Error("Api::Doors->Put database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"door_id": vm.Door.ID,
}).Error("Api::Doors->Post door updated")
render.JSON(http.StatusOK, DoorViewModel{Door: door})
}
开发者ID:masom,项目名称:doorbot,代码行数:50,代码来源:doors.go
示例3: Disable
// Disable a device
func Disable(render render.Render, r doorbot.Repositories, params martini.Params) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"the id must be an unsigned integer"}))
return
}
repo := r.DeviceRepository()
device, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_id": id,
"step": "device-find",
}).Error("Api::Devices->Disable database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if device == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified deevice does not exists."}))
return
}
_, err = repo.Enable(r.DB(), device, false)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_id": id,
"step": "device-disable",
}).Error("Api::Devices->Disable database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"device_id": id,
}).Info("Api::Devices->Disabled device disabled")
render.Status(http.StatusNoContent)
}
开发者ID:masom,项目名称:doorbot,代码行数:49,代码来源:devices.go
示例4: TestPostCreateError
func TestPostCreateError(t *testing.T) {
render := new(tests.MockRender)
repo := new(tests.MockAccountRepository)
db := new(tests.MockExecutor)
admin := &doorbot.Administrator{}
repositories := new(tests.MockRepositories)
repositories.On("AccountRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(1)
account := &doorbot.Account{
Name: "ACME",
Host: "derp",
}
// nil
var findByHostReponse *doorbot.Account
repo.On("Create", db, account).Return(errors.New("errooor"))
repo.On("FindByHost", db, "derp").Return(findByHostReponse, nil)
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Post(render, repositories, AccountViewModel{Account: account}, admin)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:30,代码来源:accounts_test.go
示例5: TestPutFailed
func TestPutFailed(t *testing.T) {
render := new(tests.MockRender)
repo := new(tests.MockAccountRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("AccountRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(1)
postAccount := &doorbot.Account{
Name: "Romanian Landlords",
}
repoAccount := &doorbot.Account{
ID: 5555,
Name: "ACME",
IsEnabled: true,
}
session := &auth.Authorization{
Type: auth.AuthorizationAdministrator,
}
repo.On("Update", db, repoAccount).Return(false, errors.New("failed"))
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Put(render, repoAccount, repositories, AccountViewModel{Account: postAccount}, session)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:33,代码来源:accounts_test.go
示例6: TestPutFailed
func TestPutFailed(t *testing.T) {
render := new(tests.MockRender)
repo := new(tests.MockDoorRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("DoorRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(uint(1))
params := martini.Params{
"id": "5555",
}
postDoor := &doorbot.Door{
Name: "Romanian Landlords",
}
repoDoor := &doorbot.Door{
ID: 5555,
Name: "ACME",
}
repo.On("Find", db, uint(5555)).Return(repoDoor, nil)
repo.On("Update", db, repoDoor).Return(false, errors.New("failed"))
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Put(render, repositories, params, DoorViewModel{Door: postDoor})
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
repositories.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:35,代码来源:doors_test.go
示例7: TestPostCreateError
func TestPostCreateError(t *testing.T) {
render := new(tests.MockRender)
repo := new(tests.MockDoorRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("DoorRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(uint(1))
door := &doorbot.Door{
Name: "ACME",
}
repo.On("Create", db, door).Return(errors.New("errooor"))
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Post(render, repositories, DoorViewModel{Door: door})
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
repositories.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:25,代码来源:doors_test.go
示例8: TestIndexError
func TestIndexError(t *testing.T) {
session := &auth.Authorization{
Type: auth.AuthorizationPerson,
Person: &doorbot.Person{
AccountType: doorbot.AccountOwner,
},
}
people := []*doorbot.Person{}
err := errors.New("i like pasta")
render := new(tests.MockRender)
repo := new(tests.MockPersonRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("PersonRepository").Return(repo)
repositories.On("AccountScope").Return(uint(0))
repositories.On("DB").Return(db)
repo.On("All", db).Return(people, err)
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Index(render, repositories, session)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
repositories.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:30,代码来源:people_test.go
示例9: TestDeleteFailed
func TestDeleteFailed(t *testing.T) {
repo := new(tests.MockAccountRepository)
render := new(tests.MockRender)
admin := &doorbot.Administrator{}
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("AccountRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(1)
params := martini.Params{
"id": "55",
}
account := &doorbot.Account{
ID: 55,
Name: "ACME",
}
repo.On("Find", db, uint(55)).Return(account, nil)
repo.On("Delete", db, account).Return(false, errors.New("error"))
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Delete(render, repositories, params, admin)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:32,代码来源:accounts_test.go
示例10: Index
// Index returns people
func Index(render render.Render, r doorbot.Repositories, session *auth.Authorization) {
repo := r.PersonRepository()
people, err := repo.All(r.DB())
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
}).Error("Api::People->Index database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
switch session.Type {
case auth.AuthorizationAdministrator:
render.JSON(http.StatusOK, PeopleViewModel{People: people})
case auth.AuthorizationDevice:
render.JSON(http.StatusOK, PublicPeopleViewModel{People: newPublicPeople(people)})
case auth.AuthorizationPerson:
if session.Person.IsAccountManager() {
render.JSON(http.StatusOK, PeopleViewModel{People: people})
return
}
render.JSON(http.StatusOK, PublicPeopleViewModel{People: newPublicPeople(people)})
}
}
开发者ID:masom,项目名称:doorbot,代码行数:30,代码来源:people.go
示例11: Delete
// Delete an account ( admin panel )
func Delete(render render.Render, r doorbot.Repositories, params martini.Params, administrator *doorbot.Administrator) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.AccountRepository()
account, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
"account_id": account.ID,
"administrator_id": administrator.ID,
}).Error("Api::Accounts->Delete database find error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if account == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified account does not exists."}))
return
}
_, err = repo.Delete(r.DB(), account)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
"administrator_id": administrator.ID,
"account_id": account.ID,
}).Error("Api::Accounts->Delete database delete error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"administrator_id": administrator.ID,
"account_id": account.ID,
}).Info("Api::Accounts->Delete account deleted by administrator.")
render.Status(http.StatusNoContent)
}
开发者ID:masom,项目名称:doorbot,代码行数:48,代码来源:accounts.go
示例12: Post
// Post create a new account ( using the admin panel )
func Post(render render.Render, r doorbot.Repositories, vm AccountViewModel, administrator *doorbot.Administrator) {
repo := r.AccountRepository()
exists, err := repo.FindByHost(r.DB(), vm.Account.Host)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"host": vm.Account.Host,
}).Error("Api::Accounts->Post database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if exists != nil {
log.WithFields(log.Fields{
"host": vm.Account.Host,
}).Warn("Api::Accounts->Post Host already registered")
render.JSON(http.StatusConflict, doorbot.NewConflictErrorResponse([]string{"The specified host is already registered."}))
return
}
err = repo.Create(r.DB(), vm.Account)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"host": vm.Account.Host,
}).Error("Api::Accounts->Post database error.")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"administrator_id": administrator.ID,
"account_id": vm.Account.ID,
"host": vm.Account.Host,
}).Info("Account created by administrator")
render.JSON(http.StatusCreated, vm)
}
开发者ID:masom,项目名称:doorbot,代码行数:45,代码来源:accounts.go
示例13: Index
// Index action
func Index(render render.Render, r doorbot.Repositories, administrator *doorbot.Administrator) {
repo := r.AccountRepository()
accounts, err := repo.All(r.DB())
if err != nil {
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
render.JSON(http.StatusOK, AccountsViewModel{Accounts: accounts})
}
开发者ID:masom,项目名称:doorbot,代码行数:12,代码来源:accounts.go
示例14: Get
// Get return a specific account
func Get(render render.Render, r doorbot.Repositories, params martini.Params, session *auth.Authorization) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.AccountRepository()
account, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"account_id": id,
"error": err,
}).Error("Api::Accounts->Get database error.")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if account == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{}))
return
}
// Switch the view model depending on who/what requests the information.
switch session.Type {
case auth.AuthorizationAdministrator:
render.JSON(http.StatusOK, AccountViewModel{Account: account})
case auth.AuthorizationPerson:
if session.Person.IsAccountManager() {
render.JSON(http.StatusOK, AccountViewModel{Account: account})
return
}
// Display a reduced version of the account.
public := PublicAccount{
ID: account.ID,
Name: account.Name,
Host: account.Host,
}
render.JSON(http.StatusOK, PublicAccountViewModel{Account: public})
default:
render.Status(http.StatusForbidden)
return
}
}
开发者ID:masom,项目名称:doorbot,代码行数:51,代码来源:accounts.go
示例15: Get
// Get a specific person
func Get(render render.Render, r doorbot.Repositories, params martini.Params, session *auth.Authorization) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.PersonRepository()
person, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"person_id": id,
}).Error("Api::People->Get database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if person == nil {
err := doorbot.NewEntityNotFoundResponse([]string{"The specified person does not exists"})
render.JSON(http.StatusNotFound, err)
return
}
switch session.Type {
case auth.AuthorizationAdministrator:
render.JSON(http.StatusOK, PersonViewModel{Person: person})
case auth.AuthorizationDevice:
render.JSON(http.StatusOK, PublicPersonViewModel{Person: newPublicPerson(person)})
case auth.AuthorizationPerson:
// Display detailed info if the requesting user is an account manager or it is the same person
if session.Person.IsAccountManager() || session.Person.ID == person.ID {
render.JSON(http.StatusOK, PersonViewModel{Person: person})
return
}
render.JSON(http.StatusOK, PublicPersonViewModel{Person: newPublicPerson(person)})
default:
render.Status(http.StatusForbidden)
}
}
开发者ID:masom,项目名称:doorbot,代码行数:48,代码来源:people.go
示例16: Index
// Index return a list of doors
func Index(render render.Render, r doorbot.Repositories) {
repo := r.DoorRepository()
doors, err := repo.All(r.DB())
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
}).Error("Api::Doors->Index database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
render.JSON(http.StatusOK, DoorsViewModel{Doors: doors})
}
开发者ID:masom,项目名称:doorbot,代码行数:18,代码来源:doors.go
示例17: TestPutFailed
func TestPutFailed(t *testing.T) {
render := new(tests.MockRender)
repo := new(tests.MockPersonRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("PersonRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(uint(1))
params := martini.Params{
"id": "5555",
}
postPerson := &doorbot.Person{
Name: "Romanian Landlords",
}
repoPerson := &doorbot.Person{
ID: 5555,
Name: "ACME",
AccountType: doorbot.AccountOwner,
}
session := &auth.Authorization{
Type: auth.AuthorizationPerson,
Person: repoPerson,
}
repo.On("Find", db, uint(5555)).Return(repoPerson, nil)
repo.On("Update", db, repoPerson).Return(false, errors.New("failed"))
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Put(render, repositories, params, PersonViewModel{Person: postPerson}, session)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
repositories.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:41,代码来源:people_test.go
示例18: Post
// Post creates a new person
func Post(render render.Render, r doorbot.Repositories, vm PersonViewModel) {
repo := r.PersonRepository()
err := repo.Create(r.DB(), vm.Person)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
}).Error("Api::People->Post database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"person_id": vm.Person.ID,
}).Info("Api::People->Post person added.")
render.JSON(http.StatusCreated, vm)
}
开发者ID:masom,项目名称:doorbot,代码行数:23,代码来源:people.go
示例19: Post
// Post creates a door
func Post(render render.Render, r doorbot.Repositories, vm DoorViewModel) {
repo := r.DoorRepository()
err := repo.Create(r.DB(), vm.Door)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
}).Error("Api::Doors->Post database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"door_id": vm.Door.ID,
}).Error("Api::Doors->Post door created")
render.JSON(http.StatusCreated, vm)
}
开发者ID:masom,项目名称:doorbot,代码行数:23,代码来源:doors.go
示例20: TestIndexError
func TestIndexError(t *testing.T) {
doors := []*doorbot.Door{}
err := errors.New("i like pasta")
render := new(tests.MockRender)
repo := new(tests.MockDoorRepository)
db := new(tests.MockExecutor)
repositories := new(tests.MockRepositories)
repositories.On("DoorRepository").Return(repo)
repositories.On("DB").Return(db)
repositories.On("AccountScope").Return(uint(1))
repo.On("All", db).Return(doors, err)
render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()
Index(render, repositories)
render.Mock.AssertExpectations(t)
repo.Mock.AssertExpectations(t)
repositories.Mock.AssertExpectations(t)
}
开发者ID:masom,项目名称:doorbot,代码行数:23,代码来源:doors_test.go
注:本文中的github.com/masom/doorbot/doorbot.NewInternalServerErrorResponse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论