types

package
v0.0.0-...-70f9d4a Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 5 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SectionMerged = "merged"
	SectionTypes  = "types"
)
View Source
const (
	StructTypeTmpl = `

{{ .Comment }}
type {{ .Name }} struct {
{{ .Fields }}
}`
	FieldTmpl    = "\n\n\n{{ .Comment }}\n{{ .Name }} {{ .Type }} `{{ .Tag }}`"
	EnumTypeTmpl = `

{{ .Comment }}
type {{ .Name }} {{ .UnderlyingType }}`
)

Variables

This section is empty.

Functions

func NewNamedInLocalPkg

func NewNamedInLocalPkg(t *types.Named, pkg *types.Package) *types.Named

func QualifiedFieldPath

func QualifiedFieldPath(n *types.TypeName, f string) string

QualifiedFieldPath returns a fully qualified path for the field of the given type. The format is <package path>.<type name>:<field name>

func QualifiedTypePath

func QualifiedTypePath(n *types.TypeName) string

QualifiedTypePath returns a fully qualified path for the type name. The format is <package path>.<type name>

Types

type Comments

type Comments map[string]string

Comments holds all comments that will be printed together with objects. We have to have this map separate from the types because go/types package doesn't include comments anywhere in its structs.

func (Comments) AddFieldComment

func (c Comments) AddFieldComment(t *types.TypeName, f, comm string)

AddFieldComment lets you add comment for the given field of the type.

func (Comments) AddTypeComment

func (c Comments) AddTypeComment(t *types.TypeName, comm string)

AddTypeComment lets you add comment for the given type.

type EnumTypeTmplInput

type EnumTypeTmplInput struct {
	Name           string
	UnderlyingType string
	Comment        string
}

type FieldFilter

type FieldFilter interface {
	Filter(field *types.Var, tag string) (*types.Var, string)
}

type FieldFilterChain

type FieldFilterChain []FieldFilter

func (FieldFilterChain) Filter

func (tc FieldFilterChain) Filter(field *types.Var, tag string) (*types.Var, string)

type FieldProcessor

type FieldProcessor interface {
	Process(n *types.Named, f *types.Var, tag string, comment string, formerFields []string) error
}

type FieldProcessorChain

type FieldProcessorChain []FieldProcessor

func (FieldProcessorChain) Process

func (fpc FieldProcessorChain) Process(n *types.Named, f *types.Var, tag string, comment string, formerFields []string) error

type FieldTmplInput

type FieldTmplInput struct {
	Name    string
	Type    string
	Tag     string
	Comment string
}

type Flattener

type Flattener struct {
	Imports *packages.Imports
	// RemotePkgPath is the path of the package of the remote type we're pulling
	// the types from.
	RemotePkgPath string
	LocalPkg      *types.Package

	TypeFilter  TypeFilter
	FieldFilter FieldFilter
}

func NewFlattener

func NewFlattener(im *packages.Imports, opts ...FlattenerOption) *Flattener

func (*Flattener) Flatten

func (f *Flattener) Flatten(t *types.Named) []*types.Named

type FlattenerOption

type FlattenerOption func(*Flattener)

func WithFieldFilters

func WithFieldFilters(ff ...FieldFilter) FlattenerOption

func WithLocalPkg

func WithLocalPkg(pkg *types.Package) FlattenerOption

func WithRemotePkgPath

func WithRemotePkgPath(path string) FlattenerOption

func WithTypeFilters

func WithTypeFilters(tf ...TypeFilter) FlattenerOption

type IgnoreFieldFilter

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

func NewIgnoreFieldFilter

func NewIgnoreFieldFilter(list []string) *IgnoreFieldFilter

func (*IgnoreFieldFilter) Filter

func (ig *IgnoreFieldFilter) Filter(field *types.Var, tag string) (*types.Var, string)

type IgnoreTypeFilter

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

func NewIgnoreTypeFilter

func NewIgnoreTypeFilter(list []string) *IgnoreTypeFilter

func (*IgnoreTypeFilter) Filter

func (ig *IgnoreTypeFilter) Filter(name types.TypeName, t types.Type) types.Type

type Merger

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

func NewMerger

func NewMerger(name *types.TypeName, inputTypes []*types.Named) *Merger

func (*Merger) Generate

func (m *Merger) Generate() (*types.Named, packages.CommentMarkers, error)

type NopFieldFilter

type NopFieldFilter struct{}

func (NopFieldFilter) Filter

func (tc NopFieldFilter) Filter(field *types.Var, tag string) (*types.Var, string)

type NopTypeFilter

type NopTypeFilter struct{}

func (NopTypeFilter) Filter

func (tc NopTypeFilter) Filter(t *types.Named) *types.Named

type Printer

type Printer struct {
	Imports     *packages.Imports
	TargetScope *types.Scope
	Comments    Comments
}

func NewPrinter

func NewPrinter(im *packages.Imports, targetScope *types.Scope, opts ...PrinterOption) *Printer

func (*Printer) Print

func (tp *Printer) Print(typeList []*types.Named) (string, error)

type PrinterOption

type PrinterOption func(*Printer)

func WithComments

func WithComments(c Comments) PrinterOption

type StructTypeTmplInput

type StructTypeTmplInput struct {
	Name    string
	Fields  string
	Comment string
}

type Traverser

type Traverser struct {
	TypeProcessors  TypeProcessor
	FieldProcessors FieldProcessor
	// contains filtered or unexported fields
}

func NewTraverser

func NewTraverser(cache *packages.Cache, opts ...TraverserOption) *Traverser

func (*Traverser) Traverse

func (t *Traverser) Traverse(n *types.Named, formerFields ...string) error

type TraverserOption

type TraverserOption func(*Traverser)

func WithFieldProcessor

func WithFieldProcessor(fp FieldProcessor) TraverserOption

func WithTypeProcessor

func WithTypeProcessor(tp TypeProcessor) TraverserOption

type TypeFilter

type TypeFilter interface {
	Filter(*types.Named) *types.Named
}

type TypeFilterChain

type TypeFilterChain []TypeFilter

func (TypeFilterChain) Filter

func (tc TypeFilterChain) Filter(t *types.Named) *types.Named

type TypeProcessor

type TypeProcessor interface {
	Process(n *types.Named, comment string) error
}

type TypeProcessorChain

type TypeProcessorChain []TypeProcessor

func (TypeProcessorChain) Process

func (tpc TypeProcessorChain) Process(n *types.Named, comment string) error

Jump to

Keyboard shortcuts

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