本文整理匯總了Golang中github.com/app-kit/go-appkit.Model.Collection方法的典型用法代碼示例。如果您正苦於以下問題:Golang Model.Collection方法的具體用法?Golang Model.Collection怎麽用?Golang Model.Collection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/app-kit/go-appkit.Model
的用法示例。
在下文中一共展示了Model.Collection方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Create
func (s *Service) Create(m kit.Model, user kit.User) apperror.Error {
res := s.resources[m.Collection()]
if res == nil {
return &apperror.Err{
Code: "unknown_resource",
Message: fmt.Sprintf("The resource %v was not registered with service", m.Collection()),
}
}
return res.Create(m, user)
}
示例2: SerializeModel
// SerializeModel converts a model into the target format.
func (s *Serializer) SerializeModel(model kit.Model) (interface{}, []interface{}, apperror.Error) {
// Find backend.
backend := s.findBackend(model.Collection())
if backend == nil {
return nil, nil, apperror.New("unknown_collection", fmt.Sprintf("Can't serialize model of unknown collection %v", model.Collection()))
}
// Serialize model.
m, extra, err := SerializeModel(backend, model)
if err != nil {
return nil, nil, err
}
// Convert extra slice to interface slice.
var rawExtra []interface{}
for _, item := range extra {
rawExtra = append(rawExtra, item)
}
return m, rawExtra, nil
}