本文整理匯總了Golang中github.com/raphael/goa/design.APIDefinition.IterateMediaTypes方法的典型用法代碼示例。如果您正苦於以下問題:Golang APIDefinition.IterateMediaTypes方法的具體用法?Golang APIDefinition.IterateMediaTypes怎麽用?Golang APIDefinition.IterateMediaTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa/design.APIDefinition
的用法示例。
在下文中一共展示了APIDefinition.IterateMediaTypes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Generate
//.........這裏部分代碼省略.........
}
data.Actions = append(data.Actions, action)
return nil
})
if err != nil {
return err
}
if len(data.Actions) > 0 {
controllersData = append(controllersData, data)
}
return nil
})
g.genfiles = append(g.genfiles, g.controllersFilename)
if err := g.ControllersWriter.Execute(controllersData); err != nil {
g.Cleanup()
return nil, err
}
if err := g.ControllersWriter.FormatCode(); err != nil {
g.Cleanup()
return nil, err
}
title = fmt.Sprintf("%s: Application Resource Href Factories", api.Name)
g.ResourcesWriter.WriteHeader(title, TargetPackage, nil)
err = api.IterateResources(func(r *design.ResourceDefinition) error {
m, ok := api.MediaTypes[r.MediaType]
var identifier string
if ok {
identifier = m.Identifier
} else {
identifier = "application/text"
}
canoTemplate := r.URITemplate()
canoTemplate = design.WildcardRegex.ReplaceAllLiteralString(canoTemplate, "/%v")
var canoParams []string
if ca := r.CanonicalAction(); ca != nil {
if len(ca.Routes) > 0 {
canoParams = ca.Routes[0].Params()
}
}
data := ResourceData{
Name: codegen.Goify(r.Name, true),
Identifier: identifier,
Description: r.Description,
Type: m,
CanonicalTemplate: canoTemplate,
CanonicalParams: canoParams,
}
return g.ResourcesWriter.Execute(&data)
})
g.genfiles = append(g.genfiles, g.resourcesFilename)
if err != nil {
g.Cleanup()
return nil, err
}
if err := g.ResourcesWriter.FormatCode(); err != nil {
g.Cleanup()
return nil, err
}
title = fmt.Sprintf("%s: Application Media Types", api.Name)
imports = []*codegen.ImportSpec{
codegen.SimpleImport("github.com/raphael/goa"),
codegen.SimpleImport("fmt"),
}
g.MediaTypesWriter.WriteHeader(title, TargetPackage, imports)
err = api.IterateMediaTypes(func(mt *design.MediaTypeDefinition) error {
if mt.Type.IsObject() || mt.Type.IsArray() {
return g.MediaTypesWriter.Execute(mt)
}
return nil
})
g.genfiles = append(g.genfiles, g.mediaTypesFilename)
if err != nil {
g.Cleanup()
return nil, err
}
if err := g.MediaTypesWriter.FormatCode(); err != nil {
g.Cleanup()
return nil, err
}
title = fmt.Sprintf("%s: Application User Types", api.Name)
g.UserTypesWriter.WriteHeader(title, TargetPackage, nil)
err = api.IterateUserTypes(func(t *design.UserTypeDefinition) error {
return g.UserTypesWriter.Execute(t)
})
g.genfiles = append(g.genfiles, g.userTypesFilename)
if err != nil {
g.Cleanup()
return nil, err
}
if err := g.UserTypesWriter.FormatCode(); err != nil {
g.Cleanup()
return nil, err
}
return g.genfiles, nil
}