genapp

package
v0.0.0-...-655ad1f Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: MIT Imports: 10 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 Generate

func Generate(api *design.APIDefinition) ([]string, 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
	MediaTypes   map[string]*design.MediaTypeDefinition
	Types        map[string]*design.UserTypeDefinition
}

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) MustSetHas

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

MustSetHas returns true if the "Has" context field for the given parameter must be generated.

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.GoGenerator
	CtxTmpl        *template.Template
	CtxNewTmpl     *template.Template
	CtxRespTmpl    *template.Template
	PayloadTmpl    *template.Template
	NewPayloadTmpl *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 {
	Resource string                   // Lower case plural resource name, e.g. "bottles"
	Actions  []map[string]interface{} // Array of actions, each action has keys "Name", "Routes" and "Context"
}

ControllerTemplateData contains the information required to generate an action handler.

type ControllersWriter

type ControllersWriter struct {
	*codegen.GoGenerator
	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

type Generator

type Generator struct {
	*codegen.GoGenerator
	ContextsWriter    *ContextsWriter
	ControllersWriter *ControllersWriter
	ResourcesWriter   *ResourcesWriter
	MediaTypesWriter  *MediaTypesWriter
	UserTypesWriter   *UserTypesWriter
	// contains filtered or unexported fields
}

Generator is the application code generator.

func NewGenerator

func NewGenerator() (*Generator, error)

NewGenerator returns 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, error)

Generate the application code, implement codegen.Generator.

type MediaTypesWriter

type MediaTypesWriter struct {
	*codegen.GoGenerator
	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.GoGenerator
	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.GoGenerator
	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