本文整理匯總了Golang中github.com/raphael/goa/design.ResourceDefinition.FullPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceDefinition.FullPath方法的具體用法?Golang ResourceDefinition.FullPath怎麽用?Golang ResourceDefinition.FullPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa/design.ResourceDefinition
的用法示例。
在下文中一共展示了ResourceDefinition.FullPath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: finalizeResource
// finalizeResource makes the final pass at the resource DSL. This is needed so that the order
// of DSL function calls is irrelevant. For example a resource response may be defined after an
// action refers to it.
func finalizeResource(r *design.ResourceDefinition) {
r.IterateActions(func(a *design.ActionDefinition) error {
// 1. Merge response definitions
for name, resp := range a.Responses {
if pr, ok := a.Parent.Responses[name]; ok {
resp.Merge(pr)
}
if ar, ok := design.Design.Responses[name]; ok {
resp.Merge(ar)
}
if dr, ok := design.Design.DefaultResponses[name]; ok {
resp.Merge(dr)
}
}
// 2. Create implicit action parameters for path wildcards that dont' have one
for _, r := range a.Routes {
design.Design.IterateVersions(func(ver *design.APIVersionDefinition) error {
wcs := design.ExtractWildcards(r.FullPath(ver))
for _, wc := range wcs {
found := false
var o design.Object
if all := a.AllParams(); all != nil {
o = all.Type.ToObject()
} else {
o = design.Object{}
a.Params = &design.AttributeDefinition{Type: o}
}
for n := range o {
if n == wc {
found = true
break
}
}
if !found {
o[wc] = &design.AttributeDefinition{Type: design.String}
}
}
return nil
})
}
// 3. Compute QueryParams from Params
if params := a.Params; params != nil {
queryParams := params.Dup()
design.Design.IterateVersions(func(ver *design.APIVersionDefinition) error {
for _, route := range a.Routes {
pnames := route.Params(ver)
for _, pname := range pnames {
delete(queryParams.Type.ToObject(), pname)
}
}
return nil
})
// (note: we may end up with required attribute names that don't correspond
// to actual attributes cos' we just deleted them but that's probably OK.)
a.QueryParams = queryParams
}
return nil
})
}
示例2: finalizeResource
// finalizeResource makes the final pass at the resource DSL. This is needed so that the order
// of DSL function calls is irrelevant. For example a resource response may be defined after an
// action refers to it.
func finalizeResource(r *design.ResourceDefinition) {
r.IterateActions(func(a *design.ActionDefinition) error {
// 1. Merge response definitions
for name, resp := range a.Responses {
if pr, ok := a.Parent.Responses[name]; ok {
resp.Merge(pr)
}
if ar, ok := design.Design.Responses[name]; ok {
resp.Merge(ar)
}
if dr, ok := design.Design.DefaultResponses[name]; ok {
resp.Merge(dr)
}
}
// 2. Create implicit action parameters for path wildcards that dont' have one
for _, r := range a.Routes {
wcs := design.ExtractWildcards(r.FullPath())
for _, wc := range wcs {
found := false
var o design.Object
if a.Params != nil {
o = a.Params.Type.ToObject()
} else {
o = design.Object{}
a.Params = &design.AttributeDefinition{Type: o}
}
for n := range o {
if n == wc {
found = true
break
}
}
if !found {
o[wc] = &design.AttributeDefinition{Type: design.String}
}
}
}
return nil
})
}