models

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// OperationMode determines whether the generator is working with
	// source files or a module
	OperationMode OperationMode

	// SourceModule represents the module that will be used to source interfaces
	// to be used to generate stubs
	SourceModule gocli.ModuleInformation

	// Renames contains an association of interface names to be replaced
	// when generating sources
	Renames map[string]string

	// OutputDirectory contains the absolute path to the target directory
	// to receive generated sources
	OutputDirectory string

	// TargetPackageName determines the package name to be used when generating
	// sources.
	TargetPackageName string

	// Workdir determines the directory from which the CLI is being executed
	// from
	Workdir string

	// SourceFile represents the source file to be used to extract interfaces
	// from when using OperationModeSource
	SourceFile string

	// WantsAllInterfaces indicates whether the user wishes to generate stubs
	// for all exported interfaces. This option is only valid with
	// OperationModeSource.
	WantsAllInterfaces bool

	// UsedRenames contains a list of Renames that were actually used during the
	// codegen operation
	UsedRenames map[string]bool

	// IsInterfaceCache implements a simple cache that associates whether a
	// given type (through Type.FullName) is an interface
	IsInterfaceCache *genericConcurrentMap[string, bool]

	// PackageByNameCache implements a simple cache that associates package
	// import paths and their packages.Package representation
	PackageByNameCache *genericConcurrentMap[string, *packages.Package]

	// GoTypeDefinitionCache implements a simple cache that associates paths
	// of specific types with their respective Go type information.
	GoTypeDefinitionCache *genericConcurrentMap[string, types.Object]
}

func LoadContext

func LoadContext(sourcePath, outputDirectory, targetPackage string) (*Context, error)

type Interface

type Interface struct {
	Name    string
	Methods []Method

	// Maps import paths to names, if any
	Imports map[string]string
}

func (*Interface) AddImport

func (i *Interface) AddImport(ctx *Context, p *Package)

type Method

type Method struct {
	Name    string
	Inputs  []Parameter
	Outputs []Parameter
}

type OperationMode

type OperationMode int8
const (
	OperationModeInvalid OperationMode = iota
	OperationModeSource
	OperationModeModule
)

type Package

type Package struct {
	ImportPath string
	Name       string
}

type Parameter

type Parameter struct {
	Names []string
	Type  Type
}

type Type

type Type struct {
	Package     *Package
	Name        string
	IsPointer   bool
	IsSlice     bool
	IsInterface bool
	HasEllipsis bool
	IsFunction  bool
	IsMap       bool

	FuncInputs  []Parameter
	FuncOutputs []Parameter

	MapKey   *Type
	MapValue *Type
}

func (Type) FullName

func (t Type) FullName() string

func (Type) ToGo

func (t Type) ToGo() string

Jump to

Keyboard shortcuts

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