Help us shape the future of Go! Take the 2026 Go Developer Survey

findpackagesrc

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

findpackagesrc

GoDoc

Golang package that find original source path

package main

import (
    "fmt"
    "github.com/shibukawa/findpackagesrc"
)

func main() {
    finder, err := findpackagesrc.NewFinder(findpackagesrc.Option{})
    if err != nil {
        panic(err)
    }
    path, err := finder.FindSourcePath("github.com/stretchr/testify")
    if err != nil {
        panic(err)
    }
    fmt.Println(path)
    // /home/yourname/go/pkg/mod/github.com/stretchr/testify@v1.4.0
}

It searches in the following order (I don't know the order is as same as Go's rule):

  1. Replace defined in go.mod
  2. Downloaded by go mod in go.sum
  3. vendor folder
  4. $GOPATH
  5. $GOROOT (for go standard library)

License

Apache 2

Documentation

Overview

findpackagesrc package provides API to detect original source of go package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finder

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

Finder has method returns package source

func NewFinder

func NewFinder(options ...Option) (*Finder, error)

NewFinder is a constructor function of Finder

func (Finder) FindSourcePath

func (f Finder) FindSourcePath(pkg string) (string, error)

FindSourcePath returns source folder of specified package

This method searches package in the following order:

  1. Replace defined in go.mod
  2. Downloaded by go mod in go.sum
  3. vendor folder
  4. $GOPATH
  5. $GOROOT (for go standard library)

type ModType

type ModType int
const (
	Module ModType = iota + 1
	LocalPath
)

type Option

type Option struct {
	ProjectPath string
	GoPath      string
	GoRoot      string
}

Option specify Finder's option

Default value of ProjectPath is a is a nearest parent folder that contains go.mod. If go.mod is not found, it becomes current folder.

Default value of GoPath is a $GOPATH.

Default value of GoRoot is a $GOROOT.

Jump to

Keyboard shortcuts

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