godetector

package module
v0.0.0-...-f938e11 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 14 Imported by: 6

README

GO-Detector

Documentation license donate

The library aims to provide useful utilities to work with golang packages:

  • Detect package name from directory (not just by using base name, but also parse go files)
  • Detect package import path (including vendor support and go modules)
  • Detect import package definition (where go files located) with respect to gomodules

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindImportPath

func FindImportPath(dir string) (string, error)

Find import path assuming that directory contains Go package.

For projects with 'vendor' directory it will return path in the vendor dir.

It will check all upper directories checking each of them as (a) they have go.mod file (b) directory is under GOROOT/GOPATH

func FindPackageDefinitionDir

func FindPackageDefinitionDir(importPath string, workDir string) (string, error)

Find package definition with respect to gomodules

func FindPackageNameByDir

func FindPackageNameByDir(dir string) string

Find package name by directory: scans go file to detect package definition and uses path detection as fail-over

func InspectDirectory

func InspectDirectory(dir string) (info *importPathInfo, err error)

func InspectImport

func InspectImport(importPath string, workDir string) (info *importPathInfo, err error)

Types

type Import

type Import struct {
	Path                string // example.com/project/alfa/beta/gamma
	Package             string // gamma
	Location            string // /opt/go/src/example.com/project/alfa/beta/gamma
	RootPackageLocation string // /opt/go/src/example.com/project/alfa
	Type                LocationType
}

func InspectImportByDir

func InspectImportByDir(pkgDir string) (*Import, error)

Aggregated information about directory

func ResolveImport

func ResolveImport(alias string, file *ast.File, workdir string) (*Import, error)

Find correct import definition in a file: "lala" "net/http" will be resolve to "net/http"

type LocationType

type LocationType int
const (
	Local         LocationType = 0
	GoMod         LocationType = 1
	InLocalVendor LocationType = 2
	GoPath        LocationType = 3
	GoRoot        LocationType = 4
	GoCache       LocationType = 5
)

type Package

type Package struct {
	Location string
	Import   string
	Name     string
	Type     LocationType
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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