本文整理汇总了Golang中github.com/app-kit/go-appkit.Resource.Collection方法的典型用法代码示例。如果您正苦于以下问题:Golang Resource.Collection方法的具体用法?Golang Resource.Collection怎么用?Golang Resource.Collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/app-kit/go-appkit.Resource
的用法示例。
在下文中一共展示了Resource.Collection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AllowDelete
func (UserResource) AllowDelete(res kit.Resource, obj kit.Model, user kit.User) bool {
if user == nil {
return false
}
if obj.(kit.UserModel).GetUserId() == user.GetId() {
return true
}
return user.HasRole("admin") || user.HasPermission(res.Collection()+".delete")
}
示例2: RegisterResource
func (s *Service) RegisterResource(res kit.Resource) {
if res.Backend() == nil {
if s.defaultBackend == nil {
s.registry.Logger().Panic("Registering resource without backend, but no default backend set on resources.Service")
}
s.defaultBackend.RegisterModel(res.Model())
res.SetBackend(s.defaultBackend)
}
if res.Collection() == "" {
s.registry.Logger().Panic("Registering resource without a model type")
}
s.resources[res.Collection()] = res
}
示例3: AddResource
func (d *Registry) AddResource(res kit.Resource) {
d.resources[res.Collection()] = res
}
示例4: Find
func Find(res kit.Resource, request kit.Request) (kit.Response, apperror.Error) {
collection := res.Collection()
info := res.Backend().ModelInfo(collection)
var query *db.Query
jsonQuery := request.GetContext().String("query")
if jsonQuery != "" {
var rawQuery map[string]interface{}
if err := json.Unmarshal([]byte(jsonQuery), &rawQuery); err != nil {
return nil, apperror.Wrap(err, "invalid_query_json")
}
rawQuery["collection"] = collection
// A custom query was supplied.
// Try to parse the query.
var err apperror.Error
query, err = db.ParseQuery(res.Backend(), rawQuery)
if err != nil {
return nil, apperror.Wrap(err, "invalid_query", "", false)
}
}
if query == nil {
query = res.Backend().Q(collection)
}
// Check paging parameters.
var limit, offset int
context := request.GetContext()
if context.Has("limit") {
val, err := context.Int("limit")
if err != nil {
return nil, &apperror.Err{
Public: true,
Code: "non_numeric_limit_parameter",
Message: "The get query contains a non-numeric ?limit",
}
}
limit = val
}
if context.Has("offset") {
val, err := context.Int("offset")
if err != nil {
return nil, &apperror.Err{
Public: true,
Code: "non_numeric_offset_parameter",
Message: "The get query contains a non-numeric ?offset",
}
}
offset = val
}
var page, perPage int
if context.Has("page") {
val, err := context.Int("page")
if err != nil {
return nil, &apperror.Err{
Public: true,
Code: "non_numeric_page_parameter",
Message: "The get query contains a non-numeric ?page",
}
}
page = val
}
if context.Has("per_page") {
val, err := context.Int("per_page")
if err != nil {
return nil, &apperror.Err{
Public: true,
Code: "non_numeric_per_page_parameter",
Message: "The get query contains a non-numeric ?per_page",
}
}
perPage = val
}
if perPage > 0 {
limit = perPage
}
if page > 1 {
offset = (page - 1) * limit
}
if limit > 0 {
query.Limit(int(limit)).Offset(int(offset))
}
// Add joins.
if context.Has("joins") {
parts := strings.Split(context.String("joins"), ",")
for _, name := range parts {
//.........这里部分代码省略.........