本文整理匯總了Golang中github.com/raphael/goa/design.APIVersionDefinition.IsDefault方法的典型用法代碼示例。如果您正苦於以下問題:Golang APIVersionDefinition.IsDefault方法的具體用法?Golang APIVersionDefinition.IsDefault怎麽用?Golang APIVersionDefinition.IsDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa/design.APIVersionDefinition
的用法示例。
在下文中一共展示了APIVersionDefinition.IsDefault方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: generateControllers
// generateControllers iterates through the version resources and generates the low level
// controllers.
func (g *Generator) generateControllers(verdir string, version *design.APIVersionDefinition) error {
ctlFile := filepath.Join(verdir, "controllers.go")
ctlWr, err := NewControllersWriter(ctlFile)
if err != nil {
panic(err) // bug
}
title := fmt.Sprintf("%s: Application Controllers", version.Context())
imports := []*codegen.ImportSpec{
codegen.SimpleImport("github.com/julienschmidt/httprouter"),
codegen.SimpleImport("github.com/raphael/goa"),
}
if !version.IsDefault() {
appPkg, err := AppPackagePath()
if err != nil {
return err
}
imports = append(imports, codegen.SimpleImport(appPkg))
}
ctlWr.WriteHeader(title, packageName(version), imports)
var controllersData []*ControllerTemplateData
version.IterateResources(func(r *design.ResourceDefinition) error {
if !r.SupportsVersion(version.Version) {
return nil
}
data := &ControllerTemplateData{Resource: codegen.Goify(r.Name, true)}
err := r.IterateActions(func(a *design.ActionDefinition) error {
context := fmt.Sprintf("%s%sContext", codegen.Goify(a.Name, true), codegen.Goify(r.Name, true))
unmarshal := fmt.Sprintf("unmarshal%s%sPayload", codegen.Goify(a.Name, true), codegen.Goify(r.Name, true))
action := map[string]interface{}{
"Name": codegen.Goify(a.Name, true),
"Routes": a.Routes,
"Context": context,
"Unmarshal": unmarshal,
"Payload": a.Payload,
}
data.Actions = append(data.Actions, action)
return nil
})
if err != nil {
return err
}
if len(data.Actions) > 0 {
data.Version = version
controllersData = append(controllersData, data)
}
return nil
})
g.genfiles = append(g.genfiles, ctlFile)
if err = ctlWr.Execute(controllersData); err != nil {
return err
}
return ctlWr.FormatCode()
}
示例2: generateContexts
// generateContexts iterates through the version resources and actions and generates the action
// contexts.
func (g *Generator) generateContexts(verdir string, api *design.APIDefinition, version *design.APIVersionDefinition) error {
ctxFile := filepath.Join(verdir, "contexts.go")
ctxWr, err := NewContextsWriter(ctxFile)
if err != nil {
panic(err) // bug
}
title := fmt.Sprintf("%s: Application Contexts", version.Context())
imports := []*codegen.ImportSpec{
codegen.SimpleImport("fmt"),
codegen.SimpleImport("strconv"),
codegen.SimpleImport("github.com/raphael/goa"),
}
if !version.IsDefault() {
appPkg, err := AppPackagePath()
if err != nil {
return err
}
imports = append(imports, codegen.SimpleImport(filepath.ToSlash(appPkg)))
}
ctxWr.WriteHeader(title, packageName(version), imports)
var appPackage string
if !version.IsDefault() {
appPackage = TargetPackage
}
err = version.IterateResources(func(r *design.ResourceDefinition) error {
if !r.SupportsVersion(version.Version) {
return nil
}
return r.IterateActions(func(a *design.ActionDefinition) error {
ctxName := codegen.Goify(a.Name, true) + codegen.Goify(a.Parent.Name, true) + "Context"
ctxData := ContextTemplateData{
Name: ctxName,
ResourceName: r.Name,
ActionName: a.Name,
Payload: a.Payload,
Params: a.AllParams(),
Headers: r.Headers.Merge(a.Headers),
Routes: a.Routes,
Responses: MergeResponses(r.Responses, a.Responses),
API: api,
Version: version,
AppPackage: appPackage,
}
return ctxWr.Execute(&ctxData)
})
})
g.genfiles = append(g.genfiles, ctxFile)
if err != nil {
return err
}
return ctxWr.FormatCode()
}