Documentation ¶
Index ¶
- Variables
- func AppOutputDir() string
- func AppPackagePath() (string, error)
- func BuildEncoderMap(info []*design.EncodingDefinition, encoder bool) (map[string]*EncoderTemplateData, error)
- func Generate(roots []interface{}) (files []string, err error)
- func MergeResponses(l, r map[string]*design.ResponseDefinition) map[string]*design.ResponseDefinition
- type Command
- type ContextTemplateData
- type ContextsWriter
- type ControllerTemplateData
- type ControllersWriter
- type EncoderTemplateData
- type Generator
- type MediaTypeTemplateData
- type MediaTypesWriter
- type ResourceData
- type ResourcesWriter
- type UserTypeTemplateData
- type UserTypesWriter
Constants ¶
This section is empty.
Variables ¶
var ( // TargetPackage is the name of the generated Go package. TargetPackage string )
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 ¶
AppPackagePath returns the Go package path to the generated package.
func BuildEncoderMap ¶
func BuildEncoderMap(info []*design.EncodingDefinition, encoder bool) (map[string]*EncoderTemplateData, error)
BuildEncoderMap 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 encoder Go package path.
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 (*Command) RegisterFlags ¶
func (c *Command) RegisterFlags(r codegen.FlagRegistry)
RegisterFlags registers the command line flags with the given registry.
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 Version *design.APIVersionDefinition 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.
func (*ContextTemplateData) Versioned ¶
func (c *ContextTemplateData) Versioned() bool
Versioned returns true if the context was built from an API version.
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 { 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" Version *design.APIVersionDefinition // Controller API version EncoderMap map[string]*EncoderTemplateData // Encoder data indexed by package path DecoderMap map[string]*EncoderTemplateData // Decoder data indexed by package path }
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
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 // Factory is the name of the package variable implementing the decoder / encoder factory. Factory 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 ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is the application code generator.
type MediaTypeTemplateData ¶
type MediaTypeTemplateData struct { MediaType *design.MediaTypeDefinition Versioned bool DefaultPkg string }
MediaTypeTemplateData contains all the information used by the template to redner the media types code.
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 ¶
func (w *MediaTypesWriter) Execute(data *MediaTypeTemplateData) error
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 UserTypeTemplateData ¶
type UserTypeTemplateData struct { UserType *design.UserTypeDefinition Versioned bool DefaultPkg string }
UserTypeTemplateData contains all the information used by the template to redner the media types code.
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 ¶
func (w *UserTypesWriter) Execute(data *UserTypeTemplateData) error
Execute writes the code for the context types to the writer.