meta

package module
v0.0.0-...-f3ee89d Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: MIT Imports: 16 Imported by: 0

README

meta

Boilerplate for code generation with go/types and go/ast

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStructs

func AppendStructs(specs []*ast.TypeSpec, f *ast.File) []*ast.TypeSpec

func Base

func Base(t types.Type) string

func Basic

func Basic(t types.Type) (*types.Basic, bool)

func BasicInfo

func BasicInfo(t types.Type, info types.BasicInfo) (*types.Basic, bool)

func BasicKind

func BasicKind(t types.Type, k types.BasicKind) (*types.Basic, bool)

func Embedded

func Embedded(field *types.Var) (*types.Struct, bool)

func ErrorInterface

func ErrorInterface() *types.Interface

func FieldName

func FieldName(field *types.Var) string

func ForEachStruct

func ForEachStruct(f *ast.File, fn func(s *ast.StructType, t *ast.TypeSpec))

func ForEachTypeSpec

func ForEachTypeSpec(f *ast.File, fn func(t *ast.TypeSpec))

func ForEachValueSpec

func ForEachValueSpec(f *ast.File, fn func(spec *ast.ValueSpec))

func ForEachVar

func ForEachVar(spec *ast.ValueSpec, fn func(id *ast.Ident, v ast.Expr))

func HasTag

func HasTag(tag, key string) bool

func IgnoreTestFiles

func IgnoreTestFiles(f os.FileInfo) bool

func IsString

func IsString(t types.Type) (ok bool)

func IsStruct

func IsStruct(t types.Type) (ok bool)

func MakeInterface

func MakeInterface(name string, params []types.Type, results []types.Type, v bool) *types.Interface

func MustImport

func MustImport(path string) *types.Package

func Nilable

func Nilable(t types.Type) bool

func Pointer

func Pointer(t types.Type) (*types.Pointer, bool)

func ShortestPath

func ShortestPath(a, b FieldPath) int

ShortestPath compares the paths of two fields.

func Sized

func Sized(t types.Type) bool

func Slice

func Slice(t types.Type) (*types.Slice, bool)

func String

func String(t types.Type) (*types.Basic, bool)

func Struct

func Struct(t types.Type) (*types.Struct, bool)

func TypeImports

func TypeImports(imports []*types.Package, t ...interface{}) []*types.Package

func TypeSpec

func TypeSpec(i *ast.Ident) *ast.TypeSpec

func Vars

func Vars(pkg *types.Package, typ ...types.Type) (v []*types.Var)

Types

type Code

type Code struct {
	Imports []*types.Package
	Code    []byte
	// contains filtered or unexported fields
}

func Printf

func Printf(src string, args ...interface{}) (code Code)

func (Code) Append

func (c Code) Append(cc Code) Code

func (Code) Err

func (c Code) Err() error

func (Code) Error

func (c Code) Error(err error) Code

func (Code) Errorf

func (c Code) Errorf(format string, a ...interface{}) Code

func (Code) Format

func (c Code) Format() Code

func (Code) Import

func (c Code) Import(args ...interface{}) Code

func (Code) Print

func (c Code) Print(args ...interface{}) Code

func (Code) Printf

func (c Code) Printf(format string, args ...interface{}) Code

func (Code) Println

func (c Code) Println(args ...interface{}) Code

func (Code) QPrintf

func (c Code) QPrintf(q types.Qualifier, format string, args ...interface{}) Code

func (Code) String

func (c Code) String() string

}

func (*Code) Write

func (c *Code) Write(p []byte) (int, error)

type Field

type Field struct {
	*types.Var
	Tag  string
	Path FieldPath
}

func (Field) WithTag

func (f Field) WithTag(key string) Field

type FieldIndex

type FieldIndex struct {
	Index int
	*types.Var
	Tag string
}

func (FieldIndex) Name

func (f FieldIndex) Name() string

type FieldPath

type FieldPath []FieldIndex

func (FieldPath) Copy

func (p FieldPath) Copy() FieldPath

Copy creates a copy of a path.

func (FieldPath) String

func (p FieldPath) String() string

type Fields

type Fields map[string][]Field

func NewFields

func NewFields(s *types.Struct, embed bool) Fields

NewFields creates a field map for a struct.

func (Fields) Add

func (fields Fields) Add(field Field) Fields

Add adds a field to a field map handling duplicates.

func (Fields) Merge

func (fields Fields) Merge(s *types.Struct, embed bool, path FieldPath) Fields

type Package

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

func (*Package) Code

func (p *Package) Code(format string, args ...interface{}) (c Code)

func (*Package) DefinedTypes

func (p *Package) DefinedTypes(filter TypeFilter) (typs []types.Type)

func (*Package) DefinedTypesN

func (p *Package) DefinedTypesN(maxResults int, filter TypeFilter) (typs []types.Type)

func (*Package) DefinedVars

func (p *Package) DefinedVars(filter TypeFilter) (vars []Var)

func (*Package) FindImport

func (p *Package) FindImport(path string) *types.Package

func (*Package) Fprint

func (p *Package) Fprint(w io.Writer, node interface{}) error

func (*Package) LookupType

func (p *Package) LookupType(name string) (T *types.Named)

LookupType looks up a named type in the package's definitions.

func (*Package) Name

func (p *Package) Name() string

func (*Package) NamedTypes

func (p *Package) NamedTypes() map[string]*types.Named

func (*Package) Path

func (p *Package) Path() string

func (*Package) Qualifier

func (p *Package) Qualifier() types.Qualifier

func (*Package) TypeString

func (p *Package) TypeString(t types.Type) string

type Params

type Params url.Values

func (Params) Assign

func (p Params) Assign(other ...Params) Params

func (Params) Defaults

func (p Params) Defaults(other ...Params) Params

func (Params) Duration

func (p Params) Duration(key string) (d time.Duration)

func (Params) Float

func (p Params) Float(key string) (f float64)

func (Params) Get

func (p Params) Get(key string) string

func (Params) Has

func (p Params) Has(key string) bool

func (Params) Int

func (p Params) Int(key string) (i int)

func (Params) Pop

func (p Params) Pop(key string) (v string)

func (Params) Pull

func (p Params) Pull(key string) (v string)

func (Params) Time

func (p Params) Time(key, format string) (t time.Time)

func (Params) ToBool

func (p Params) ToBool(key string) (bool, error)

func (Params) ToDuration

func (p Params) ToDuration(key string) (time.Duration, error)

func (Params) ToFloat

func (p Params) ToFloat(key string) (float64, error)

func (Params) ToInt

func (p Params) ToInt(key string) (i int, err error)

func (Params) ToTime

func (p Params) ToTime(key, format string) (time.Time, error)

func (Params) True

func (p Params) True(key string) (b bool)

func (Params) Values

func (p Params) Values() url.Values

func (Params) With

func (p Params) With(param string) Params

type Parser

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

func NewParser

func NewParser(mode parser.Mode) *Parser

func (*Parser) Package

func (p *Parser) Package(name, path string, filter func(*ast.File) bool) (*Package, error)

func (*Parser) ParseDir

func (p *Parser) ParseDir(path string, filter func(os.FileInfo) bool) error

func (*Parser) ParseFile

func (p *Parser) ParseFile(filename string, src interface{}) (string, error)

type Tag

type Tag struct {
	Key     string
	Name    string
	Missing bool
	Params  Params
}

func ParseTag

func ParseTag(tag, key string) (t Tag, ok bool)

type TypeFilter

type TypeFilter func(t types.Type) bool

func AssignableTo

func AssignableTo(t types.Type) TypeFilter

func ConvertibleTo

func ConvertibleTo(t types.Type) TypeFilter

type Var

type Var struct {
	*ast.Ident
	Type  types.TypeAndValue
	Value ast.Expr
}

Jump to

Keyboard shortcuts

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