Documentation ¶
Overview ¶
Package bast implements a simple intermediate object model of top level Go declarations from AST of go source files and is designed for use in text based code-generation with Go's text/template templating engine.
Bast's structure can be easily traversed from a template and provides a number of functions to help with data retrieval and other utils.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bast ¶
type Bast struct { // Packages is a list of packages parsed into bast using Load(). // // Files outside of a package given to Load will be placed in a package // with an empty name. Packages map[string]*Package }
Bast is a top level struct that contains parsed go packages. It also implements all functions usable from a text/template.
func Load ¶
Load loads and returns bast of Go packages named by the given patterns.
Paths can be absolute or relative paths to a directory containing go source files possibly defining a package or a cmd or a go file. It can also be a go module path loading of which depends on the current go environment.
If an error in loading a file or a package occurs the error returned will be the first error of the first package that contains an error. Nil Bast is returned in case of an error.
Patterns which name file paths ar epared into an unnamed package in bast.
type Config ¶
type Config struct { PrintConsts bool PrintVars bool PrintTypes bool PrintFuncs bool PrintMethods bool PrintStructs bool PrintInterfaces bool }
func DefaultConfig ¶
func DefaultConfig() *Config
type Const ¶
type Const struct { // Comment is the const comment. Comment []string // Doc is the const doc comment. Doc []string // Name is the constant name. Name string // Type is the const type, empty if undpecified. Type string // Value is the const value, empty if undpecified. Value string }
Const contains info about a constant.
type Declaration ¶
type Declaration interface { // GetName returns the Declaration name. GetName() string }
Declaration represents a top level declaration in a Go file.
type Field ¶
type Field struct { // Comment is the field comment. Comment []string // Doc is the field doc comment. Doc []string // Name is the field name. Name string // Type is the field type. Type string // Tag is the field raw tag string. Tag string }
Field contains info about a struct field, method receiver, or method or func type params, params or results.
type File ¶
type File struct { // Comments are the file comments, grouped by separation, including docs. Comments [][]string // Doc is the file doc comment. Doc []string // Name is the File name, without path. Name string // Imports is a list of file imports. Imports map[string]*Import // Declarations is a list of top level declarations in the file. Declarations map[string]Declaration }
File contians info about a Go source file.
type Func ¶
type Func struct { // Comment is the func comment. Comment []string // Doc is the func doc comment. Doc []string // Name is the func name. Name string // TypeParams are type parameters. TypeParams map[string]*Field // Params is a list of func arguments. Params map[string]*Field // Results is a list of func returns. Results map[string]*Field }
Func contains info about a function.
type Import ¶
type Import struct { // Comment is the import comment. Comment []string // Doc is the import doc. Doc []string // Name is the import name, possibly empty, "." or some custom name. Name string // Path is the import path. Path string }
Import contians info about an import.
type Interface ¶
type Interface struct { // Comment is the interface comment. Comment []string // Doc is the interface doc comment. Doc []string // Name is the interface name. Name string // Methods is a list of methods defined by the interface. Methods map[string]*Method }
Interface contains info about an interface.
type Method ¶
type Method struct { // Func embeds all Func properties. Func // Receiver is the method receiver. Receivers map[string]*Field }
Method contains info about a method.
type Package ¶
type Package struct { // Name is the package name, without path. Name string // Files is a list of files in the package. Files map[string]*File }
Package contians info about a Go package.
type Struct ¶
type Struct struct { // Comment is the struct comment. Comment []string // Doc is the struct doc comment. Doc []string // Name is the struct name. Name string // Fields is a list of struct fields. Fields map[string]*Field }
Struct contains info about a struct.
type Type ¶
type Type struct { // Comment is the struct comment. Comment []string // Doc is the struct doc comment. Doc []string // Name is the struct name. Name string // Type is Type's underlying type. Type string // IsAlias is true if type is an alias of the type it derives from. IsAlias bool }
Type contains info about a type.
type Var ¶
type Var struct { // Comment is the const comment. Comment []string // Doc is the const doc comment. Doc []string // Name is the constant name. Name string // Type is the const type, empty if undpecified. Type string // Value is the const value, empty if undpecified. Value string }
Var contains info about a variable.