本文整理匯總了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 {
//.........這裏部分代碼省略.........