Documentation ¶
Index ¶
- Constants
- Variables
- func GetPackageComponents(pkg string) []string
- func ValidateOption(lang, option string) bool
- type BaseGenerator
- func (b *BaseGenerator) CreateFile(name, outputDir, suffix string, usePrefix bool) (*os.File, error)
- func (b *BaseGenerator) GenerateBlockComment(comment []string, indent string) string
- func (b *BaseGenerator) GenerateInlineComment(comment []string, indent string) string
- func (b *BaseGenerator) GenerateNewline(file *os.File, count int) error
- func (b *BaseGenerator) GetElem() string
- func (b *BaseGenerator) GetServiceMethodTypes(service *parser.Service) []*parser.Struct
- func (b *BaseGenerator) SetFrugal(f *parser.Frugal)
- type FileType
- type LanguageGenerator
- type LanguageOptions
- type Options
- type ProgramGenerator
Constants ¶
const FilePrefix = "f_"
FilePrefix is the default prefix for generated files.
Variables ¶
var Languages = LanguageOptions{ "go": Options{ "thrift_import": "Override Thrift package import path (default: git.apache.org/thrift.git/lib/go/thrift)", "frugal_import": "Override Frugal package import path (default: github.com/Workiva/frugal/lib/go)", "package_prefix": "Package prefix for generated files", "async": "Generate async client code using channels", "use_vendor": "Use specified import references for vendored includes and do not generate code for them", "slim": "Generate slim type definitions (WARNING: code generated by this may break code consumers, protocol logic should not change)", "suppress_deprecated_logging": "Suppress decrecated API usage warning logging", }, "gopherjs": Options{ "package_prefix": "Package prefix for generated files", "use_vendor": "Use specified import references for vendored includes and do not generate code for them", }, "java": Options{ "generated_annotations": "[use|undated|suppress] " + "use: add @Generated annotations, " + "undated: suppress the date, " + "suppress (default): suppress the annotations", "async": "Generate async client code using futures", "boxed_primitives": "Generate primitives as the boxed equivalents", "use_vendor": "Use specified import references for vendored includes and do not generate code for them", "suppress_deprecated_logging": "Suppress decrecated API usage warning logging", }, "dart": Options{ "library_prefix": "Generate code that can be used within an existing library. " + "Use a dot-separated string, e.g. \"my_parent_lib.src.gen\"", "use_enums": "Generate enums as enums rather than a class with numerical constants", "use_vendor": "Use specified import references for vendored includes and do not generate code for them", }, "py": Options{ "tornado": "Generate code for use with Tornado (compatible with Python 2.7)", "asyncio": "Generate code for use with asyncio (compatible with Python 3.5 or above)", "package_prefix": "Package prefix for generated files", }, "html": Options{ "standalone": "Self-contained mode, includes all CSS in the HTML files. Generates no style.css file, but HTML files will be larger", }, }
Languages is a map of supported language to a map of the generator options it supports.
Functions ¶
func GetPackageComponents ¶
GetPackageComponents returns the package string split on dots.
func ValidateOption ¶
ValidateOption indicates if the language option is supported for the given language.
Types ¶
type BaseGenerator ¶
type BaseGenerator struct { Options map[string]string Frugal *parser.Frugal // contains filtered or unexported fields }
BaseGenerator contains base generator logic which language generators can extend.
func (*BaseGenerator) CreateFile ¶
func (b *BaseGenerator) CreateFile(name, outputDir, suffix string, usePrefix bool) (*os.File, error)
CreateFile creates a new file using the given configuration.
func (*BaseGenerator) GenerateBlockComment ¶
func (b *BaseGenerator) GenerateBlockComment(comment []string, indent string) string
GenerateBlockComment generates a C-style comment.
func (*BaseGenerator) GenerateInlineComment ¶
func (b *BaseGenerator) GenerateInlineComment(comment []string, indent string) string
GenerateInlineComment generates an inline comment.
func (*BaseGenerator) GenerateNewline ¶
func (b *BaseGenerator) GenerateNewline(file *os.File, count int) error
GenerateNewline adds the specific number of newlines to the given file.
func (*BaseGenerator) GetElem ¶
func (b *BaseGenerator) GetElem() string
func (*BaseGenerator) GetServiceMethodTypes ¶
func (b *BaseGenerator) GetServiceMethodTypes(service *parser.Service) []*parser.Struct
func (*BaseGenerator) SetFrugal ¶
func (b *BaseGenerator) SetFrugal(f *parser.Frugal)
SetFrugal sets the Frugal parse tree for this generator.
type FileType ¶
type FileType string
FileType represents a generated file type.
const ( CombinedServiceFile FileType = "combined_service" CombinedScopeFile FileType = "combined_scope" PublishFile FileType = "publish" SubscribeFile FileType = "subscribe" TypeFile FileType = "types" ServiceArgsResultsFile FileType = "service_args_results" ObjectFile FileType = "object" )
Valid FileTypes.
type LanguageGenerator ¶
type LanguageGenerator interface { // Generic methods SetFrugal(*parser.Frugal) SetupGenerator(outputDir string) error TeardownGenerator() error GenerateDependencies(dir string) error GenerateFile(name, outputDir string, fileType FileType) (*os.File, error) GenerateDocStringComment(*os.File) error GenerateConstants(f *os.File, name string) error GenerateNewline(*os.File, int) error GetOutputDir(dir string) string DefaultOutputDir() string PostProcess(*os.File) error // Thrift stuff GenerateConstantsContents([]*parser.Constant) error GenerateTypeDef(*parser.TypeDef) error GenerateEnum(*parser.Enum) error GenerateStruct(*parser.Struct) error GenerateUnion(*parser.Struct) error GenerateException(*parser.Struct) error // Service-specific methods GenerateServicePackage(*os.File, *parser.Service) error GenerateServiceImports(*os.File, *parser.Service) error GenerateService(*os.File, *parser.Service) error // Scope-specific methods GenerateScopePackage(*os.File, *parser.Scope) error GenerateScopeImports(*os.File, *parser.Scope) error GeneratePublisher(*os.File, *parser.Scope) error GenerateSubscriber(*os.File, *parser.Scope) error // UseVendor returns whether this generator instance supports using // vendored includes UseVendor() bool }
LanguageGenerator generates source code as implemented for specific languages.
type LanguageOptions ¶
LanguageOptions contains a map of language to generator options.
type Options ¶
Options contains language generator options. The map key is the option name, and the value is the option description.
type ProgramGenerator ¶
type ProgramGenerator interface { // Generate the Frugal in the given directory. Generate(frugal *parser.Frugal, outputDir string) error // GetOutputDir returns the full output directory for generated code. GetOutputDir(dir string, f *parser.Frugal) string // DefaultOutputDir returns the default directory for generated code. DefaultOutputDir() string // UseVendor returns whether this generator supports using vendored includes UseVendor() bool }
ProgramGenerator generates source code in a specified language for a Frugal produced by the parser.
func NewProgramGenerator ¶
func NewProgramGenerator(generator LanguageGenerator, splitPublisherSubscriber bool) ProgramGenerator
NewProgramGenerator creates a new ProgramGenerator using the given LanguageGenerator.