本文整理汇总了Golang中github.com/rs/rest-layer/resource.Resource.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Resource.Name方法的具体用法?Golang Resource.Name怎么用?Golang Resource.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rs/rest-layer/resource.Resource
的用法示例。
在下文中一共展示了Resource.Name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getObjectType
// getObjectType returns a graphql object type definition from a REST layer schema
func (t types) getObjectType(idx resource.Index, r *resource.Resource) *graphql.Object {
// Memoize types by their name so we don't create several instance of the same resource
name := r.Name()
o := t[name]
if o == nil {
o = graphql.NewObject(graphql.ObjectConfig{
Name: name,
Description: r.Schema().Description,
Fields: getFields(idx, r.Schema()),
})
t[name] = o
t.addConnections(o, idx, r)
}
return o
}
示例2: getGetQuery
func (t types) getGetQuery(idx resource.Index, r *resource.Resource) *graphql.Field {
return &graphql.Field{
Description: fmt.Sprintf("Get %s by id", r.Name()),
Type: t.getObjectType(idx, r),
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.String,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
id, ok := p.Args["id"].(string)
if !ok {
return nil, nil
}
item, err := r.Get(p.Context, id)
if err != nil {
return nil, err
}
return item.Payload, nil
},
}
}
示例3: getListQuery
func (t types) getListQuery(idx resource.Index, r *resource.Resource, params url.Values) *graphql.Field {
return &graphql.Field{
Description: fmt.Sprintf("Get a list of %s", r.Name()),
Type: graphql.NewList(t.getObjectType(idx, r)),
Args: listArgs,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
lookup, page, perPage, err := listParamResolver(r, p, params)
if err != nil {
return nil, err
}
list, err := r.Find(p.Context, lookup, page, perPage)
if err != nil {
return nil, err
}
result := make([]map[string]interface{}, len(list.Items))
for i, item := range list.Items {
result[i] = item.Payload
}
return result, nil
},
}
}