goa: github.com/goadesign/goa/goagen/gen_app Index | Files

package genapp

import "github.com/goadesign/goa/goagen/gen_app"

Package genapp provides the generator for the handlers, context data structures and tests of a goa application. It generates the glue between user code and the low level router.

Index

Package Files

doc.go encoding.go generator.go options.go test_generator.go writers.go

Variables

var WildcardRegex = regexp.MustCompile("(?:[^/]*/:([^/]+))+")

WildcardRegex is the regex used to capture path parameters.

func BuildEncoders Uses

func BuildEncoders(info []*design.EncodingDefinition, encoder bool) ([]*EncoderTemplateData, error)

BuildEncoders builds the template data needed to render the given encoding definitions. This extra map is needed to handle the case where a single encoding definition maps to multiple encoding packages. The data is indexed by mime type.

func Generate Uses

func Generate() (files []string, err error)

Generate is the generator entry point called by the meta generator.

type ContextTemplateData Uses

type ContextTemplateData struct {
    Name         string // e.g. "ListBottleContext"
    ResourceName string // e.g. "bottles"
    ActionName   string // e.g. "list"
    Params       *design.AttributeDefinition
    Payload      *design.UserTypeDefinition
    Headers      *design.AttributeDefinition
    Routes       []*design.RouteDefinition
    Responses    map[string]*design.ResponseDefinition
    API          *design.APIDefinition
    DefaultPkg   string
    Security     *design.SecurityDefinition
}

ContextTemplateData contains all the information used by the template to render the context code for an action.

func (*ContextTemplateData) HasParamAndHeader Uses

func (c *ContextTemplateData) HasParamAndHeader(name string) bool

HasParamAndHeader returns true if the generated struct field name for the given header name matches the generated struct field name of a param in c.Params.

func (*ContextTemplateData) IsPathParam Uses

func (c *ContextTemplateData) IsPathParam(param string) bool

IsPathParam returns true if the given parameter name corresponds to a path parameter for all the context action routes. Such parameter is required but does not need to be validated as httptreemux takes care of that.

func (*ContextTemplateData) IterateResponses Uses

func (c *ContextTemplateData) IterateResponses(it func(*design.ResponseDefinition) error) error

IterateResponses iterates through the responses sorted by status code.

func (*ContextTemplateData) MustValidate Uses

func (c *ContextTemplateData) MustValidate(name string) bool

MustValidate returns true if code that checks for the presence of the given param must be generated.

type ContextsWriter Uses

type ContextsWriter struct {
    *codegen.SourceFile
    CtxTmpl     *template.Template
    CtxNewTmpl  *template.Template
    CtxRespTmpl *template.Template
    PayloadTmpl *template.Template
    Finalizer   *codegen.Finalizer
    Validator   *codegen.Validator
}

ContextsWriter generate codes for a goa application contexts.

func NewContextsWriter Uses

func NewContextsWriter(filename string) (*ContextsWriter, error)

NewContextsWriter returns a contexts code writer. Contexts provide the glue between the underlying request data and the user controller.

func (*ContextsWriter) Execute Uses

func (w *ContextsWriter) Execute(data *ContextTemplateData) error

Execute writes the code for the context types to the writer.

type ControllerTemplateData Uses

type ControllerTemplateData struct {
    API            *design.APIDefinition          // API definition
    Resource       string                         // Lower case plural resource name, e.g. "bottles"
    Actions        []map[string]interface{}       // Array of actions, each action has keys "Name", "DesignName", "Routes", "Context" and "Unmarshal"
    FileServers    []*design.FileServerDefinition // File servers
    Encoders       []*EncoderTemplateData         // Encoder data
    Decoders       []*EncoderTemplateData         // Decoder data
    Origins        []*design.CORSDefinition       // CORS policies
    PreflightPaths []string
}

ControllerTemplateData contains the information required to generate an action handler.

type ControllersWriter Uses

type ControllersWriter struct {
    *codegen.SourceFile
    CtrlTmpl  *template.Template
    MountTmpl *template.Template

    Finalizer *codegen.Finalizer
    Validator *codegen.Validator
    // contains filtered or unexported fields
}

ControllersWriter generate code for a goa application handlers. Handlers receive a HTTP request, create the action context, call the action code and send the resulting HTTP response.

func NewControllersWriter Uses

func NewControllersWriter(filename string) (*ControllersWriter, error)

NewControllersWriter returns a handlers code writer. Handlers provide the glue between the underlying request data and the user controller.

func (*ControllersWriter) Execute Uses

func (w *ControllersWriter) Execute(data []*ControllerTemplateData) error

Execute writes the handlers GoGenerator

func (*ControllersWriter) WriteInitService Uses

func (w *ControllersWriter) WriteInitService(encoders, decoders []*EncoderTemplateData) error

WriteInitService writes the initService function

type EncoderTemplateData Uses

type EncoderTemplateData struct {
    // PackagePath is the Go package path to the package implmenting the encoder/decoder.
    PackagePath string
    // PackageName is the name of the Go package implementing the encoder/decoder.
    PackageName string
    // Function is the name of the package function implementing the decoder/encoder factory.
    Function string
    // MIMETypes is the list of supported MIME types.
    MIMETypes []string
    // Default is true if this encoder/decoder should be set as the default.
    Default bool
}

EncoderTemplateData contains the data needed to render the registration code for a single encoder or decoder package.

type Generator Uses

type Generator struct {
    API    *design.APIDefinition // The API definition
    OutDir string                // Path to output directory
    Target string                // Name of generated package
    NoTest bool                  // Whether to skip test generation
    // contains filtered or unexported fields
}

Generator is the application code generator.

func NewGenerator Uses

func NewGenerator(options ...Option) *Generator

NewGenerator returns an initialized instance of an Application Generator

func (*Generator) Cleanup Uses

func (g *Generator) Cleanup()

Cleanup removes the entire "app" directory if it was created by this generator.

func (*Generator) Generate Uses

func (g *Generator) Generate() (_ []string, err error)

Generate the application code, implement codegen.Generator.

type MediaTypesWriter Uses

type MediaTypesWriter struct {
    *codegen.SourceFile
    MediaTypeTmpl *template.Template
    Validator     *codegen.Validator
}

MediaTypesWriter generate code for a goa application media types. Media types are data structures used to render the response bodies.

func NewMediaTypesWriter Uses

func NewMediaTypesWriter(filename string) (*MediaTypesWriter, error)

NewMediaTypesWriter returns a contexts code writer. Media types contain the data used to render response bodies.

func (*MediaTypesWriter) Execute Uses

func (w *MediaTypesWriter) Execute(mt *design.MediaTypeDefinition) error

Execute writes the code for the context types to the writer.

type ObjectType Uses

type ObjectType struct {
    Label       string
    Name        string
    Type        string
    Pointer     string
    Validatable bool
}

ObjectType structure

type Option Uses

type Option func(*Generator)

Option a generator option definition

func API Uses

func API(API *design.APIDefinition) Option

API The API definition

func NoTest Uses

func NoTest(noTest bool) Option

NoTest Whether to skip test generation

func OutDir Uses

func OutDir(outDir string) Option

OutDir Path to output directory

func Target Uses

func Target(target string) Option

Target Name of generated package

type ResourceData Uses

type ResourceData struct {
    Name              string                      // Name of resource
    Identifier        string                      // Identifier of resource media type
    Description       string                      // Description of resource
    Type              *design.MediaTypeDefinition // Type of resource media type
    CanonicalTemplate string                      // CanonicalFormat represents the resource canonical path in the form of a fmt.Sprintf format.
    CanonicalParams   []string                    // CanonicalParams is the list of parameter names that appear in the resource canonical path in order.
}

ResourceData contains the information required to generate the resource GoGenerator

type ResourcesWriter Uses

type ResourcesWriter struct {
    *codegen.SourceFile
    ResourceTmpl *template.Template
}

ResourcesWriter generate code for a goa application resources. Resources are data structures initialized by the application handlers and passed to controller actions.

func NewResourcesWriter Uses

func NewResourcesWriter(filename string) (*ResourcesWriter, error)

NewResourcesWriter returns a contexts code writer. Resources provide the glue between the underlying request data and the user controller.

func (*ResourcesWriter) Execute Uses

func (w *ResourcesWriter) Execute(data *ResourceData) error

Execute writes the code for the context types to the writer.

type SecurityWriter Uses

type SecurityWriter struct {
    *codegen.SourceFile
    SecurityTmpl *template.Template
}

SecurityWriter generate code for action-level security handlers.

func NewSecurityWriter Uses

func NewSecurityWriter(filename string) (*SecurityWriter, error)

NewSecurityWriter returns a security functionality code writer. Those functionalities are there to support action-middleware related to security.

func (*SecurityWriter) Execute Uses

func (w *SecurityWriter) Execute(schemes []*design.SecuritySchemeDefinition) error

Execute adds the different security schemes and middleware supporting functions.

type TestMethod Uses

type TestMethod struct {
    Name              string
    Comment           string
    ResourceName      string
    ActionName        string
    ControllerName    string
    ContextVarName    string
    ContextType       string
    RouteVerb         string
    FullPath          string
    Status            int
    ReturnType        *ObjectType
    ReturnsErrorMedia bool
    Params            []*ObjectType
    QueryParams       []*ObjectType
    Headers           []*ObjectType
    Payload           *ObjectType
    // contains filtered or unexported fields
}

TestMethod structure

func (*TestMethod) Escape Uses

func (t *TestMethod) Escape(s string) string

Escape escapes given string.

type UserTypesWriter Uses

type UserTypesWriter struct {
    *codegen.SourceFile
    UserTypeTmpl *template.Template
    Finalizer    *codegen.Finalizer
    Validator    *codegen.Validator
}

UserTypesWriter generate code for a goa application user types. User types are data structures defined in the DSL with "Type".

func NewUserTypesWriter Uses

func NewUserTypesWriter(filename string) (*UserTypesWriter, error)

NewUserTypesWriter returns a contexts code writer. User types contain custom data structured defined in the DSL with "Type".

func (*UserTypesWriter) Execute Uses

func (w *UserTypesWriter) Execute(t *design.UserTypeDefinition) error

Execute writes the code for the context types to the writer.

Package genapp imports 13 packages (graph) and is imported by 19 packages. Updated 2017-09-19. Refresh now. Tools for package owners.