modpath

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2019 License: MIT Imports: 7 Imported by: 0

README

modpath

Go Doc

modpath provides an API to detect the module path from the go.mod file underneath the given directory or its root.

Installation

go get github.com/nakabonne/modpath

Usage

package main

import (
	"fmt"

	"github.com/nakabonne/modpath"
)

func main() {
	modulePath, _ := modpath.Run("/path/to/foo/bar")
	fmt.Println(modulePath) // -> "example.com/foo/bar"
}
Using as a replacement for go list -m

Unlike go list -m, you can inspect any directories except for the current directory.

$ cat /path/to/foo/bar/go.mod
module example.com/foo/bar

go 1.13

$ modpath /path/to/foo/bar/
example.com/foo/bar

If no directory is explicitly given, the module containing the current directory is emitted as go list -m does.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(dir string) (modulePath string, err error)

Run returns the module path from the gomod file underneath the given directory or its all ancestor directories. "." is populated as dir if empty string provided.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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