tsgen

package
v0.0.0-...-5d3802e Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prettier

func Prettier(b []byte) ([]byte, error)

Types

type Code

type Code interface {
	// contains filtered or unexported methods
}

type Dict

type Dict map[Code]Code

Dict renders as key/value pairs. Use with Values for map or composite literals.

func DictFunc

func DictFunc(f func(Dict)) Dict

DictFunc executes a func(Dict) to generate the value. Use with Values for map or composite literals.

type File

type File struct {
	*Group
	// contains filtered or unexported fields
}

func NewFile

func NewFile(options ...Option) *File

func (*File) GoString

func (f *File) GoString() string

func (*File) HeaderComment

func (f *File) HeaderComment(comment string)

func (*File) Import

func (f *File) Import(path, name string)

func (*File) ImportAlias

func (f *File) ImportAlias(path, name, alias string)

func (*File) ImportDefault

func (f *File) ImportDefault(path, name string)

func (*File) Render

func (f *File) Render(w io.Writer) error

func (*File) Save

func (f *File) Save(filename string) error

type Group

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

func (*Group) Add

func (g *Group) Add(code ...Code) *Statement

Add appends the provided items to the statement.

func (*Group) Any

func (g *Group) Any() *Statement

Any renders the any identifier.

func (*Group) Assert

func (g *Group) Assert(typ Code) *Statement

Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.

func (*Group) Bigint

func (g *Group) Bigint() *Statement

Bigint renders the bigint identifier.

func (*Group) Block

func (g *Group) Block(statements ...Code) *Statement

Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func (*Group) BlockFunc

func (g *Group) BlockFunc(f func(*Group)) *Statement

BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func (*Group) Boolean

func (g *Group) Boolean() *Statement

Boolean renders the boolean identifier.

func (*Group) Break

func (g *Group) Break() *Statement

Break renders the break keyword.

func (*Group) Call

func (g *Group) Call(params ...Code) *Statement

Call renders a comma separated list enclosed by parenthesis. Use for function calls.

func (*Group) CallFunc

func (g *Group) CallFunc(f func(*Group)) *Statement

CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.

func (*Group) Case

func (g *Group) Case(cases ...Code) *Statement

Case renders the keyword followed by a comma separated list.

func (*Group) CaseFunc

func (g *Group) CaseFunc(f func(*Group)) *Statement

CaseFunc renders the keyword followed by a comma separated list.

func (*Group) Class

func (g *Group) Class() *Statement

Class renders the class keyword.

func (*Group) Const

func (g *Group) Const() *Statement

Const renders the const keyword.

func (*Group) Continue

func (g *Group) Continue() *Statement

Continue renders the continue keyword.

func (*Group) Default

func (g *Group) Default() *Statement

Default renders the default keyword.

func (*Group) Defs

func (g *Group) Defs(definitions ...Code) *Statement

Defs renders a statement list enclosed in parenthesis. Use for definition lists.

func (*Group) DefsFunc

func (g *Group) DefsFunc(f func(*Group)) *Statement

DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.

func (*Group) Do

func (g *Group) Do(f func(*Statement)) *Statement

Do calls the provided function with the statement as a parameter. Use for embedding logic.

func (*Group) Dot

func (g *Group) Dot(name string) *Statement

Dot renders a period followed by an identifier. Use for fields and selectors.

func (*Group) Else

func (g *Group) Else() *Statement

Else renders the else keyword.

func (*Group) Empty

func (g *Group) Empty() *Statement

Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.

func (*Group) Export

func (g *Group) Export() *Statement

Export renders the export keyword.

func (*Group) For

func (g *Group) For(conditions ...Code) *Statement

For renders the keyword followed by a semicolon separated list.

func (*Group) ForFunc

func (g *Group) ForFunc(f func(*Group)) *Statement

ForFunc renders the keyword followed by a semicolon separated list.

func (*Group) Function

func (g *Group) Function() *Statement

Function renders the function keyword.

func (*Group) GoString

func (g *Group) GoString() string

GoString renders the Group for testing. Any error will cause a panic.

func (*Group) Id

func (g *Group) Id(name string) *Statement

Id renders an identifier.

func (*Group) If

func (g *Group) If(conditions ...Code) *Statement

If renders the keyword followed by a semicolon separated list.

func (*Group) IfFunc

func (g *Group) IfFunc(f func(*Group)) *Statement

IfFunc renders the keyword followed by a semicolon separated list.

func (*Group) Import

func (g *Group) Import() *Statement

Import renders the import keyword.

func (*Group) Index

func (g *Group) Index(items ...Code) *Statement

Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func (*Group) IndexFunc

func (g *Group) IndexFunc(f func(*Group)) *Statement

IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func (*Group) Interface

func (g *Group) Interface() *Statement

Interface renders the interface keyword.

func (*Group) Len

func (g *Group) Len(v Code) *Statement

Len renders the len built-in function.

func (*Group) Let

func (g *Group) Let() *Statement

Let renders the let keyword.

func (*Group) Line

func (g *Group) Line() *Statement

Line inserts a blank line.

func (*Group) List

func (g *Group) List(items ...Code) *Statement

List renders a comma separated list. Use for multiple return functions.

func (*Group) ListFunc

func (g *Group) ListFunc(f func(*Group)) *Statement

ListFunc renders a comma separated list. Use for multiple return functions.

func (*Group) Lit

func (g *Group) Lit(v interface{}) *Statement

Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.

func (*Group) LitByte

func (g *Group) LitByte(v byte) *Statement

LitByte renders a byte literal.

func (*Group) LitByteFunc

func (g *Group) LitByteFunc(f func() byte) *Statement

LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.

func (*Group) LitFunc

func (g *Group) LitFunc(f func() interface{}) *Statement

LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.

func (*Group) LitRune

func (g *Group) LitRune(v rune) *Statement

LitRune renders a rune literal.

func (*Group) LitRuneFunc

func (g *Group) LitRuneFunc(f func() rune) *Statement

LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.

func (*Group) Method

func (g *Group) Method(name Code) *Statement

Method renders a method call. Use for method calls.

func (*Group) Namespace

func (g *Group) Namespace() *Statement

Namespace renders the namespace keyword.

func (*Group) New

func (g *Group) New() *Statement

New renders the new keyword.

func (*Group) Null

func (g *Group) Null() *Statement

Null adds a null item. Null items render nothing and are not followed by a separator in lists.

func (*Group) Number

func (g *Group) Number() *Statement

Number renders the number identifier.

func (*Group) Op

func (g *Group) Op(op string) *Statement

Op renders the provided operator / token.

func (*Group) Params

func (g *Group) Params(params ...Code) *Statement

Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func (*Group) ParamsFunc

func (g *Group) ParamsFunc(f func(*Group)) *Statement

ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func (*Group) Parens

func (g *Group) Parens(item Code) *Statement

Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.

func (*Group) Print

func (g *Group) Print(args ...Code) *Statement

Print renders the print built-in function.

func (*Group) PrintFunc

func (g *Group) PrintFunc(f func(*Group)) *Statement

PrintFunc renders the print built-in function.

func (*Group) Qual

func (g *Group) Qual(path, name string) *Statement

Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).

func (*Group) Render

func (g *Group) Render(writer io.Writer) error

Render renders the Group to the provided writer.

func (*Group) RenderWithFile

func (g *Group) RenderWithFile(writer io.Writer, file *File) error

RenderWithFile renders the Group to the provided writer, using imports from the provided file.

func (*Group) Return

func (g *Group) Return(result Code) *Statement

Return renders the keyword followed by a comma separated list.

func (*Group) Semicolon

func (g *Group) Semicolon() *Statement

Semicolon renders a semicolon

func (*Group) String

func (g *Group) String() *Statement

String renders the string identifier.

func (*Group) Switch

func (g *Group) Switch(conditions ...Code) *Statement

Switch renders the keyword followed by a semicolon separated list.

func (*Group) SwitchFunc

func (g *Group) SwitchFunc(f func(*Group)) *Statement

SwitchFunc renders the keyword followed by a semicolon separated list.

func (*Group) Type

func (g *Group) Type() *Statement

Type renders the type keyword.

func (*Group) Types

func (g *Group) Types(types ...Code) *Statement

Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func (*Group) TypesFunc

func (g *Group) TypesFunc(f func(*Group)) *Statement

TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func (*Group) Undefined

func (g *Group) Undefined() *Statement

Undefined renders the undefined identifier.

func (*Group) Union

func (g *Group) Union(types ...Code) *Statement

Union renders a pipe separated list. Use for union type constraints.

func (*Group) UnionFunc

func (g *Group) UnionFunc(f func(*Group)) *Statement

UnionFunc renders a pipe separated list. Use for union type constraints.

func (*Group) Values

func (g *Group) Values(values ...Code) *Statement

Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func (*Group) ValuesFunc

func (g *Group) ValuesFunc(f func(*Group)) *Statement

ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func (*Group) Var

func (g *Group) Var() *Statement

Var renders the var keyword.

type Option

type Option func(f *File) error

func WithPrettierFormatter

func WithPrettierFormatter() Option

type Statement

type Statement []Code

func Add

func Add(code ...Code) *Statement

Add appends the provided items to the statement.

func Any

func Any() *Statement

Any renders the any identifier.

func Assert

func Assert(typ Code) *Statement

Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.

func Bigint

func Bigint() *Statement

Bigint renders the bigint identifier.

func Block

func Block(statements ...Code) *Statement

Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func BlockFunc

func BlockFunc(f func(*Group)) *Statement

BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func Boolean

func Boolean() *Statement

Boolean renders the boolean identifier.

func Break

func Break() *Statement

Break renders the break keyword.

func Call

func Call(params ...Code) *Statement

Call renders a comma separated list enclosed by parenthesis. Use for function calls.

func CallFunc

func CallFunc(f func(*Group)) *Statement

CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.

func Case

func Case(cases ...Code) *Statement

Case renders the keyword followed by a comma separated list.

func CaseFunc

func CaseFunc(f func(*Group)) *Statement

CaseFunc renders the keyword followed by a comma separated list.

func Class

func Class() *Statement

Class renders the class keyword.

func Const

func Const() *Statement

Const renders the const keyword.

func Continue

func Continue() *Statement

Continue renders the continue keyword.

func Default

func Default() *Statement

Default renders the default keyword.

func Defs

func Defs(definitions ...Code) *Statement

Defs renders a statement list enclosed in parenthesis. Use for definition lists.

func DefsFunc

func DefsFunc(f func(*Group)) *Statement

DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.

func Do

func Do(f func(*Statement)) *Statement

Do calls the provided function with the statement as a parameter. Use for embedding logic.

func Dot

func Dot(name string) *Statement

Dot renders a period followed by an identifier. Use for fields and selectors.

func Else

func Else() *Statement

Else renders the else keyword.

func Empty

func Empty() *Statement

Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.

func Export

func Export() *Statement

Export renders the export keyword.

func For

func For(conditions ...Code) *Statement

For renders the keyword followed by a semicolon separated list.

func ForFunc

func ForFunc(f func(*Group)) *Statement

ForFunc renders the keyword followed by a semicolon separated list.

func Function

func Function() *Statement

Function renders the function keyword.

func Id

func Id(name string) *Statement

Id renders an identifier.

func If

func If(conditions ...Code) *Statement

If renders the keyword followed by a semicolon separated list.

func IfFunc

func IfFunc(f func(*Group)) *Statement

IfFunc renders the keyword followed by a semicolon separated list.

func Import

func Import() *Statement

Import renders the import keyword.

func Index

func Index(items ...Code) *Statement

Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func IndexFunc

func IndexFunc(f func(*Group)) *Statement

IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func Interface

func Interface() *Statement

Interface renders the interface keyword.

func Len

func Len(v Code) *Statement

Len renders the len built-in function.

func Let

func Let() *Statement

Let renders the let keyword.

func Line

func Line() *Statement

Line inserts a blank line.

func List

func List(items ...Code) *Statement

List renders a comma separated list. Use for multiple return functions.

func ListFunc

func ListFunc(f func(*Group)) *Statement

ListFunc renders a comma separated list. Use for multiple return functions.

func Lit

func Lit(v interface{}) *Statement

Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.

func LitByte

func LitByte(v byte) *Statement

LitByte renders a byte literal.

func LitByteFunc

func LitByteFunc(f func() byte) *Statement

LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.

func LitFunc

func LitFunc(f func() interface{}) *Statement

LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.

func LitRune

func LitRune(v rune) *Statement

LitRune renders a rune literal.

func LitRuneFunc

func LitRuneFunc(f func() rune) *Statement

LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.

func Method

func Method(name Code) *Statement

Method renders a method call. Use for method calls.

func Namespace

func Namespace() *Statement

Namespace renders the namespace keyword.

func New

func New() *Statement

New renders the new keyword.

func Null

func Null() *Statement

Null adds a null item. Null items render nothing and are not followed by a separator in lists.

func Number

func Number() *Statement

Number renders the number identifier.

func Op

func Op(op string) *Statement

Op renders the provided operator / token.

func Params

func Params(params ...Code) *Statement

Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func ParamsFunc

func ParamsFunc(f func(*Group)) *Statement

ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func Parens

func Parens(item Code) *Statement

Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.

func Print

func Print(args ...Code) *Statement

Print renders the print built-in function.

func PrintFunc

func PrintFunc(f func(*Group)) *Statement

PrintFunc renders the print built-in function.

func Qual

func Qual(path, name string) *Statement

Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).

func Return

func Return(result Code) *Statement

Return renders the keyword followed by a comma separated list.

func Semicolon

func Semicolon() *Statement

Semicolon renders a semicolon

func String

func String() *Statement

String renders the string identifier.

func Switch

func Switch(conditions ...Code) *Statement

Switch renders the keyword followed by a semicolon separated list.

func SwitchFunc

func SwitchFunc(f func(*Group)) *Statement

SwitchFunc renders the keyword followed by a semicolon separated list.

func Type

func Type() *Statement

Type renders the type keyword.

func Types

func Types(types ...Code) *Statement

Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func TypesFunc

func TypesFunc(f func(*Group)) *Statement

TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func Undefined

func Undefined() *Statement

Undefined renders the undefined identifier.

func Union

func Union(types ...Code) *Statement

Union renders a pipe separated list. Use for union type constraints.

func UnionFunc

func UnionFunc(f func(*Group)) *Statement

UnionFunc renders a pipe separated list. Use for union type constraints.

func Values

func Values(values ...Code) *Statement

Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func ValuesFunc

func ValuesFunc(f func(*Group)) *Statement

ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func Var

func Var() *Statement

Var renders the var keyword.

func (*Statement) Add

func (s *Statement) Add(code ...Code) *Statement

Add appends the provided items to the statement.

func (*Statement) Any

func (s *Statement) Any() *Statement

Any renders the any identifier.

func (*Statement) Assert

func (s *Statement) Assert(typ Code) *Statement

Assert renders a period followed by a single item enclosed by parenthesis. Use for type assertions.

func (*Statement) Bigint

func (s *Statement) Bigint() *Statement

Bigint renders the bigint identifier.

func (*Statement) Block

func (s *Statement) Block(statements ...Code) *Statement

Block renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func (*Statement) BlockFunc

func (s *Statement) BlockFunc(f func(*Group)) *Statement

BlockFunc renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.

func (*Statement) Boolean

func (s *Statement) Boolean() *Statement

Boolean renders the boolean identifier.

func (*Statement) Break

func (s *Statement) Break() *Statement

Break renders the break keyword.

func (*Statement) Call

func (s *Statement) Call(params ...Code) *Statement

Call renders a comma separated list enclosed by parenthesis. Use for function calls.

func (*Statement) CallFunc

func (s *Statement) CallFunc(f func(*Group)) *Statement

CallFunc renders a comma separated list enclosed by parenthesis. Use for function calls.

func (*Statement) Case

func (s *Statement) Case(cases ...Code) *Statement

Case renders the keyword followed by a comma separated list.

func (*Statement) CaseFunc

func (s *Statement) CaseFunc(f func(*Group)) *Statement

CaseFunc renders the keyword followed by a comma separated list.

func (*Statement) Class

func (s *Statement) Class() *Statement

Class renders the class keyword.

func (*Statement) Clone

func (s *Statement) Clone() *Statement

Clone makes a copy of the Statement, so further tokens can be appended without affecting the original.

func (*Statement) Const

func (s *Statement) Const() *Statement

Const renders the const keyword.

func (*Statement) Continue

func (s *Statement) Continue() *Statement

Continue renders the continue keyword.

func (*Statement) Default

func (s *Statement) Default() *Statement

Default renders the default keyword.

func (*Statement) Defs

func (s *Statement) Defs(definitions ...Code) *Statement

Defs renders a statement list enclosed in parenthesis. Use for definition lists.

func (*Statement) DefsFunc

func (s *Statement) DefsFunc(f func(*Group)) *Statement

DefsFunc renders a statement list enclosed in parenthesis. Use for definition lists.

func (*Statement) Do

func (s *Statement) Do(f func(*Statement)) *Statement

Do calls the provided function with the statement as a parameter. Use for embedding logic.

func (*Statement) Dot

func (s *Statement) Dot(name string) *Statement

Dot renders a period followed by an identifier. Use for fields and selectors.

func (*Statement) Else

func (s *Statement) Else() *Statement

Else renders the else keyword.

func (*Statement) Empty

func (s *Statement) Empty() *Statement

Empty adds an empty item. Empty items render nothing but are followed by a separator in lists.

func (*Statement) Export

func (s *Statement) Export() *Statement

Export renders the export keyword.

func (*Statement) For

func (s *Statement) For(conditions ...Code) *Statement

For renders the keyword followed by a semicolon separated list.

func (*Statement) ForFunc

func (s *Statement) ForFunc(f func(*Group)) *Statement

ForFunc renders the keyword followed by a semicolon separated list.

func (*Statement) Function

func (s *Statement) Function() *Statement

Function renders the function keyword.

func (*Statement) Id

func (s *Statement) Id(name string) *Statement

Id renders an identifier.

func (*Statement) If

func (s *Statement) If(conditions ...Code) *Statement

If renders the keyword followed by a semicolon separated list.

func (*Statement) IfFunc

func (s *Statement) IfFunc(f func(*Group)) *Statement

IfFunc renders the keyword followed by a semicolon separated list.

func (*Statement) Import

func (s *Statement) Import() *Statement

Import renders the import keyword.

func (*Statement) Index

func (s *Statement) Index(items ...Code) *Statement

Index renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func (*Statement) IndexFunc

func (s *Statement) IndexFunc(f func(*Group)) *Statement

IndexFunc renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.

func (*Statement) Interface

func (s *Statement) Interface() *Statement

Interface renders the interface keyword.

func (*Statement) Len

func (s *Statement) Len(v Code) *Statement

Len renders the len built-in function.

func (*Statement) Let

func (s *Statement) Let() *Statement

Let renders the let keyword.

func (*Statement) Line

func (s *Statement) Line() *Statement

Line inserts a blank line.

func (*Statement) List

func (s *Statement) List(items ...Code) *Statement

List renders a comma separated list. Use for multiple return functions.

func (*Statement) ListFunc

func (s *Statement) ListFunc(f func(*Group)) *Statement

ListFunc renders a comma separated list. Use for multiple return functions.

func (*Statement) Lit

func (s *Statement) Lit(v interface{}) *Statement

Lit renders a literal. Lit supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Passing any other type will panic.

func (*Statement) LitByte

func (s *Statement) LitByte(v byte) *Statement

LitByte renders a byte literal.

func (*Statement) LitByteFunc

func (s *Statement) LitByteFunc(f func() byte) *Statement

LitByteFunc renders a byte literal. LitByteFunc generates the value to render by executing the provided function.

func (*Statement) LitFunc

func (s *Statement) LitFunc(f func() interface{}) *Statement

LitFunc renders a literal. LitFunc generates the value to render by executing the provided function. LitFunc supports only built-in types (bool, string, int, complex128, float64, float32, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr and complex64). Returning any other type will panic.

func (*Statement) LitRune

func (s *Statement) LitRune(v rune) *Statement

LitRune renders a rune literal.

func (*Statement) LitRuneFunc

func (s *Statement) LitRuneFunc(f func() rune) *Statement

LitRuneFunc renders a rune literal. LitRuneFunc generates the value to render by executing the provided function.

func (*Statement) Method

func (s *Statement) Method(name Code) *Statement

Method renders a method call. Use for method calls.

func (*Statement) Namespace

func (s *Statement) Namespace() *Statement

Namespace renders the namespace keyword.

func (*Statement) New

func (s *Statement) New() *Statement

New renders the new keyword.

func (*Statement) Null

func (s *Statement) Null() *Statement

Null adds a null item. Null items render nothing and are not followed by a separator in lists.

func (*Statement) Number

func (s *Statement) Number() *Statement

Number renders the number identifier.

func (*Statement) Op

func (s *Statement) Op(op string) *Statement

Op renders the provided operator / token.

func (*Statement) Params

func (s *Statement) Params(params ...Code) *Statement

Params renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func (*Statement) ParamsFunc

func (s *Statement) ParamsFunc(f func(*Group)) *Statement

ParamsFunc renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.

func (*Statement) Parens

func (s *Statement) Parens(item Code) *Statement

Parens renders a single item in parenthesis. Use for type conversion or to specify evaluation order.

func (*Statement) Print

func (s *Statement) Print(args ...Code) *Statement

Print renders the print built-in function.

func (*Statement) PrintFunc

func (s *Statement) PrintFunc(f func(*Group)) *Statement

PrintFunc renders the print built-in function.

func (*Statement) Qual

func (s *Statement) Qual(path, name string) *Statement

Qual renders a qualified identifier. Imports are automatically added when used with a File. If the path matches the local path, the package name is omitted. If package names conflict they are automatically renamed. Note that it is not possible to reliably determine the package name given an arbitrary package path, so a sensible name is guessed from the path and added as an alias. The names of all standard library packages are known so these do not need to be aliased. If more control is needed of the aliases, see [File.ImportName](#importname) or File.ImportAlias(#importalias).

func (*Statement) Render

func (s *Statement) Render(writer io.Writer) error

Render renders the Statement to the provided writer.

func (*Statement) RenderWithFile

func (s *Statement) RenderWithFile(writer io.Writer, file *File) error

RenderWithFile renders the Statement to the provided writer, using imports from the provided file.

func (*Statement) Return

func (s *Statement) Return(result Code) *Statement

Return renders the keyword followed by a comma separated list.

func (*Statement) Semicolon

func (s *Statement) Semicolon() *Statement

Semicolon renders a semicolon

func (*Statement) String

func (s *Statement) String() *Statement

String renders the string identifier.

func (*Statement) Switch

func (s *Statement) Switch(conditions ...Code) *Statement

Switch renders the keyword followed by a semicolon separated list.

func (*Statement) SwitchFunc

func (s *Statement) SwitchFunc(f func(*Group)) *Statement

SwitchFunc renders the keyword followed by a semicolon separated list.

func (*Statement) Type

func (s *Statement) Type() *Statement

Type renders the type keyword.

func (*Statement) Types

func (s *Statement) Types(types ...Code) *Statement

Types renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func (*Statement) TypesFunc

func (s *Statement) TypesFunc(f func(*Group)) *Statement

TypesFunc renders a comma separated list enclosed by square brackets. Use for type parameters and constraints.

func (*Statement) TypescriptString

func (s *Statement) TypescriptString() string

GoString renders the Statement for testing. Any error will cause a panic.

func (*Statement) Undefined

func (s *Statement) Undefined() *Statement

Undefined renders the undefined identifier.

func (*Statement) Union

func (s *Statement) Union(types ...Code) *Statement

Union renders a pipe separated list. Use for union type constraints.

func (*Statement) UnionFunc

func (s *Statement) UnionFunc(f func(*Group)) *Statement

UnionFunc renders a pipe separated list. Use for union type constraints.

func (*Statement) Values

func (s *Statement) Values(values ...Code) *Statement

Values renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func (*Statement) ValuesFunc

func (s *Statement) ValuesFunc(f func(*Group)) *Statement

ValuesFunc renders a comma separated list enclosed by curly braces. Use for slice or composite literals.

func (*Statement) Var

func (s *Statement) Var() *Statement

Var renders the var keyword.

Jump to

Keyboard shortcuts

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