codegen

package
v0.0.0-...-581c8d3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package codegen generates Go, Protobuf, Flatbuffers, TypeScript, etc. code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncloseBT

func EncloseBT(s string) string

EncloseBT encloses the string s in backticks

func SkipWS

func SkipWS(str ...interface{}) []byte

SkipWS converts all arguments to type string, panics if it does not support a type, and merges all arguments to one single string without white space concatenation. This function can be used as argument to Pln or P or C.

Types

type FormatError

type FormatError struct {
	Code string
	// contains filtered or unexported fields
}

FormatError gets returned when generating the source code in case gofmt or any equal other program for a language can't run the formatting.

func (*FormatError) ErrorKind

func (*FormatError) ErrorKind() errors.Kind

type Go

type Go struct {
	BuildTags []string // each entry is one line
	// contains filtered or unexported fields
}

func NewGo

func NewGo(packageName string) *Go

NewGo creates a new Go source code generator for a specific new package.

func (*Go) AddImport

func (g *Go) AddImport(importPath, packageName string)

AddImport adds a new import path. importPath required and packageName optional.

func (*Go) AddImports

func (g *Go) AddImports(importPaths ...string)

AddImports adds multiple import paths at once. They all must have unique base names.

func (*Go) AddInitf

func (g *Go) AddInitf(stmt string, a ...interface{})

AddInitf stores the given statement to be printed inside the file's init function. The statement is given as a format specifier and arguments.

func (*Go) C

func (g *Go) C(comments ...interface{})

Writes a multiline comment and formats it to a max width of 80 chars. It adds automatically the comment prefix `//`. It converts all types to string, if it can't it panics. If the first argument is a boolean and true, the subsequent data gets printed, otherwise not.

func (*Go) GenerateFile

func (g *Go) GenerateFile(w io.Writer) error

func (*Go) In

func (g *Go) In()

In Indents the output one tab stop.

func (*Go) Out

func (g *Go) Out()

Out unindents the output one tab stop.

func (*Go) P

func (g *Go) P(str ...interface{})

P same as Pln but without the line break at the end.

func (*Go) Pln

func (g *Go) Pln(str ...interface{})

Pln prints the arguments to the generated output. It tries to convert all kind of types to a string. It adds a line break at the end IF there are strs to print. If the first argument is a boolean and true, the subsequent data gets printed, otherwise not.

func (*Go) WriteConstants

func (g *Go) WriteConstants(lines ...string)

WriteConstants add a const () declaration to the current position in the buffer. A line includes the const name equal value.

type Proto

type Proto struct {
	// contains filtered or unexported fields
}

func NewProto

func NewProto(packageName string) *Proto

NewProto creates a new Proto source code generator for a specific new package.

func (*Proto) AddImport

func (g *Proto) AddImport(importPath, packageName string)

AddImport adds a new import path. importPath required and packageName optional.

func (*Proto) AddImports

func (g *Proto) AddImports(importPaths ...string)

AddImports adds multiple import paths at once. They all must have unique base names.

func (*Proto) AddOptions

func (g *Proto) AddOptions(nameRawValue ...string)

func (*Proto) C

func (g *Proto) C(comments ...interface{})

Writes a multiline comment and formats it to a max width of 80 chars. It adds automatically the comment prefix `//`. It converts all types to string, if it can't it panics. If the first argument is a boolean and true, the subsequent data gets printed, otherwise not.

func (*Proto) GenerateFile

func (g *Proto) GenerateFile(w io.Writer) error

func (*Proto) In

func (g *Proto) In()

In Indents the output one tab stop.

func (*Proto) Out

func (g *Proto) Out()

Out unindents the output one tab stop.

func (*Proto) P

func (g *Proto) P(str ...interface{})

P same as Pln but without the line break at the end.

func (*Proto) Pln

func (g *Proto) Pln(str ...interface{})

Pln prints the arguments to the generated output. It tries to convert all kind of types to a string. It adds a line break at the end IF there are strs to print. If the first argument is a boolean and true, the subsequent data gets printed, otherwise not.

Jump to

Keyboard shortcuts

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