gen

package
v0.0.0-...-03ebdbe Latest Latest
Warning

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

Go to latest
Published: May 15, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gen provides functions for generating go source code

The gen package provides wrapper functions around the go/ast and go/token packages to reduce boilerplate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstChar

func ConstChar(args ...string) *ast.GenDecl

ConstChar creates a series of character const declarations from the name/value pairs in args.

func ConstFloat

func ConstFloat(args ...string) *ast.GenDecl

ConstFloat creates a series of floating-point const declarations from the name/value pairs in args.

func ConstImaginary

func ConstImaginary(args ...string) *ast.GenDecl

ConstImaginary creates a series of imaginary const declarations from the name/value pairs in args.

func ConstInt

func ConstInt(args ...string) *ast.GenDecl

ConstInt creates a series of numeric const declarations from the name/value pairs in args.

func ConstString

func ConstString(args ...string) *ast.GenDecl

ConstString creates a series of string const declarations from the name/value pairs in args.

func ExprString

func ExprString(expr ast.Expr) string

ExprString converts an ast.Expr to the Go source it represents.

func FieldList

func FieldList(fields ...string) (*ast.FieldList, error)

FieldList generates a field list from strings in the form "[name] expr".

func Public

func Public(name string) *ast.Ident

Public turns a string into a public (uppercase) identifier.

func SimpleType

func SimpleType(name string) ast.Expr

SimpleType creates an identifier suitable for use as a type expression.

func String

func String(s string) *ast.BasicLit

String generates a literal string. If the string contains a double quote, backticks are used for quoting instead.

func Struct

func Struct(args ...ast.Expr) *ast.StructType

Struct creates a struct{} expression. The arguments are a series of name/type/tag tuples. Name must be of type *ast.Ident, type must be of type ast.Expr, and tag must be of type *ast.BasicLit, The number of arguments must be a multiple of 3, or a run-time panic will occur.

func TagKey

func TagKey(field *ast.Field, key string) string

TagKey gets the struct tag item with the given key.

func TypeDecl

func TypeDecl(name *ast.Ident, typ ast.Expr) *ast.GenDecl

TypeDecl generates a type declaration with the given name.

Types

type Function

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

func Func

func Func(name string) *Function

func (*Function) Args

func (fn *Function) Args(args ...string) *Function

Args sets the arguments that a function takes.

func (*Function) Body

func (fn *Function) Body(format string, v ...interface{}) *Function

Body sets the body of a function. The body should not include enclosing braces.

func (*Function) Comment

func (fn *Function) Comment(s string) *Function

Comments sets the Godoc comments for the function.

func (*Function) Decl

func (fn *Function) Decl() (*ast.FuncDecl, error)

Decl generates Go source for a Func. an error is returned if the body, or parameters cannot be parsed.

func (*Function) Receiver

func (fn *Function) Receiver(receiver string) *Function

Receiver turns the function into a method operating on the specified type.

func (*Function) Returns

func (fn *Function) Returns(values ...string) *Function

Returns sets the return values of a function. Each return value should be a string matching the Go syntax for a single return value.

Jump to

Keyboard shortcuts

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