github.com/brycereitano/goa@v0.0.0-20170315073847-8ffa6c85e265/goagen/codegen/run.go (about)

     1  package codegen
     2  
     3  import "github.com/goadesign/goa/dslengine"
     4  
     5  type generator interface {
     6  	Generate() ([]string, error)
     7  }
     8  
     9  // Run runs all generators passed as parameter. Call ParseDSL first to
    10  // fill `design.Design`.  Each `goa` generator lives in its own
    11  // `goagen/gen_something` package in `generator.go` and has a
    12  // `Generator` object which implements the interface required here.
    13  //
    14  //   codegen.Run(
    15  //     &genapp.Generator{
    16  //       API: design.Design,
    17  //       Target: "app",
    18  //     },
    19  //     &genmain.Generator{
    20  //       API: design.Design,
    21  //     },
    22  //   )
    23  //
    24  func Run(generators ...generator) {
    25  	for _, generator := range generators {
    26  		dslengine.PrintFilesOrFail(generator.Generate())
    27  	}
    28  }
    29  
    30  // ParseDSL will run the DSL engine and analyze any imported `design`
    31  // package, creating your `design.APIDefinition` along the way.
    32  func ParseDSL() {
    33  	// Catch any init-time errors
    34  	dslengine.FailOnError(dslengine.Errors)
    35  
    36  	// Catch any runtime errors, when analyzing the DSL
    37  	dslengine.FailOnError(dslengine.Run())
    38  }