Documentation
¶
Overview ¶
Package distiller extracts only the necessary information from the AST, making it easy to access the names and documentation of structs, fields, and constants.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConstInfo ¶
type ConstInfo struct { Name string // Constant name. Value string // String representation of constant value. Doc string // Constant documentation and comment nodes contents. }
ConstInfo holds information about a typed constant.
func LookupTypedConsts ¶
LookupTypedConsts searches loaded packages for declared constants of specified fully qualified named type. It returns nil in case of no matches.
func NewConstInfo ¶
NewConstInfo creates new const information object from given abstract syntax tree value spec and package.
type FieldInfo ¶
type FieldInfo struct { Type types.Type // Field type, used to compute fully qualified type string. Name string // Field name. Layout FieldLayout // Field layout. EltType types.Type // Field element type, when the field is a slice or map. IsEmbedded bool // True if field is an embedded struct and Name is an empty string. Tags map[string]string // Tags applied to that field as map of name-value key-pairs. Doc string // Documentation content if present. }
FieldInfo holds information about structure field.
func GetFieldsInfo ¶ added in v1.0.5
func NewFieldInfo ¶
NewFieldInfo creates new field information object from given abstract syntax tree field and package. Terminates the process with a fatal error if multiple names are specified for the same field. Returns nil if the field is not exported.
type FieldLayout ¶
type FieldLayout int
const ( LayoutSingle FieldLayout = iota // The field is a single element. LayoutArray // The field is an array or slice of elements. LayoutMap // The field is a map of elements. )
type PackageInfo ¶
type PackageInfo struct { Package *packages.Package Imported []*packages.Package // Packages imported from this. Structs map[string]*StructInfo // Structures declared on this package mapped by fully qualified name. TypedConsts map[string][]*ConstInfo // Typed constants grouped by fully qualified type name. }
PackageInfo holds information about a package.
func NewPackageInfo ¶
func NewPackageInfo(dir string, typeName string) (*PackageInfo, error)
NewPackageInfo creates a new package information object from given directory. The passed name defines the struct for which read also defaults values.
type StructInfo ¶
type StructInfo struct { Package *packages.Package // Package of which the structure is part Name string // Struct name. Doc string // Documentation content if present. Fields []*FieldInfo // Struct fields. // If a function with following signature: // // func <StructName>Defaults() *StructName // // is found on the same package where the struct is declared // it will be parsed to extract default values for all fields. Defaults map[string]interface{} // Map of defaults values for struct fields. }
StructInfo holds information about a struct.
func LookupStruct ¶
func LookupStruct(name string) *StructInfo
LookupStruct searches loaded packages for the specified fully qualified struct name. It returns nil in case of no matches.
func NewStructInfo ¶
func NewStructInfo(genDecl *ast.GenDecl, pkg *packages.Package) *StructInfo
NewStructInfo creates a new struct information object from given abstract syntax tree type spec and types info read on package loading.
func (*StructInfo) FormatDoc ¶
func (s *StructInfo) FormatDoc(indent string) string
FormatDoc formats the struct documentation indenting it with passed indent string.
func (*StructInfo) ParseDefaultsMethod ¶
func (s *StructInfo) ParseDefaultsMethod() error
ParseDefaultsMethod parses the Defaults method of this struct populating Defaults map.
func (*StructInfo) String ¶
func (s *StructInfo) String() string