本文整理匯總了Golang中github.com/raphael/goa/design.APIVersionDefinition.IterateMediaTypes方法的典型用法代碼示例。如果您正苦於以下問題:Golang APIVersionDefinition.IterateMediaTypes方法的具體用法?Golang APIVersionDefinition.IterateMediaTypes怎麽用?Golang APIVersionDefinition.IterateMediaTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa/design.APIVersionDefinition
的用法示例。
在下文中一共展示了APIVersionDefinition.IterateMediaTypes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: generateMediaTypes
// generateMediaTypes iterates through the media types and generate the data structures and
// marshaling code.
func (g *Generator) generateMediaTypes(verdir string, version *design.APIVersionDefinition) error {
mtFile := filepath.Join(verdir, "media_types.go")
mtWr, err := NewMediaTypesWriter(mtFile)
if err != nil {
panic(err) // bug
}
title := fmt.Sprintf("%s: Application Media Types", version.Context())
imports := []*codegen.ImportSpec{
codegen.SimpleImport("github.com/raphael/goa"),
codegen.SimpleImport("fmt"),
}
mtWr.WriteHeader(title, packageName(version), imports)
err = version.IterateMediaTypes(func(mt *design.MediaTypeDefinition) error {
data := &MediaTypeTemplateData{
MediaType: mt,
Versioned: version.Version != "",
DefaultPkg: TargetPackage,
}
if mt.Type.IsObject() || mt.Type.IsArray() {
return mtWr.Execute(data)
}
return nil
})
g.genfiles = append(g.genfiles, mtFile)
if err != nil {
return err
}
return mtWr.FormatCode()
}