Documentation ¶
Index ¶
- Constants
- func GoGenerateMain(arg []string, imp *Importer) error
- func IsLocalImportPath(pkgpath string) bool
- type AbsolutePath
- type ImportMode
- type Importer
- func (imp *Importer) ImportPackage(alias PackageName, path string, enableModule bool) *PackageRef
- func (imp *Importer) ImportPackagesOrError(pathMap map[string]PackageName, enableModule bool) (map[string]*PackageRef, error)
- func (imp *Importer) InImportAllowlist(pathMap map[string]PackageName) (blocked []string)
- func (imp *Importer) InImportDenylist(pathMap map[string]PackageName) (blocked []string)
- func (imp *Importer) Load(dir string, paths []string, mode ImportMode, enableModule bool) (retPkgs map[string]*types.Package, retErr error)
- type Output
- type PackageName
- type PackagePath
- type PackageRef
- type TypeVisitor
Constants ¶
const GoModuleSupported bool = true
Variables ¶
This section is empty.
Functions ¶
func GoGenerateMain ¶
GoGenerateMain allows gomacro to be run under go generate. It is used to write new x_package.go import bindings for a package. Thus `go generate` will automatically update your bindings.
To use, add a comment to one go file in your package:
`//go:generate gomacro -g .`
to import the current dir; or one like
`//go:generate gomacro -g github.com/truthtracer/gomacro/classic`
to specify the exact import path. The second, specific form, may be necessary if we cannot detect the GOPATH environment variable.
func IsLocalImportPath ¶
Types ¶
type AbsolutePath ¶
type AbsolutePath struct {
// contains filtered or unexported fields
}
an absolute filesystem path - can be either a file or directory
func MakeAbsolutePathOrError ¶
func MakeAbsolutePathOrError(path string) (AbsolutePath, error)
func MakeAbsolutePathOrPanic ¶
func MakeAbsolutePathOrPanic(path string) AbsolutePath
func (AbsolutePath) String ¶
func (abspath AbsolutePath) String() string
type ImportMode ¶
type ImportMode int
const ( // ImBuiltin import mechanism is: // 1. write a file $GOPATH/src/github.com/truthtracer/gomacro/imports/$PKGPATH.go containing a single func init() // i.e. *inside* gomacro sources // 2. tell the user to recompile gomacro ImBuiltin ImportMode = iota // ImThirdParty import mechanism is the same as ImBuiltin, except that files are created in a thirdparty/ subdirectory: // 1. write a file $GOPATH/src/github.com/truthtracer/gomacro/imports/thirdparty/$PKGPATH.go containing a single func init() // i.e. *inside* gomacro sources // 2. tell the user to recompile gomacro ImThirdParty // ImInception import mechanism is: // 1. write a file $GOPATH/src/$PKGPATH/x_package.go containing a single func init() // i.e. *inside* the package to be imported // 2. tell the user to recompile $PKGPATH ImInception // ImPlugin import mechanism is: // 1. write a file $GOPATH/src/gomacro.imports/.../ containing a var Packages map[string]Package // and a single func init() to populate it // 2. invoke "go build -buildmode=plugin" on the file to create a shared library // 3. load such shared library with plugin.Open().Lookup("Packages") ImPlugin )
func (ImportMode) String ¶
func (mode ImportMode) String() string
type Importer ¶
type Importer struct { PluginOpen r.Value // = reflect.ValueOf(plugin.Open) BuildArgs []string // When you need to strictly set the allowed imports without touching // the global imports.Packages between the different interpreters. AllowList []string // In case you want to ban some specific modules from loading without // touching of the global imports.Packages between the different interpreters. DenyList []string // Blocks interpreter access to external (not in imports.Packages) imports. BlockExternal bool // contains filtered or unexported fields }
func DefaultImporter ¶
func (*Importer) ImportPackage ¶
func (imp *Importer) ImportPackage(alias PackageName, path string, enableModule bool) *PackageRef
path can be a Go package path or and absolute filesystem path
func (*Importer) ImportPackagesOrError ¶
func (imp *Importer) ImportPackagesOrError(pathMap map[string]PackageName, enableModule bool) (map[string]*PackageRef, error)
pathMap is a map (Go package path or absolute filesystem path) -> package alias
func (*Importer) InImportAllowlist ¶
func (imp *Importer) InImportAllowlist(pathMap map[string]PackageName) (blocked []string)
func (*Importer) InImportDenylist ¶
func (imp *Importer) InImportDenylist(pathMap map[string]PackageName) (blocked []string)
func (*Importer) Load ¶
func (imp *Importer) Load(dir string, paths []string, mode ImportMode, enableModule bool) ( retPkgs map[string]*types.Package, retErr error)
Return the exported declarations of requested packages. If needed, prepare a Go module in 'dir' to list them.
Note: paths can contain both Go package paths (corresponding to published Go packages) and filesystem absolute paths (corrisponding to local Go packages)
Each returned map entry {string, *types.Package} will contain: 1. paths[i] as map key 2. *types.Package as map value, which contains both the Go package name and its Go package path
allowing the caller to match each filesystem absolute path to the corresponding Go package
type PackageName ¶
type PackageName = imports.PackageName // package default name, or package alias
type PackagePath ¶
type PackagePath struct {
// contains filtered or unexported fields
}
the full path of a Go package
func MakePackagePathOrPanic ¶
func MakePackagePathOrPanic(path string) PackagePath
func (PackagePath) Join ¶
func (pkgpath PackagePath) Join(subpkg PackagePath) PackagePath
func (PackagePath) JoinString ¶
func (pkgpath PackagePath) JoinString(subdir string) PackagePath
func (PackagePath) String ¶
func (pkgpath PackagePath) String() string
type PackageRef ¶
func LookupPackage ¶
func LookupPackage(alias PackageName, pkgpath string) *PackageRef
LookupPackage returns a package if already present in cache
func (*PackageRef) DefaultName ¶
func (ref *PackageRef) DefaultName() PackageName
func (*PackageRef) String ¶
func (ref *PackageRef) String() string