genapp

package
v0.0.0-...-b874cf7 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TargetPackage is the name of the generated Go package.
	TargetPackage string
)
View Source
var WildcardRegex = regexp.MustCompile("(?:[^/]*/:([^/]+))+")

WildcardRegex is the regex used to capture path parameters.

Functions

func AppOutputDir

func AppOutputDir() string

AppOutputDir returns the directory containing the generated files.

func AppPackagePath

func AppPackagePath() (string, error)

AppPackagePath returns the Go package path to the generated package.

func Generate

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

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

func MergeResponses

func MergeResponses(l, r map[string]*design.ResponseDefinition) map[string]*design.ResponseDefinition

MergeResponses merge the response maps overriding the first argument map entries with the second argument map entries in case of collision.

Types

type Command

type Command struct {
	*codegen.BaseCommand
}

Command is the goa application code generator command line data structure.

func NewCommand

func NewCommand() *Command

NewCommand instantiates a new command.

func (*Command) RegisterFlags

func (c *Command) RegisterFlags(r codegen.FlagRegistry)

RegisterFlags registers the command line flags with the given registry.

func (*Command) Run

func (c *Command) Run() ([]string, error)

Run simply calls the meta generator.

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
}

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

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 httprouter 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
}

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"
	Encoders []*EncoderTemplateData   // Encoder data
	Decoders []*EncoderTemplateData   // Decoder data
}

ControllerTemplateData contains the information required to generate an action handler.

type ControllersWriter

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

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 {
	// 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(api *design.APIDefinition) (_ []string, err error)

Generate the application code, implement codegen.Generator.

type MediaTypesWriter

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

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 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 UserTypesWriter

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

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