code: func (g *Generator) Generate() (_ []string, err error) {
  	if g.API == nil {
  		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
  	}
  
  	go utils.Catch(nil, func() { g.Cleanup() })
  
  	defer func() {
  		if err != nil {
  			g.Cleanup()
  		}
  	}()
  
  	if g.AppPkg == "" {
  		g.AppPkg = "app"
  	}
  	g.smartenPkg()
  	elems := strings.Split(g.AppPkg, "/")
  	pkgName := elems[len(elems)-1]
  	codegen.Reserved[pkgName] = true
  
  	err = g.API.IterateResources(func(r *design.ResourceDefinition) error {
  		var (
  			filename string
  			err      error
  		)
  		if g.Resource == "" || g.Resource == r.Name {
  			filename, err = genmain.GenerateController(g.Force, g.Regen, g.AppPkg, g.OutDir, g.Pkg, r.Name, r)
  		}
  
  		if err != nil {
  			return err
  		}
  		g.genfiles = append(g.genfiles, filename)
  
  		return nil
  	})
  	if err != nil {
  		return nil, err
  	}
  
  	return g.genfiles, err
  }
docs: // Generate produces the skeleton controller service factory.