distiller

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 12 Imported by: 0

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

This section is empty.

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

func LookupTypedConsts(name string) []*ConstInfo

LookupTypedConsts searches loaded packages for declared constants of specified fully qualified named type. It returns nil in case of no matches.

func NewConstInfo

func NewConstInfo(valueSpec *ast.ValueSpec, pkg *packages.Package) *ConstInfo

NewConstInfo creates new const information object from given abstract syntax tree value spec and package.

func (*ConstInfo) InlineDoc added in v0.3.0

func (c *ConstInfo) InlineDoc() string

InlineDoc replaces all new line in the documentation with spaces, making the resulting string suitable to be placed inline.

func (*ConstInfo) String

func (c *ConstInfo) String() string

String implements the stringer interface.

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 NewFieldInfo

func NewFieldInfo(field *ast.Field, pkg *packages.Package) *FieldInfo

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.

func (*FieldInfo) FormatDoc

func (f *FieldInfo) FormatDoc(indent string, renderType bool) string

FormatDoc formats the field documentation indenting it with passed indent string.

func (*FieldInfo) String

func (f *FieldInfo) String() string

type FieldLayout added in v0.3.0

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

Jump to

Keyboard shortcuts

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