genapp

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

WildcardRegex is the regex used to capture path parameters.

Functions

func Generate

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

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

Types

type ContextTemplateData

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

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

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

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

IterateResponses iterates through the responses sorted by status code.

func (*ContextTemplateData) MustValidate

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

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

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

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

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

type ControllerTemplateData

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", "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

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

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

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

Execute writes the handlers GoGenerator

func (*ControllersWriter) WriteInitService

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

WriteInitService writes the initService function

type EncoderTemplateData

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.

func BuildEncoders

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.

type Generator

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 (*Generator) Cleanup

func (g *Generator) Cleanup()

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

func (*Generator) Generate

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

Generate the application code, implement codegen.Generator.

type MediaTypesWriter

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

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

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

type ObjectType

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

ObjectType structure

type ResourceData

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

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

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

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

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

type SecurityWriter

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

SecurityWriter generate code for action-level security handlers.

func NewSecurityWriter

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

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

Execute adds the different security schemes and middleware supporting functions.

type TestMethod

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
}

TestMethod structure

type UserTypesWriter

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL