structfields

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 6 Imported by: 0

README

Package structfields

Enumerate struct types and their fields from Go source files.

Go Reference

Notes

  • The intended use-case is generating docs for config structs.
  • Embedded struct fields are flattened into regular fields.
  • Embedded fields are not de-duplicated.
  • Fields with inline struct types are not well supported.

Documentation

Index

Constants

Needs is the packages.Mode with all the flags required to find fields.

Variables

This section is empty.

Functions

func ResolvePackage

func ResolvePackage(pkg *packages.Package, file *ast.File, name string) (*packages.Package, bool)

ResolvePackage will resolve a package by its name. It's legal to pass a nil file, but then import aliases and duplicates are not handled.

func ResolveType

func ResolveType(pkg *packages.Package, name string) (*ast.StructType, *ast.File, bool)

ResolveType returns a struct type defined in the provided package along with the file it's declared in. The bool return value will be false if the name could not be resolved.

Types

type FieldType

type FieldType struct {
	Name    string
	Type    string
	Doc     string
	Comment string
	Tag     string
}

FieldType contains information about a struct field.

func Fields

func Fields(pkg *packages.Package, file *ast.File, stype *ast.StructType) []*FieldType

Fields returns a list of the struct type's fields. A nil file may be passed, but this limits the ability to resolve embeded types.

type StructType

type StructType struct {
	Doc        string
	Name       string
	Directives []string
	Fields     []*FieldType
}

StructType contains details about a struct and it's fields.

func Load

func Load(dir string, patterns ...string) ([]*StructType, error)

Load finds all structs in the packages specified in the patterns. Embeded fields are treated the same as regular fields.

func Structs

func Structs(pkg *packages.Package) []*StructType

Structs finds all structs in the provided package. Embeded fields are treated the same as regular fields.

Directories

Path Synopsis
cmd
structfields command

Jump to

Keyboard shortcuts

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